Class: Binda::SetupGenerator
- Inherits:
-
Rails::Generators::Base
- Object
- Rails::Generators::Base
- Binda::SetupGenerator
- Defined in:
- lib/generators/binda/setup/setup_generator.rb
Overview
Setup initial settings for the application.
This is setup is mandatory as sets the initial super admin user and
the default dashboard where are stored the main application settings.
It is useful also when Binda has been already installed once but the
database has been reset. Runnin `rails g binda:setup` will populate
the application database with new default settings.
Instance Method Summary collapse
- #create_credentials ⇒ Object
- #feedback ⇒ Object
- #setup_maintenance_mode ⇒ Object
- #setup_settings ⇒ Object
- #setup_website_content ⇒ Object
- #setup_website_name ⇒ Object
Instance Method Details
#create_credentials ⇒ Object
29 30 31 32 33 |
# File 'lib/generators/binda/setup/setup_generator.rb', line 29 def create_credentials puts "1) Create a superadmin user" User.create_super_admin_user puts end |
#feedback ⇒ Object
90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/generators/binda/setup/setup_generator.rb', line 90 def feedback puts "===============================================================================" puts puts " Binda CMS has been succesfully installed! " puts puts "===============================================================================" puts puts "Before deploying to production, remember to uncomment and update the" puts "'config.action_mailer.default_url_options' in 'config/environments/production.rb'" puts puts "===============================================================================" end |
#setup_maintenance_mode ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/generators/binda/setup/setup_generator.rb', line 35 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, 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 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 |
#setup_settings ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/generators/binda/setup/setup_generator.rb', line 14 def setup_settings puts "Implement Binda settings" puts if Structure.find_by(slug: 'dashboard').nil? dashboard_structure = Structure.create!(name: 'dashboard', slug: 'dashboard', instance_type: 'board') else dashboard_structure = Structure.find_by(slug: 'dashboard') end @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 |
#setup_website_content ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/generators/binda/setup/setup_generator.rb', line 72 def setup_website_content puts "4) Setting up website description" puts "Don't worry you can modify it later." 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 description_field_setting.update_attribute( 'slug', 'website-description' ) end 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 |
#setup_website_name ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/generators/binda/setup/setup_generator.rb', line 55 def setup_website_name puts "3) Setting up website name" puts "Don't worry you can modify it later." 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 name_field_setting.update_attribute( 'slug', 'website-name' ) end 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 |