Class: Radiant::Setup

Inherits:
Object show all
Extended by:
Forwardable
Defined in:
lib/radiant/setup.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#configObject

Returns the value of attribute config.



15
16
17
# File 'lib/radiant/setup.rb', line 15

def config
  @config
end

Class Method Details

.bootstrap(config) ⇒ Object



8
9
10
11
12
# File 'lib/radiant/setup.rb', line 8

def bootstrap(config)
  setup = new
  setup.bootstrap(config)
  setup
end

Instance Method Details

#bootstrap(config) ⇒ Object



17
18
19
20
21
22
23
24
# File 'lib/radiant/setup.rb', line 17

def bootstrap(config)
  @config = config
  @admin = create_admin_user(config[:admin_name], config[:admin_username], config[:admin_password])
  UserActionObserver.current_user = @admin
  load_default_configuration
  load_database_template(config[:database_template])
  announce "Finished.\n\n"
end

#create_admin_user(name, username, password) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/radiant/setup.rb', line 26

def create_admin_user(name, username, password)
  unless name and username and password
    announce "Create the admin user (press enter for defaults)."
    name = prompt_for_admin_name unless name
    username = prompt_for_admin_username unless username
    password = prompt_for_admin_password unless password
  end
  attributes = {
    :name => name,
    :login => username,
    :password => password,
    :password_confirmation => password,
    :admin => true
  }
  admin = User.(username)
  admin = User.new unless admin
  admin.update_attributes(attributes)
  admin
end

#load_database_template(filename) ⇒ Object



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/radiant/setup.rb', line 57

def load_database_template(filename)
  template = nil
  if filename
    name = find_template_in_path(filename)
    unless name
      announce "Invalid template name: #{filename}"
      filename = nil
    else
      template = load_template_file(name)
    end
  end
  unless filename
    templates = find_and_load_templates("#{RADIANT_ROOT}/db/templates/*.yml")
    templates.concat find_and_load_templates("#{RAILS_ROOT}/db/templates/*.yml") if RADIANT_ROOT != RAILS_ROOT
    choose do |menu|
      menu.header = "\nSelect a database template"
      menu.prompt = "[1-#{templates.size}]: "
      menu.select_by = :index
      templates.each { |t| menu.choice(t['name']) { template = t } }
    end
  end
  create_records(template)
end

#load_default_configurationObject



46
47
48
49
50
51
52
53
54
55
# File 'lib/radiant/setup.rb', line 46

def load_default_configuration
  feedback "\nInitializing configuration" do
    step { Radiant::Config['admin.title'   ] = 'Radiant CMS' }
    step { Radiant::Config['admin.subtitle'] = 'Publishing for Small Teams' }
    step { Radiant::Config['defaults.page.parts' ] = 'body, extended' }
    step { Radiant::Config['defaults.page.status' ] = 'draft' }
    step { Radiant::Config['defaults.page.filter' ] = nil }
    step { Radiant::Config['session_timeout'] = 2.weeks }
  end
end