Class: RailsloveSuspenders::AppBuilder

Inherits:
Rails::AppBuilder
  • Object
show all
Includes:
Actions
Defined in:
lib/railslove-suspenders/app_builder.rb

Instance Method Summary collapse

Methods included from Actions

#action_mailer_host, #concat_file, #configure_environment, #download_file, #replace_in_file

Instance Method Details

#add_default_stylesheetsObject



71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/railslove-suspenders/app_builder.rb', line 71

def add_default_stylesheets
  copy_file 'stylesheets/application.css.sass', 'app/assets/stylesheets/application.css.sass'
  copy_file 'stylesheets/_shame.css.sass', 'app/assets/stylesheets/_shame.css.sass'
  copy_file 'stylesheets/base/_colors.css.sass', 'app/assets/stylesheets/base/_colors.css.sass'
  copy_file 'stylesheets/base/_dimension.css.sass', 'app/assets/stylesheets/base/_dimensions.css.sass'
  copy_file 'stylesheets/base/_element_defaults.css.sass', 'app/assets/stylesheets/base/_element_defaults.css.sass'
  copy_file 'stylesheets/base/_icon_font.css.sass', 'app/assets/stylesheets/base/_icon_font.css.sass'
  copy_file 'stylesheets/base/_sprites.css.sass', 'app/assets/stylesheets/base/_sprites.css.sass'
  copy_file 'stylesheets/base/_typography.css.sass', 'app/assets/stylesheets/base/_typography.css.sass'
  copy_file 'stylesheets/base/_global_mixins.css.sass', 'app/assets/stylesheets/base/_global_mixins.css.sass'

end

#configure_action_mailerObject



183
184
185
186
187
188
# File 'lib/railslove-suspenders/app_builder.rb', line 183

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_background_jobs_for_rspecObject



161
162
163
164
# File 'lib/railslove-suspenders/app_builder.rb', line 161

def configure_background_jobs_for_rspec
  copy_file 'background_jobs_rspec.rb', 'spec/support/background_jobs.rb'
  run 'rails g delayed_job:active_record'
end

#configure_capybara_webkitObject



194
195
196
197
198
# File 'lib/railslove-suspenders/app_builder.rb', line 194

def configure_capybara_webkit
  append_file 'spec/spec_helper.rb' do
    "\nCapybara.javascript_driver = :webkit\n"
  end
end

#configure_rack_timeoutObject



179
180
181
# File 'lib/railslove-suspenders/app_builder.rb', line 179

def configure_rack_timeout
  copy_file 'rack_timeout.rb', 'config/initializers/rack_timeout.rb'
end

#configure_rspecObject



134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
# File 'lib/railslove-suspenders/app_builder.rb', line 134

def configure_rspec
  remove_file '.rspec'
  copy_file 'rspec', '.rspec'

  rspec_expect_syntax = <<-RUBY

  config.expect_with :rspec do |c|
c.syntax = :expect
  end
  RUBY

  config = <<-RUBY
config.generators do |generate|
  generate.test_framework :rspec
  generate.helper false
  generate.stylesheets false
  generate.javascript_engine false
  generate.view_specs false
end

  RUBY

  inject_into_file 'spec/spec_helper.rb', rspec_expect_syntax,
    :after => 'RSpec.configure do |config|'
  inject_into_class 'config/application.rb', 'Application', config
end

#configure_smtpObject



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/railslove-suspenders/app_builder.rb', line 41

def configure_smtp
  copy_file 'smtp.rb', 'config/initializers/smtp.rb'

  prepend_file 'config/environments/production.rb',
    "require Rails.root.join('config/initializers/smtp')\n"

  config = <<-RUBY

  config.action_mailer.delivery_method = :smtp
  config.action_mailer.smtp_settings = SMTP_SETTINGS
  RUBY

  inject_into_file 'config/environments/production.rb', config,
    :after => 'config.action_mailer.raise_delivery_errors = false'
end

#configure_time_formatsObject



174
175
176
177
# File 'lib/railslove-suspenders/app_builder.rb', line 174

def configure_time_formats
  remove_file 'config/locales/en.yml'
  copy_file 'config_locales_en.yml', 'config/locales/en.yml'
end

#configure_time_zoneObject



166
167
168
169
170
171
172
# File 'lib/railslove-suspenders/app_builder.rb', line 166

def configure_time_zone
  config = <<-RUBY
config.active_record.default_timezone = :utc

  RUBY
  inject_into_class 'config/application.rb', 'Application', config
end

#configure_unicornObject



204
205
206
# File 'lib/railslove-suspenders/app_builder.rb', line 204

def configure_unicorn
  copy_file 'unicorn.rb', 'config/unicorn.rb'
end

#copy_miscellaneous_filesObject



250
251
252
# File 'lib/railslove-suspenders/app_builder.rb', line 250

def copy_miscellaneous_files
  copy_file 'errors.rb', 'config/initializers/errors.rb'
end

#create_application_layoutObject



92
93
94
95
96
97
# File 'lib/railslove-suspenders/app_builder.rb', line 92

def create_application_layout
  remove_file 'app/views/layouts/application.html.erb'
  template 'suspenders_layout.html.haml',
    'app/views/layouts/application.html.haml',
    :force => true
end

#create_common_javascriptsObject



99
100
101
# File 'lib/railslove-suspenders/app_builder.rb', line 99

def create_common_javascripts
  directory 'javascripts', 'app/assets/javascripts'
end

#create_databaseObject



108
109
110
# File 'lib/railslove-suspenders/app_builder.rb', line 108

def create_database
  bundle_command 'exec rake db:create'
end

#create_github_repo(repo_name) ⇒ Object



245
246
247
248
# File 'lib/railslove-suspenders/app_builder.rb', line 245

def create_github_repo(repo_name)
  path_addition = override_path_for_tests
  run "#{path_addition} hub create #{repo_name}"
end

#create_heroku_appsObject



238
239
240
241
242
243
# File 'lib/railslove-suspenders/app_builder.rb', line 238

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"
  run "#{path_addition} heroku config:add RACK_ENV=staging RAILS_ENV=staging --remote=staging"
end

#create_partials_directoryObject



64
65
66
67
68
69
# File 'lib/railslove-suspenders/app_builder.rb', line 64

def create_partials_directory
  empty_directory 'app/assets/stylesheets/base'
  empty_directory 'app/assets/stylesheets/modules'
  empty_directory 'app/assets/stylesheets/layout'
  empty_directory 'app/assets/stylesheets/controllers'
end

#create_shared_flashesObject



84
85
86
# File 'lib/railslove-suspenders/app_builder.rb', line 84

def create_shared_flashes
  copy_file '_flashes.html.haml', 'app/views/layouts/_flashes.html.haml'
end

#create_shared_javascriptsObject



88
89
90
# File 'lib/railslove-suspenders/app_builder.rb', line 88

def create_shared_javascripts
  copy_file '_javascript.html.haml', 'app/views/layouts/_javascript.html.haml'
end

#customize_error_pagesObject



254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
# File 'lib/railslove-suspenders/app_builder.rb', line 254

def customize_error_pages
  meta_tags =<<-EOS
  <meta charset='utf-8' />
  <meta name='ROBOTS' content='NOODP' />
  EOS
  style_tags =<<-EOS
<link href='/assets/application.css' media='all' rel='stylesheet' type='text/css' />
  EOS

  %w(500 404 422).each do |page|
    inject_into_file "public/#{page}.html", meta_tags, :after => "<head>\n"
    replace_in_file "public/#{page}.html", /<style.+>.+<\/style>/mi, style_tags.strip
    replace_in_file "public/#{page}.html", /<!--.+-->\n/, ''
  end
end

#disable_xml_paramsObject



276
277
278
# File 'lib/railslove-suspenders/app_builder.rb', line 276

def disable_xml_params
  copy_file 'disable_xml_params.rb', 'config/initializers/disable_xml_params.rb'
end

#enable_database_cleanerObject



122
123
124
125
126
127
128
# File 'lib/railslove-suspenders/app_builder.rb', line 122

def enable_database_cleaner
  replace_in_file 'spec/spec_helper.rb',
    'config.use_transactional_fixtures = true',
    'config.use_transactional_fixtures = false'

  copy_file 'database_cleaner_rspec.rb', 'spec/support/database_cleaner.rb'
end

#enable_factory_girl_syntaxObject



32
33
34
# File 'lib/railslove-suspenders/app_builder.rb', line 32

def enable_factory_girl_syntax
  copy_file 'factory_girl_syntax_rspec.rb', 'spec/support/factory_girl.rb'
end

#enable_strong_parameter_matcherObject



130
131
132
# File 'lib/railslove-suspenders/app_builder.rb', line 130

def enable_strong_parameter_matcher
  copy_file 'strong_parameter_matcher.rb', 'spec/support/matchers/strong_parameter_matcher.rb'
end

#generate_clearanceObject



200
201
202
# File 'lib/railslove-suspenders/app_builder.rb', line 200

def generate_clearance
  generate 'clearance:install'
end

#generate_rspecObject



190
191
192
# File 'lib/railslove-suspenders/app_builder.rb', line 190

def generate_rspec
  generate 'rspec:install'
end

#gitignore_filesObject



219
220
221
222
223
224
225
226
227
228
229
230
231
232
# File 'lib/railslove-suspenders/app_builder.rb', line 219

def gitignore_files
  concat_file 'suspenders_gitignore', '.gitignore'
  [
    'spec/lib',
    'spec/controllers',
    'spec/helpers',
    'spec/support/matchers',
    'spec/support/mixins',
    'spec/support/shared_examples'
  ].each do |dir|
    run "mkdir #{dir}"
    run "touch #{dir}/.keep"
  end
end

#init_gitObject



234
235
236
# File 'lib/railslove-suspenders/app_builder.rb', line 234

def init_git
  run 'git init'
end

#provide_setup_scriptObject



27
28
29
30
# File 'lib/railslove-suspenders/app_builder.rb', line 27

def provide_setup_script
  copy_file 'bin_setup', 'bin/setup'
  run 'chmod a+x bin/setup'
end

#raise_on_delivery_errorsObject



17
18
19
20
# File 'lib/railslove-suspenders/app_builder.rb', line 17

def raise_on_delivery_errors
  replace_in_file 'config/environments/development.rb',
    'raise_delivery_errors = false', 'raise_delivery_errors = true'
end

#raise_on_unpermitted_parametersObject



22
23
24
25
# File 'lib/railslove-suspenders/app_builder.rb', line 22

def raise_on_unpermitted_parameters
  configure_environment 'development',
    'config.action_controller.action_on_unpermitted_parameters = :raise'
end

#readmeObject



5
6
7
# File 'lib/railslove-suspenders/app_builder.rb', line 5

def readme
  template 'README.md.erb', 'README.md'
end

#remove_public_indexObject



9
10
11
# File 'lib/railslove-suspenders/app_builder.rb', line 9

def remove_public_index
  remove_file 'public/index.html'
end

#remove_rails_logo_imageObject



13
14
15
# File 'lib/railslove-suspenders/app_builder.rb', line 13

def remove_rails_logo_image
  remove_file 'app/assets/images/rails.png'
end

#remove_routes_comment_linesObject



270
271
272
273
274
# File 'lib/railslove-suspenders/app_builder.rb', line 270

def remove_routes_comment_lines
  replace_in_file 'config/routes.rb',
    /Application\.routes\.draw do.*end/m,
    "Application.routes.draw do\nend"
end

#replace_gemfileObject



112
113
114
115
# File 'lib/railslove-suspenders/app_builder.rb', line 112

def replace_gemfile
  remove_file 'Gemfile'
  copy_file 'Gemfile_clean', 'Gemfile'
end

#set_ruby_to_version_being_usedObject



117
118
119
120
# File 'lib/railslove-suspenders/app_builder.rb', line 117

def set_ruby_to_version_being_used
  inject_into_file 'Gemfile', "\n\nruby '#{RUBY_VERSION}'",
    after: /source 'https:\/\/rubygems.org'/
end

#setup_default_rake_taskObject



280
281
282
283
284
# File 'lib/railslove-suspenders/app_builder.rb', line 280

def setup_default_rake_task
  append_file 'Rakefile' do
    "task(:default).clear\ntask :default => [:spec]\n"
  end
end

#setup_foremanObject



208
209
210
211
# File 'lib/railslove-suspenders/app_builder.rb', line 208

def setup_foreman
  copy_file 'sample.env', '.sample.env'
  copy_file 'Procfile', 'Procfile'
end

#setup_staging_environmentObject



57
58
59
60
61
62
# File 'lib/railslove-suspenders/app_builder.rb', line 57

def setup_staging_environment
  run 'cp config/environments/production.rb config/environments/staging.rb'

  # prepend_file 'config/environments/staging.rb',
  #  "Mail.register_interceptor RecipientInterceptor.new(ENV['EMAIL_RECIPIENTS'])\n"
end

#setup_stylesheetsObject



213
214
215
216
217
# File 'lib/railslove-suspenders/app_builder.rb', line 213

def setup_stylesheets
  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_firstObject



36
37
38
39
# File 'lib/railslove-suspenders/app_builder.rb', line 36

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_templateObject



103
104
105
106
# File 'lib/railslove-suspenders/app_builder.rb', line 103

def use_postgres_config_template
  template 'postgresql_database.yml.erb', 'config/database.yml',
    :force => true
end