class Cambium::AppGenerator
Public Instance Methods
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
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
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 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 a User
model
# File lib/generators/cambium/app_generator.rb, line 144 def add_devise_user_model generate "devise User" end
Add custom gitignore file
# File lib/generators/cambium/app_generator.rb, line 78 def add_gitignore remove_file ".gitignore" template "gitignore", ".gitignore" end
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
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
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
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 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 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 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 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 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
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
Go through standard Devise installation
# File lib/generators/cambium/app_generator.rb, line 138 def install_devise generate "devise:install" end
Install Simple Form automatically
# File lib/generators/cambium/app_generator.rb, line 166 def install_simple_form generate "simple_form:install" end
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
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 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
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