Class: Suspenders::AppBuilder
- Inherits:
-
Rails::AppBuilder
- Object
- Rails::AppBuilder
- Suspenders::AppBuilder
- Includes:
- Actions
- Defined in:
- lib/suspenders/app_builder.rb
Instance Method Summary collapse
- #add_capybara_webkit_gem ⇒ Object
- #add_clearance_gem ⇒ Object
- #add_custom_gems ⇒ Object
- #add_email_validator ⇒ Object
- #add_jquery_ui ⇒ Object
- #configure_action_mailer ⇒ Object
- #configure_capybara_webkit ⇒ Object
- #configure_rspec ⇒ Object
- #configure_time_formats ⇒ Object
- #configure_time_zone ⇒ Object
- #copy_miscellaneous_files ⇒ Object
- #create_application_layout ⇒ Object
- #create_common_javascripts ⇒ Object
- #create_database ⇒ Object
- #create_github_repo(repo_name) ⇒ Object
- #create_heroku_apps ⇒ Object
- #create_partials_directory ⇒ Object
- #create_shared_flashes ⇒ Object
- #create_shared_javascripts ⇒ Object
- #customize_error_pages ⇒ Object
- #enable_factory_girl_syntax ⇒ Object
- #generate_clearance ⇒ Object
- #generate_cucumber(options = {}) ⇒ Object
- #generate_rspec ⇒ Object
- #gitignore_files ⇒ Object
- #include_clearance_matchers ⇒ Object
- #init_git ⇒ Object
- #initialize_on_precompile ⇒ Object
- #raise_delivery_errors ⇒ Object
- #readme ⇒ Object
- #remove_public_index ⇒ Object
- #remove_rails_logo_image ⇒ Object
- #remove_routes_comment_lines ⇒ Object
- #set_attr_accessibles_on_user ⇒ Object
- #set_ruby_to_version_being_used ⇒ Object
- #setup_default_rake_task ⇒ Object
- #setup_guard_spork ⇒ Object
- #setup_root_route ⇒ Object
- #setup_staging_environment ⇒ Object
- #setup_stylesheets ⇒ Object
- #test_factories_first ⇒ Object
- #use_postgres_config_template ⇒ Object
Methods included from Actions
#action_mailer_host, #concat_file, #download_file, #replace_in_file
Instance Method Details
#add_capybara_webkit_gem ⇒ Object
97 98 99 100 |
# File 'lib/suspenders/app_builder.rb', line 97 def inject_into_file 'Gemfile', "\n gem 'capybara-webkit'", :after => /gem 'capybara'/ end |
#add_clearance_gem ⇒ Object
92 93 94 95 |
# File 'lib/suspenders/app_builder.rb', line 92 def add_clearance_gem inject_into_file 'Gemfile', "\ngem 'clearance'", :after => /gem 'jquery-rails'/ end |
#add_custom_gems ⇒ Object
85 86 87 88 89 90 |
# File 'lib/suspenders/app_builder.rb', line 85 def add_custom_gems additions_path = find_in_source_paths('Gemfile_additions') new_gems = File.open(additions_path).read inject_into_file 'Gemfile', "\n#{new_gems}", :after => /gem 'jquery-rails'/ end |
#add_email_validator ⇒ Object
258 259 260 |
# File 'lib/suspenders/app_builder.rb', line 258 def add_email_validator copy_file 'email_validator.rb', 'app/validators/email_validator.rb' end |
#add_jquery_ui ⇒ Object
66 67 68 69 |
# File 'lib/suspenders/app_builder.rb', line 66 def add_jquery_ui inject_into_file 'app/assets/javascripts/application.js', "//= require jquery-ui\n", :before => '//= require_tree .' end |
#configure_action_mailer ⇒ Object
135 136 137 138 139 140 |
# File 'lib/suspenders/app_builder.rb', line 135 def configure_action_mailer action_mailer_host 'development', "#{app_name}.local" action_mailer_host 'test', 'www.example.com' action_mailer_host 'staging', "staging.#{app_name}.com" action_mailer_host 'production', "#{app_name}.com" end |
#configure_capybara_webkit ⇒ Object
146 147 148 149 150 |
# File 'lib/suspenders/app_builder.rb', line 146 def append_file 'spec/spec_helper.rb' do "\n Capybara.javascript_driver = :webkit" end end |
#configure_rspec ⇒ Object
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/suspenders/app_builder.rb', line 102 def configure_rspec remove_file '.rspec' copy_file 'rspec', '.rspec' prepend_file 'spec/spec_helper.rb', simplecov_init replace_in_file 'spec/spec_helper.rb', '# config.mock_with :mocha', 'config.mock_with :mocha' generators_config = "config.generators do |generate|\ngenerate.test_framework :rspec\ngenerate.helper false\ngenerate.stylesheets false\ngenerate.javascript_engine false\ngenerate.view_specs false\nend\n" inject_into_class 'config/application.rb', 'Application', generators_config end |
#configure_time_formats ⇒ Object
130 131 132 133 |
# File 'lib/suspenders/app_builder.rb', line 130 def configure_time_formats remove_file 'config/locales/en.yml' copy_file 'config_locales_en.yml', 'config/locales/en.yml' end |
#configure_time_zone ⇒ Object
123 124 125 126 127 128 |
# File 'lib/suspenders/app_builder.rb', line 123 def configure_time_zone time_zone_config = "config.active_record.default_timezone = :utc\n" inject_into_class "config/application.rb", "Application", time_zone_config end |
#copy_miscellaneous_files ⇒ Object
222 223 224 225 |
# File 'lib/suspenders/app_builder.rb', line 222 def copy_miscellaneous_files copy_file 'errors.rb', 'config/initializers/errors.rb' copy_file 'Procfile' end |
#create_application_layout ⇒ Object
56 57 58 59 60 |
# File 'lib/suspenders/app_builder.rb', line 56 def create_application_layout template 'suspenders_layout.html.erb.erb', 'app/views/layouts/application.html.erb', :force => true end |
#create_common_javascripts ⇒ Object
62 63 64 |
# File 'lib/suspenders/app_builder.rb', line 62 def create_common_javascripts directory 'javascripts', 'app/assets/javascripts' end |
#create_database ⇒ Object
76 77 78 |
# File 'lib/suspenders/app_builder.rb', line 76 def create_database bundle_command 'exec rake db:create' end |
#create_github_repo(repo_name) ⇒ Object
217 218 219 220 |
# File 'lib/suspenders/app_builder.rb', line 217 def create_github_repo(repo_name) path_addition = override_path_for_tests run "#{path_addition} hub create #{repo_name}" end |
#create_heroku_apps ⇒ Object
211 212 213 214 215 |
# File 'lib/suspenders/app_builder.rb', line 211 def create_heroku_apps path_addition = override_path_for_tests run "#{path_addition} heroku create #{app_name}-production --remote=production" run "#{path_addition} heroku create #{app_name}-staging --remote=staging" end |
#create_partials_directory ⇒ Object
44 45 46 |
# File 'lib/suspenders/app_builder.rb', line 44 def create_partials_directory empty_directory 'app/views/application' end |
#create_shared_flashes ⇒ Object
48 49 50 |
# File 'lib/suspenders/app_builder.rb', line 48 def create_shared_flashes copy_file '_flashes.html.erb', 'app/views/application/_flashes.html.erb' end |
#create_shared_javascripts ⇒ Object
52 53 54 |
# File 'lib/suspenders/app_builder.rb', line 52 def create_shared_javascripts copy_file '_javascript.html.erb', 'app/views/application/_javascript.html.erb' end |
#customize_error_pages ⇒ Object
227 228 229 230 231 232 233 234 235 236 237 238 239 240 |
# File 'lib/suspenders/app_builder.rb', line 227 def customize_error_pages ="<meta charset='utf-8' />\n<meta name='ROBOTS' content='NOODP' />\n" ="<link href='/assets/application.css' media='all' rel='stylesheet' type='text/css' />\n" %w(500 404 422).each do |page| inject_into_file "public/#{page}.html", , :after => "<head>\n" replace_in_file "public/#{page}.html", /<style.+>.+<\/style>/mi, .strip replace_in_file "public/#{page}.html", /<!--.+-->\n/, '' end end |
#enable_factory_girl_syntax ⇒ Object
22 23 24 |
# File 'lib/suspenders/app_builder.rb', line 22 def enable_factory_girl_syntax copy_file 'factory_girl_syntax_rspec.rb', 'spec/support/factory_girl.rb' end |
#generate_clearance ⇒ Object
173 174 175 |
# File 'lib/suspenders/app_builder.rb', line 173 def generate_clearance generate 'clearance:install' end |
#generate_cucumber(options = {}) ⇒ Object
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 |
# File 'lib/suspenders/app_builder.rb', line 152 def generate_cucumber( = {}) generate 'cucumber:install', '--rspec', '--capybara' inject_into_file 'config/cucumber.yml', ' -drb -r features', :after => %{default: <%= std_opts %> features} copy_file 'features_support_env.rb', 'features/support/env.rb', :force => true prepend_file 'features/support/env.rb', simplecov_init if [:webkit] inject_into_file 'features/support/env.rb', "\n Capybara.javascript_driver = :webkit", :after => /Capybara.default_selector = :css/ end end |
#generate_rspec ⇒ Object
142 143 144 |
# File 'lib/suspenders/app_builder.rb', line 142 def generate_rspec generate 'rspec:install' end |
#gitignore_files ⇒ Object
185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 |
# File 'lib/suspenders/app_builder.rb', line 185 def gitignore_files concat_file 'suspenders_gitignore', '.gitignore' [ 'app/models', 'app/assets/images', 'app/views/pages', 'db/migrate', 'log', 'spec/support', 'spec/lib', 'spec/models', 'spec/views', 'spec/controllers', 'spec/helpers', 'spec/support/matchers', 'spec/support/mixins', 'spec/support/shared_examples' ].each do |dir| empty_directory_with_gitkeep dir end end |
#include_clearance_matchers ⇒ Object
262 263 264 |
# File 'lib/suspenders/app_builder.rb', line 262 def include_clearance_matchers create_file 'spec/support/clearance.rb', "require 'clearance/testing'" end |
#init_git ⇒ Object
207 208 209 |
# File 'lib/suspenders/app_builder.rb', line 207 def init_git run 'git init' end |
#initialize_on_precompile ⇒ Object
38 39 40 41 42 |
# File 'lib/suspenders/app_builder.rb', line 38 def initialize_on_precompile inject_into_file 'config/application.rb', "\n config.assets.initialize_on_precompile = false", :after => 'config.assets.enabled = true' end |
#raise_delivery_errors ⇒ Object
17 18 19 20 |
# File 'lib/suspenders/app_builder.rb', line 17 def raise_delivery_errors replace_in_file 'config/environments/development.rb', 'raise_delivery_errors = false', 'raise_delivery_errors = true' end |
#readme ⇒ Object
5 6 7 |
# File 'lib/suspenders/app_builder.rb', line 5 def readme template 'README.md.erb', 'README.md' end |
#remove_public_index ⇒ Object
9 10 11 |
# File 'lib/suspenders/app_builder.rb', line 9 def remove_public_index remove_file 'public/index.html' end |
#remove_rails_logo_image ⇒ Object
13 14 15 |
# File 'lib/suspenders/app_builder.rb', line 13 def remove_rails_logo_image remove_file 'app/assets/images/rails.png' end |
#remove_routes_comment_lines ⇒ Object
246 247 248 249 250 |
# File 'lib/suspenders/app_builder.rb', line 246 def remove_routes_comment_lines replace_in_file 'config/routes.rb', /Application\.routes\.draw do.*end/m, "Application.routes.draw do\nend" end |
#set_attr_accessibles_on_user ⇒ Object
252 253 254 255 256 |
# File 'lib/suspenders/app_builder.rb', line 252 def set_attr_accessibles_on_user inject_into_file 'app/models/user.rb', " attr_accessible :email, :password\n", :after => /include Clearance::User\n/ end |
#set_ruby_to_version_being_used ⇒ Object
80 81 82 83 |
# File 'lib/suspenders/app_builder.rb', line 80 def set_ruby_to_version_being_used inject_into_file 'Gemfile', "\n\nruby '#{RUBY_VERSION}'", :after => /source 'https:\/\/rubygems.org'/ end |
#setup_default_rake_task ⇒ Object
266 267 268 269 270 |
# File 'lib/suspenders/app_builder.rb', line 266 def setup_default_rake_task append_file 'Rakefile' do "task(:default).clear\ntask :default => [:spec]" end end |
#setup_guard_spork ⇒ Object
169 170 171 |
# File 'lib/suspenders/app_builder.rb', line 169 def setup_guard_spork copy_file 'Guardfile', 'Guardfile' end |
#setup_root_route ⇒ Object
242 243 244 |
# File 'lib/suspenders/app_builder.rb', line 242 def setup_root_route route "root :to => 'Clearance::Sessions#new'" end |
#setup_staging_environment ⇒ Object
31 32 33 34 35 36 |
# File 'lib/suspenders/app_builder.rb', line 31 def setup_staging_environment run 'cp config/environments/production.rb config/environments/staging.rb' inject_into_file 'config/environments/staging.rb', "\n config.action_mailer.delivery_method = :override_recipient_smtp, to: '[email protected]'", :after => 'config.action_mailer.raise_delivery_errors = false' end |
#setup_stylesheets ⇒ Object
177 178 179 180 181 182 183 |
# File 'lib/suspenders/app_builder.rb', line 177 def setup_stylesheets copy_file 'app/assets/stylesheets/application.css', 'app/assets/stylesheets/application.css.scss' remove_file 'app/assets/stylesheets/application.css' concat_file 'import_scss_styles', 'app/assets/stylesheets/application.css.scss' create_file 'app/assets/stylesheets/_screen.scss' end |
#test_factories_first ⇒ Object
26 27 28 29 |
# File 'lib/suspenders/app_builder.rb', line 26 def test_factories_first copy_file 'factories_spec.rb', 'spec/models/factories_spec.rb' append_file 'Rakefile', factories_spec_rake_task end |
#use_postgres_config_template ⇒ Object
71 72 73 74 |
# File 'lib/suspenders/app_builder.rb', line 71 def use_postgres_config_template template 'postgresql_database.yml.erb', 'config/database.yml', :force => true end |