Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 246 lines (205 sloc) 7.156 kB
517f0c3 Refactored template to a Rails AppGenerator
Harold Giménez authored
1 module Suspenders
2 class AppBuilder < Rails::AppBuilder
3 include Suspenders::Actions
4
5 def readme
4e03d4e @croaky Use consistent formatting
croaky authored
6 template 'README.md.erb', 'README.md'
517f0c3 Refactored template to a Rails AppGenerator
Harold Giménez authored
7 end
8
9 def remove_public_index
10 remove_file 'public/index.html'
11 end
12
298804d @mjankowski the rails log image starts in app/assets/images in recent rails versi…
mjankowski authored
13 def remove_rails_logo_image
14 remove_file 'app/assets/images/rails.png'
517f0c3 Refactored template to a Rails AppGenerator
Harold Giménez authored
15 end
16
b91ea65 @croaky include an email validator as seen on http://guides.rubyonrails.org/a…
croaky authored
17 def raise_delivery_errors
4e03d4e @croaky Use consistent formatting
croaky authored
18 replace_in_file 'config/environments/development.rb',
19 'raise_delivery_errors = false', 'raise_delivery_errors = true'
637427d @croaky raise delivery errors of emails in development environment. more visi…
croaky authored
20 end
21
7130e11 @mjankowski expose the factory girl syntax convenience methods to rspec and cucumber
mjankowski authored
22 def enable_factory_girl_syntax
4e03d4e @croaky Use consistent formatting
croaky authored
23 copy_file 'factory_girl_syntax_rspec.rb', 'spec/support/factory_girl.rb'
7130e11 @mjankowski expose the factory girl syntax convenience methods to rspec and cucumber
mjankowski authored
24 end
25
637427d @croaky raise delivery errors of emails in development environment. more visi…
croaky authored
26 def setup_staging_environment
4e03d4e @croaky Use consistent formatting
croaky authored
27 run 'cp config/environments/production.rb config/environments/staging.rb'
d3d6e5f @croaky Add OverrideRecipientSMTP to staging environment
croaky authored
28 inject_into_file 'config/environments/staging.rb',
29 "\n config.action_mailer.delivery_method = :override_recipient_smtp, to: 'staging@example.com'",
30 :after => 'config.action_mailer.raise_delivery_errors = false'
517f0c3 Refactored template to a Rails AppGenerator
Harold Giménez authored
31 end
32
c6f3a61 @croaky [#95] Use Heroku-compliant asset pipeline settings
croaky authored
33 def initialize_on_precompile
34 inject_into_file 'config/application.rb',
35 "\n config.assets.initialize_on_precompile = false",
36 :after => 'config.assets.enabled = true'
37 end
38
8f45973 @drapergeek Move to using app/views/application over app/views/shared for new rai…
drapergeek authored
39 def create_partials_directory
4e03d4e @croaky Use consistent formatting
croaky authored
40 empty_directory 'app/views/application'
517f0c3 Refactored template to a Rails AppGenerator
Harold Giménez authored
41 end
42
43 def create_shared_flashes
4e03d4e @croaky Use consistent formatting
croaky authored
44 copy_file '_flashes.html.erb', 'app/views/application/_flashes.html.erb'
517f0c3 Refactored template to a Rails AppGenerator
Harold Giménez authored
45 end
46
47 def create_shared_javascripts
4e03d4e @croaky Use consistent formatting
croaky authored
48 copy_file '_javascript.html.erb', 'app/views/application/_javascript.html.erb'
517f0c3 Refactored template to a Rails AppGenerator
Harold Giménez authored
49 end
50
51 def create_application_layout
4e03d4e @croaky Use consistent formatting
croaky authored
52 template 'suspenders_layout.html.erb.erb',
53 'app/views/layouts/application.html.erb',
54 :force => true
517f0c3 Refactored template to a Rails AppGenerator
Harold Giménez authored
55 end
56
57 def create_common_javascripts
4e03d4e @croaky Use consistent formatting
croaky authored
58 directory 'javascripts', 'app/assets/javascripts'
517f0c3 Refactored template to a Rails AppGenerator
Harold Giménez authored
59 end
60
61 def add_jquery_ui
4e03d4e @croaky Use consistent formatting
croaky authored
62 inject_into_file 'app/assets/javascripts/application.js',
dd64684 @mjankowski newlines need to be interpolated to actually generate newlines
mjankowski authored
63 "//= require jquery-ui\n", :before => '//= require_tree .'
517f0c3 Refactored template to a Rails AppGenerator
Harold Giménez authored
64 end
65
66 def use_postgres_config_template
826c856 @croaky [#92] Add --webkit flag
croaky authored
67 template 'postgresql_database.yml.erb', 'config/database.yml',
68 :force => true
517f0c3 Refactored template to a Rails AppGenerator
Harold Giménez authored
69 end
70
71 def create_database
4e03d4e @croaky Use consistent formatting
croaky authored
72 bundle_command 'exec rake db:create'
517f0c3 Refactored template to a Rails AppGenerator
Harold Giménez authored
73 end
74
826c856 @croaky [#92] Add --webkit flag
croaky authored
75 def add_custom_gems
244b944 Rename template directory to templates
Harold Giménez authored
76 additions_path = find_in_source_paths 'Gemfile_additions'
064b1e6 Extract Gemfile additions to an external file
Harold Giménez authored
77 new_gems = File.open(additions_path).read
826c856 @croaky [#92] Add --webkit flag
croaky authored
78 inject_into_file 'Gemfile', "\n#{new_gems}",
79 :after => /gem 'jquery-rails'/
80 end
81
82 def add_clearance_gem
83 inject_into_file 'Gemfile', "\ngem 'clearance'",
84 :after => /gem 'jquery-rails'/
85 end
86
87 def add_capybara_webkit_gem
8290c97 @croaky Remove Cucumber in favor of RSpec + Capybara
croaky authored
88 inject_into_file 'Gemfile', "\n gem 'capybara-webkit'",
89 :after => /gem 'capybara'/
517f0c3 Refactored template to a Rails AppGenerator
Harold Giménez authored
90 end
91
92 def configure_rspec
93 generators_config = <<-RUBY
da91a2b @croaky [#22] Create less cruft when generating controller
croaky authored
94 config.generators do |generate|
95 generate.test_framework :rspec
96 generate.helper false
97 generate.stylesheets false
98 generate.javascript_engine false
99 generate.view_specs false
100 end
517f0c3 Refactored template to a Rails AppGenerator
Harold Giménez authored
101 RUBY
4e03d4e @croaky Use consistent formatting
croaky authored
102 inject_into_class 'config/application.rb', 'Application', generators_config
517f0c3 Refactored template to a Rails AppGenerator
Harold Giménez authored
103 end
104
d8af03a @mike-burns Always store UTC in the DB
mike-burns authored
105 def configure_time_zone
106 time_zone_config = <<-RUBY
107 config.active_record.default_timezone = :utc
108 RUBY
109 inject_into_class "config/application.rb", "Application", time_zone_config
110 end
111
517f0c3 Refactored template to a Rails AppGenerator
Harold Giménez authored
112 def configure_action_mailer
4e03d4e @croaky Use consistent formatting
croaky authored
113 action_mailer_host 'development', "#{app_name}.local"
8290c97 @croaky Remove Cucumber in favor of RSpec + Capybara
croaky authored
114 action_mailer_host 'test', 'www.example.com'
4e03d4e @croaky Use consistent formatting
croaky authored
115 action_mailer_host 'staging', "staging.#{app_name}.com"
116 action_mailer_host 'production', "#{app_name}.com"
517f0c3 Refactored template to a Rails AppGenerator
Harold Giménez authored
117 end
118
119 def generate_rspec
4e03d4e @croaky Use consistent formatting
croaky authored
120 generate 'rspec:install'
78d6dab @croaky [#60] [#62] Add spork and guard
croaky authored
121 inject_into_file '.rspec', " --drb", :after => '--color'
4e03d4e @croaky Use consistent formatting
croaky authored
122 replace_in_file 'spec/spec_helper.rb',
123 '# config.mock_with :mocha', 'config.mock_with :mocha'
517f0c3 Refactored template to a Rails AppGenerator
Harold Giménez authored
124 end
125
8290c97 @croaky Remove Cucumber in favor of RSpec + Capybara
croaky authored
126 def configure_capybara_webkit
127 append_file 'spec/spec_helper.rb' do
128 '\n Capybara.javascript_driver = :webkit'
826c856 @croaky [#92] Add --webkit flag
croaky authored
129 end
78d6dab @croaky [#60] [#62] Add spork and guard
croaky authored
130 end
131
132 def setup_guard_spork
133 copy_file 'Guardfile', 'Guardfile'
517f0c3 Refactored template to a Rails AppGenerator
Harold Giménez authored
134 end
135
136 def generate_clearance
4e03d4e @croaky Use consistent formatting
croaky authored
137 generate 'clearance:install'
517f0c3 Refactored template to a Rails AppGenerator
Harold Giménez authored
138 end
139
140 def setup_stylesheets
8290c97 @croaky Remove Cucumber in favor of RSpec + Capybara
croaky authored
141 copy_file 'app/assets/stylesheets/application.css',
142 'app/assets/stylesheets/application.css.scss'
4e03d4e @croaky Use consistent formatting
croaky authored
143 remove_file 'app/assets/stylesheets/application.css'
144 concat_file 'import_scss_styles', 'app/assets/stylesheets/application.css.scss'
145 create_file 'app/assets/stylesheets/_screen.scss'
517f0c3 Refactored template to a Rails AppGenerator
Harold Giménez authored
146 end
147
148 def gitignore_files
4e03d4e @croaky Use consistent formatting
croaky authored
149 concat_file 'suspenders_gitignore', '.gitignore'
8290c97 @croaky Remove Cucumber in favor of RSpec + Capybara
croaky authored
150 [
151 'app/models',
4e03d4e @croaky Use consistent formatting
croaky authored
152 'app/assets/images',
153 'app/views/pages',
154 'db/migrate',
155 'log',
156 'spec/support',
157 'spec/lib',
158 'spec/models',
159 'spec/views',
160 'spec/controllers',
161 'spec/helpers',
162 'spec/support/matchers',
163 'spec/support/mixins',
8290c97 @croaky Remove Cucumber in favor of RSpec + Capybara
croaky authored
164 'spec/support/shared_examples'
165 ].each do |dir|
517f0c3 Refactored template to a Rails AppGenerator
Harold Giménez authored
166 empty_directory_with_gitkeep dir
167 end
168 end
169
cd83855 Initialize a git repo, in preparation for --heroku flag
Harold Giménez authored
170 def init_git
4e03d4e @croaky Use consistent formatting
croaky authored
171 run 'git init'
cd83855 Initialize a git repo, in preparation for --heroku flag
Harold Giménez authored
172 end
173
50f4a2e Add support for creating heroku apps with --heroku=true
Harold Giménez authored
174 def create_heroku_apps
cd3317b @croaky [#53] Add --github option to create a github repo
croaky authored
175 path_addition = override_path_for_tests
a13e7cb @harlow Cedar is the default stack
harlow authored
176 run "#{path_addition} heroku create #{app_name}-production --remote=production"
8290c97 @croaky Remove Cucumber in favor of RSpec + Capybara
croaky authored
177 run "#{path_addition} heroku create #{app_name}-staging --remote=staging"
50f4a2e Add support for creating heroku apps with --heroku=true
Harold Giménez authored
178 end
179
cd3317b @croaky [#53] Add --github option to create a github repo
croaky authored
180 def create_github_repo(repo_name)
181 path_addition = override_path_for_tests
182 run "#{path_addition} hub create #{repo_name}"
183 end
184
4a5c154 Also copy the Procfile
Harold Giménez authored
185 def copy_miscellaneous_files
4e03d4e @croaky Use consistent formatting
croaky authored
186 copy_file 'errors.rb', 'config/initializers/errors.rb'
187 copy_file 'time_formats.rb', 'config/initializers/time_formats.rb'
188 copy_file 'Procfile'
517f0c3 Refactored template to a Rails AppGenerator
Harold Giménez authored
189 end
190
3ebdbb7 @mjankowski Replace the default styling of the static error pages with something …
mjankowski authored
191 def customize_error_pages
192 meta_tags =<<-EOS
4e03d4e @croaky Use consistent formatting
croaky authored
193 <meta charset='utf-8' />
194 <meta name='ROBOTS' content='NOODP' />
3ebdbb7 @mjankowski Replace the default styling of the static error pages with something …
mjankowski authored
195 EOS
196 style_tags =<<-EOS
4e03d4e @croaky Use consistent formatting
croaky authored
197 <link href='/assets/application.css' media='all' rel='stylesheet' type='text/css' />
3ebdbb7 @mjankowski Replace the default styling of the static error pages with something …
mjankowski authored
198 EOS
199 %w(500 404 422).each do |page|
dd64684 @mjankowski newlines need to be interpolated to actually generate newlines
mjankowski authored
200 inject_into_file "public/#{page}.html", meta_tags, :after => "<head>\n"
3ebdbb7 @mjankowski Replace the default styling of the static error pages with something …
mjankowski authored
201 replace_in_file "public/#{page}.html", /<style.+>.+<\/style>/mi, style_tags.strip
202 replace_in_file "public/#{page}.html", /<!--.+-->\n/, ''
203 end
204 end
205
517f0c3 Refactored template to a Rails AppGenerator
Harold Giménez authored
206 def setup_root_route
207 route "root :to => 'Clearance::Sessions#new'"
208 end
209
0c7a3a6 @mjankowski Remove the huge block of comments in the generated routes file
mjankowski authored
210 def remove_routes_comment_lines
8290c97 @croaky Remove Cucumber in favor of RSpec + Capybara
croaky authored
211 replace_in_file 'config/routes.rb',
212 /Application\.routes\.draw do.*end/m,
213 "Application.routes.draw do\nend"
0c7a3a6 @mjankowski Remove the huge block of comments in the generated routes file
mjankowski authored
214 end
215
c3dd8ab Set attr_accessible on the right attributes on User
Harold Giménez authored
216 def set_attr_accessibles_on_user
4e03d4e @croaky Use consistent formatting
croaky authored
217 inject_into_file 'app/models/user.rb',
dd64684 @mjankowski newlines need to be interpolated to actually generate newlines
mjankowski authored
218 " attr_accessible :email, :password\n",
c3dd8ab Set attr_accessible on the right attributes on User
Harold Giménez authored
219 :after => /include Clearance::User\n/
220 end
6436933 Inject clearance/testing in spec/support/clearance.rb
Harold Giménez authored
221
b91ea65 @croaky include an email validator as seen on http://guides.rubyonrails.org/a…
croaky authored
222 def add_email_validator
4e03d4e @croaky Use consistent formatting
croaky authored
223 copy_file 'email_validator.rb', 'app/validators/email_validator.rb'
b91ea65 @croaky include an email validator as seen on http://guides.rubyonrails.org/a…
croaky authored
224 end
225
6436933 Inject clearance/testing in spec/support/clearance.rb
Harold Giménez authored
226 def include_clearance_matchers
4e03d4e @croaky Use consistent formatting
croaky authored
227 create_file 'spec/support/clearance.rb', "require 'clearance/testing'"
6436933 Inject clearance/testing in spec/support/clearance.rb
Harold Giménez authored
228 end
3131d45 Add a default rake task that runs spec and cukes
Harold Giménez authored
229
230 def setup_default_rake_task
4e03d4e @croaky Use consistent formatting
croaky authored
231 append_file 'Rakefile' do
8290c97 @croaky Remove Cucumber in favor of RSpec + Capybara
croaky authored
232 "task(:default).clear\ntask :default => [:spec]"
3131d45 Add a default rake task that runs spec and cukes
Harold Giménez authored
233 end
234 end
cd3317b @croaky [#53] Add --github option to create a github repo
croaky authored
235
236 private
237
238 def override_path_for_tests
239 if ENV['TESTING']
240 support_bin = File.expand_path(File.join('..', '..', '..', 'features', 'support', 'bin'))
241 "PATH=#{support_bin}:$PATH"
242 end
243 end
517f0c3 Refactored template to a Rails AppGenerator
Harold Giménez authored
244 end
245 end
Something went wrong with that request. Please try again.