lib/generators/binda/setup/setup_generator.rb in binda-0.1.5 vs lib/generators/binda/setup/setup_generator.rb in binda-0.1.6

- old
+ new

@@ -13,78 +13,74 @@ def setup_settings puts "Implement Binda settings" puts - dashboard_structure = ::Binda::Structure.find_or_create_by( name: 'dashboard', slug: 'dashboard', instance_type: 'board' ) + dashboard_structure = Structure.find_or_create_by( name: 'dashboard', slug: 'dashboard', instance_type: 'board' ) @dashboard = dashboard_structure.board # By default each structure has a field group which will be used to store the default field settings @field_settings = dashboard_structure.field_groups.first.field_settings end def create_credentials puts "1) Create a superadmin user" - rake 'binda:create_superadmin_user' + User.create_super_admin_user puts end def setup_maintenance_mode puts "2) Setting up maintenance mode" # Use radio field_type untill truefalse isn't available unless FieldSetting.find_by(slug: 'maintenance-mode').present? - maintenance_mode = @field_settings.create!( name: 'Maintenance Mode', field_type: 'radio', position: 1, allow_null: false ) + maintenance_mode = @field_settings.create!( name: 'Maintenance Mode', field_type: 'radio', position: 1, allow_null: false, slug: 'maintenance-mode' ) # create active and disabled choices disabled = maintenance_mode.choices.create!( label: 'disabled', value: 'false' ) maintenance_mode.choices.create!( label: 'active', value: 'true' ) # assign disabled choice and remove the temporary choice @dashboard.reload @dashboard.radios.first.choices << disabled - @dashboard.radios.first.choices.select{|choice| choice.label != 'disabled'}.first.destroy + unwanted = @dashboard.radios.first.choices.select{|choice| choice.label != 'disabled'} + unwanted.each{|choice| choice.destroy} if unwanted.any? end puts "The maintenance-mode option has been set up." puts end def setup_website_name puts "3) Setting up website name" puts "Don't worry you can modify it later." - website_name_obj = @field_settings.find_by(slug: 'website-name') - unless website_name_obj.present? - website_name_obj = @field_settings.create!( name: 'Website Name', field_type: 'string', position: 2 ) + name_field_setting = FieldSetting.find_by(slug: 'website-name') + unless name_field_setting.present? + name_field_setting = @field_settings.create!( name: 'Website Name', field_type: 'string', position: 2 ) # make sure slug works - website_name_obj.update_attribute( 'slug', 'website-name' ) + name_field_setting.update_attribute( 'slug', 'website-name' ) end - website_name = ask("How would you like to name your website? ['MySite']\n").presence || 'MySite' - @dashboard.strings.find_or_create_by( field_setting_id: website_name_obj.id ).update_attribute('content', website_name ) + STDOUT.puts "How would you like to name your website? ['MySite']" + website_name = STDIN.gets + website_name = 'MySite' if website_name.blank? + @dashboard.strings.find_or_create_by( field_setting_id: name_field_setting.id ).update_attribute('content', website_name ) + puts end def setup_website_content puts "4) Setting up website description" puts "Don't worry you can modify it later." - website_description_obj = @field_settings.find_by(slug: 'website-description') - unless website_description_obj.present? - website_description_obj = @field_settings.find_or_create_by( name: 'Website Description', field_type: 'text', position: 3 ) + description_field_setting = FieldSetting.find_by(slug: 'website-description') + unless description_field_setting.present? + description_field_setting = @field_settings.find_or_create_by( name: 'Website Description', field_type: 'text', position: 3 ) # make sure slug works - website_description_obj.update_attribute( 'slug', 'website-description' ) + description_field_setting.update_attribute( 'slug', 'website-description' ) end - website_description = ask("What is your website about? ['A website about the world']\n").presence || 'A website about the world' - @dashboard.texts.find_or_create_by!( field_setting_id: website_description_obj.id ).update_attribute( 'content', website_description ) - end - - # Setup default helpers - # - # This operation creates a class called `B` from which is possible to call any - # Binda helper contained in Binda::DefaultHelpers. This is possible by inheriting the - # `Binda::B` class. - def setup_default_helpers - puts "5) Setting up default helpers" - generate "model", "B --no-migration --parent=::Binda::B" - puts "Default helpers has been set up." + + STDOUT.puts "What is your website about? ['A website about the world']" + website_description = STDIN.gets + website_description = 'A website about the world' if website_description.blank? + @dashboard.texts.find_or_create_by!( field_setting_id: description_field_setting.id ).update_attribute( 'content', website_description ) puts end def feedback puts "==============================================================================="