Class: TrustyCms::Setup
- Inherits:
-
Object
- Object
- TrustyCms::Setup
- Extended by:
- Forwardable
- Defined in:
- lib/trusty_cms/setup.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
Returns the value of attribute config.
Class Method Summary collapse
Instance Method Summary collapse
- #bootstrap(config) ⇒ Object
- #create_admin_user(name, username, password) ⇒ Object
- #load_database_template(filename) ⇒ Object
- #load_default_configuration ⇒ Object
Instance Attribute Details
#config ⇒ Object
Returns the value of attribute config.
14 15 16 |
# File 'lib/trusty_cms/setup.rb', line 14 def config @config end |
Class Method Details
.bootstrap(config) ⇒ Object
7 8 9 10 11 |
# File 'lib/trusty_cms/setup.rb', line 7 def bootstrap(config) setup = new setup.bootstrap(config) setup end |
Instance Method Details
#bootstrap(config) ⇒ Object
16 17 18 19 20 21 22 |
# File 'lib/trusty_cms/setup.rb', line 16 def bootstrap(config) @config = config @admin = create_admin_user(config[:admin_name], config[:admin_username], config[:admin_password]) load_default_configuration # load_database_template(config[:database_template]) announce 'Finished.' end |
#create_admin_user(name, username, password) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/trusty_cms/setup.rb', line 24 def create_admin_user(name, username, password) unless name && username && password announce 'Create the admin user (press enter for defaults).' name ||= prompt_for_admin_name username ||= prompt_for_admin_username password ||= prompt_for_admin_password end attributes = { first_name: name, email: username, password: password, password_confirmation: password, } admin = User.find_by(email: username) admin ||= User.new admin.update(attributes) admin.admin = true admin.save! admin end |
#load_database_template(filename) ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/trusty_cms/setup.rb', line 58 def load_database_template(filename) template = nil if filename name = find_template_in_path(filename) if name template = load_template_file(name) else announce "Invalid template name: #{filename}" filename = nil end end unless filename templates = find_and_load_templates("#{TRUSTY_CMS_ROOT}/db/templates/*.yml") templates.concat find_and_load_templates("#{TRUSTY_CMS_ROOT}/vendor/extensions/**/db/templates/*.yml") TrustyCms::Extension.descendants.each do |d| templates.concat find_and_load_templates(d.root + '/db/templates/*.yml') end templates.concat find_and_load_templates("#{Rails.root}/vendor/extensions/**/db/templates/*.yml") templates.concat find_and_load_templates("#{Rails.root}/db/templates/*.yml") templates.uniq! choose do || .header = "\nSelect a database template" .prompt = "[1-#{templates.size}]: " .select_by = :index templates.each { |t| .choice(t['name']) { template = t } } end end create_records(template) end |
#load_default_configuration ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/trusty_cms/setup.rb', line 45 def load_default_configuration feedback "\nInitializing configuration" do step { TrustyCms::Config['admin.title'] = 'TrustyCms CMS' } step { TrustyCms::Config['admin.subtitle'] = 'Publishing for Small Teams' } step { TrustyCms::Config['defaults.page.parts'] = 'body, extended' } step { TrustyCms::Config['defaults.page.status'] = 'Draft' } step { TrustyCms::Config['defaults.page.filter'] = nil } step { TrustyCms::Config['defaults.page.fields'] = 'Keywords, Description' } step { TrustyCms::Config['session_timeout'] = 2.weeks } step { TrustyCms::Config['default_locale'] = 'en' } end end |