class Cambium::AppGenerator

Public Instance Methods

add_application_config() click to toggle source

Add settings to application config file (config/application.rb)

# File lib/generators/cambium/app_generator.rb, line 65
def add_application_config
  environment { file_contents("config/application.rb") }
end
add_application_controller_redirects() click to toggle source

Override Devise's default redirects and sign in/out

# File lib/generators/cambium/app_generator.rb, line 156
def add_application_controller_redirects
  insert_into_file(
    "app/controllers/application_controller.rb",
    template_snippet("app/controllers/application_controller.rb"),
    :after => ":exception"
  )
end
add_assets_initializer() click to toggle source

Assets initializer for Rails 4.1+

# File lib/generators/cambium/app_generator.rb, line 71
def add_assets_initializer
  file = "config/initializers/assets.rb"
  template(file, file)
end
add_default_routes() click to toggle source

Add our default routes file, which is commented out except for the root path to the home controller.

We don't override routes here in case the user started to edit their routes file before running this generator.

# File lib/generators/cambium/app_generator.rb, line 200
def add_default_routes
  template "config/routes.rb", "config/routes.rb", :force => true
end
add_devise_user_model() click to toggle source

Add a User model

# File lib/generators/cambium/app_generator.rb, line 144
def add_devise_user_model
  generate "devise User"
end
add_gitignore() click to toggle source

Add custom gitignore file

# File lib/generators/cambium/app_generator.rb, line 78
def add_gitignore
  remove_file ".gitignore"
  template "gitignore", ".gitignore"
end
add_home_controller() click to toggle source

Add a default public controller, so we have a working home page when we're done.

# File lib/generators/cambium/app_generator.rb, line 86
def add_home_controller
  generate "controller home index"
end
add_js_framework() click to toggle source

We're going to automatically install backbone unless the user has disabled it

# File lib/generators/cambium/app_generator.rb, line 108
def add_js_framework
  directory("app/assets/javascripts", "app/assets/javascripts")
end
add_js_manifest() click to toggle source

Next, we need to replace our application.js file to add backbone and its dependencies, along with our default scripts.

# File lib/generators/cambium/app_generator.rb, line 116
def add_js_manifest
  app_js = "app/assets/javascripts/application.js"
  remove_file app_js
  app_js += ".coffee"
  template app_js, app_js
end
add_layouts() click to toggle source

Our layouts are templated so we can start with some custom information.

# File lib/generators/cambium/app_generator.rb, line 100
def add_layouts
  app = "app/views/layouts/application.html.erb"
  template app, app, :force => true
end
add_public_manifest() click to toggle source

Add our application.scss file. Since we don't know what file exists, we look for and delete all and replace with ours.

# File lib/generators/cambium/app_generator.rb, line 127
def add_public_manifest
  ['css','scss','scss.css'].each do |ext|
    file = "app/assets/stylesheets/application.#{ext}"
    remove_file(file) if File.exists?(file)
  end
  manifest_file = "app/assets/stylesheets/application.scss"
  template manifest_file, manifest_file
end
add_public_views() click to toggle source

Add our default public views

# File lib/generators/cambium/app_generator.rb, line 92
def add_public_views
  directory "app/views/application"
  directory "app/views/home", :force => true
end
add_ruby_class_overrides() click to toggle source

Add ruby class overrides and additions

# File lib/generators/cambium/app_generator.rb, line 172
def add_ruby_class_overrides
  template "config/initializers/_hash.rb", "config/initializers/_hash.rb"
end
add_seed_generator() click to toggle source

Add the custom seed generator, which loads content from CSV into the database.

# File lib/generators/cambium/app_generator.rb, line 189
def add_seed_generator
  remove_file "db/seeds.rb"
  template "db/seeds.rb", "db/seeds.rb"
end
add_settings_files() click to toggle source

Add our settings and private settings files

# File lib/generators/cambium/app_generator.rb, line 178
def add_settings_files
  template "config/initializers/_settings.rb",
    "config/initializers/_settings.rb"
  ['settings','private'].each do |s|
    template "config/#{s}.yml", "config/#{s}.yml"
  end
end
add_user_model_file() click to toggle source

Copy our custom user model template into the app

# File lib/generators/cambium/app_generator.rb, line 150
def add_user_model_file
  copy_file "app/models/user.rb", "app/models/user.rb", :force => true
end
install_devise() click to toggle source

Go through standard Devise installation

# File lib/generators/cambium/app_generator.rb, line 138
def install_devise
  generate "devise:install"
end
install_simple_form() click to toggle source

Install Simple Form automatically

# File lib/generators/cambium/app_generator.rb, line 166
def install_simple_form
  generate "simple_form:install"
end
set_config() click to toggle source

Wrap our config values up in an easier-to-type variable

# File lib/generators/cambium/app_generator.rb, line 35
def set_config
  @config = Cambium.configuration
end
set_precompiled_assets() click to toggle source

Add modernizr to our list of assets to precompile when we're ready to deploy

# File lib/generators/cambium/app_generator.rb, line 55
def set_precompiled_assets
  environment(
    "config.assets.precompile += %w( modernizr.js )",
    :env => "production"
  )
end
set_url_config() click to toggle source

Set root url for mailer in development and production

# File lib/generators/cambium/app_generator.rb, line 41
def set_url_config
  environment(
    "config.action_mailer.default_url_options = { :host => '#{@config.development_url}' }",
    :env => "development"
  )
  environment(
    "config.action_mailer.default_url_options = { :host => '#{@config.production_url}' }",
    :env => "production"
  )
end
verify_configuration() click to toggle source

If there is no configuration file tell the user to run that generator first (unless user has manually overridden).

# File lib/generators/cambium/app_generator.rb, line 23
def verify_configuration
  if options.config_check?
    unless File.exists?("#{Rails.root}/config/initializers/cambium.rb")
      help_message('cambium_prereqs')
      exit
    end
  end
end