Class: Bretels::AppBuilder

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

Instance Method Summary collapse

Methods included from Actions

#action_mailer_host, #concat_file, #download_file, #replace_in_file

Instance Method Details

#add_cdn_settingsObject



34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/bretels/app_builder.rb', line 34

def add_cdn_settings
  config = "\\n\\n  # Cloudfront settings\n  # config.static_cache_control = \"public, max-age=31536000\"\n  # config.action_controller.asset_host = ENV['ASSET_HOST']\n  RUBY\n\n  inject_into_file 'config.ru', \"use Rack::Deflater\\n\",\n    :before => \"run \#{app_const}\"\n\n  inject_into_file 'config/environments/production.rb', config.rstrip,\n    :after => \"config.assets.digest = true\"\nend\n"

#add_email_validatorObject



248
249
250
# File 'lib/bretels/app_builder.rb', line 248

def add_email_validator
  copy_file 'email_validator.rb', 'app/validators/email_validator.rb'
end

#configure_action_mailerObject



172
173
174
175
176
# File 'lib/bretels/app_builder.rb', line 172

def configure_action_mailer
  action_mailer_host 'development', "#{app_name}.dev"
  action_mailer_host 'test', 'www.example.com'
  action_mailer_host 'production', "#{app_name}.nl"
end

#configure_dutch_languageObject



158
159
160
161
162
# File 'lib/bretels/app_builder.rb', line 158

def configure_dutch_language
  replace_in_file 'config/application.rb',
    '# config.i18n.default_locale = :de',
    "config.i18n.default_locale = :nl\n    config.i18n.available_locales = :nl"
end

#configure_rack_timeoutObject



168
169
170
# File 'lib/bretels/app_builder.rb', line 168

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

#configure_rspecObject



129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
# File 'lib/bretels/app_builder.rb', line 129

def configure_rspec
  config = "\n# Hand-pick the generators we use\nconfig.generators do |generate|\n  generate.test_framework :rspec\n  generate.helper false\n  generate.stylesheets false\n  generate.javascript_engine false\n  generate.request_specs false\n  generate.routing_specs false\n  generate.view_specs false\nend\n\n  RUBY\n\n  inject_into_class 'config/application.rb', 'Application', config\nend\n"

#configure_smtpObject



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/bretels/app_builder.rb', line 48

def configure_smtp
  config = "\\n\\n  ActionMailer::Base.smtp_settings = {\n:address        => 'smtp.sendgrid.net',\n:port           => '587',\n:authentication => :plain,\n:user_name      => ENV['SENDGRID_USERNAME'],\n:password       => ENV['SENDGRID_PASSWORD'],\n:domain         => 'herokuapp.com',\n:enable_starttls_auto => true\n  }\n  config.action_mailer.delivery_method = :smtp\n  RUBY\n\n  inject_into_file 'config/environments/production.rb', config.rstrip,\n    :after => 'config.action_mailer.raise_delivery_errors = false'\n\n  inject_into_file(\n    \"config/environments/development.rb\",\n    \"\\n\\n  config.action_mailer.delivery_method = :letter_opener\",\n    :before => \"\\nend\"\n  )\nend\n"

#configure_strong_parametersObject



148
149
150
# File 'lib/bretels/app_builder.rb', line 148

def configure_strong_parameters
  copy_file 'strong_parameters.rb', 'config/initializers/strong_parameters.rb'
end

#configure_time_formatsObject



164
165
166
# File 'lib/bretels/app_builder.rb', line 164

def configure_time_formats
  copy_file 'config_locales_nl.yml', 'config/locales/nl.yml'
end

#configure_time_zoneObject



152
153
154
155
156
# File 'lib/bretels/app_builder.rb', line 152

def configure_time_zone
  replace_in_file 'config/application.rb',
    "# config.time_zone = 'Central Time (US & Canada)'",
    "config.time_zone = 'Amsterdam'"
end

#copy_miscellaneous_filesObject



222
223
224
# File 'lib/bretels/app_builder.rb', line 222

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

#create_application_layoutObject



104
105
106
107
108
# File 'lib/bretels/app_builder.rb', line 104

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

#create_github_repo(repo_name) ⇒ Object



218
219
220
# File 'lib/bretels/app_builder.rb', line 218

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

#create_heroku_appsObject



212
213
214
215
216
# File 'lib/bretels/app_builder.rb', line 212

def create_heroku_apps
  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



92
93
94
# File 'lib/bretels/app_builder.rb', line 92

def create_partials_directory
  empty_directory 'app/views/application'
end

#create_shared_flashesObject



96
97
98
# File 'lib/bretels/app_builder.rb', line 96

def create_shared_flashes
  copy_file '_flashes.html.erb', 'app/views/application/_flashes.html.erb'
end

#create_shared_javascriptsObject



100
101
102
# File 'lib/bretels/app_builder.rb', line 100

def create_shared_javascripts
  copy_file '_javascript.html.erb', 'app/views/application/_javascript.html.erb'
end

#customize_error_pagesObject



226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
# File 'lib/bretels/app_builder.rb', line 226

def customize_error_pages
  meta_tags ="  <meta charset='utf-8' />\n  <meta name='robots' content='noodp' />\n  EOS\n  style_tags =<<-EOS\n<link href='/assets/application.css' media='all' rel='stylesheet' type='text/css' />\n  EOS\n\n  %w(500 404 422).each do |page|\n    inject_into_file \"public/\#{page}.html\", meta_tags, :after => \"<head>\\n\"\n    replace_in_file \"public/\#{page}.html\", /<style.+>.+<\\/style>/mi, style_tags.strip\n    replace_in_file \"public/\#{page}.html\", /<!--.+-->\\n/, ''\n  end\nend\n"

#disable_xml_paramsObject



252
253
254
# File 'lib/bretels/app_builder.rb', line 252

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

#enable_database_cleanerObject



125
126
127
# File 'lib/bretels/app_builder.rb', line 125

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

#enable_factory_girl_syntaxObject



22
23
24
# File 'lib/bretels/app_builder.rb', line 22

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

#enable_force_sslObject



72
73
74
75
# File 'lib/bretels/app_builder.rb', line 72

def enable_force_ssl
  replace_in_file 'config/environments/production.rb',
    '# config.force_ssl = true', 'config.force_ssl = true'
end

#generate_factories_fileObject



30
31
32
# File 'lib/bretels/app_builder.rb', line 30

def generate_factories_file
  template 'factories.rb', 'spec/factories.rb'
end

#generate_rspecObject



178
179
180
# File 'lib/bretels/app_builder.rb', line 178

def generate_rspec
  copy_file 'spec_helper.rb', 'spec/spec_helper.rb'
end

#gitignore_filesObject



193
194
195
196
197
198
199
200
201
202
203
204
# File 'lib/bretels/app_builder.rb', line 193

def gitignore_files
  concat_file 'suspenders_gitignore', '.gitignore'
  [
    'spec/support',
    'spec/lib',
    'spec/features',
    'spec/models',
  ].each do |dir|
    empty_directory(dir)
    create_file("#{dir}/.gitkeep")
  end
end

#init_gitObject



206
207
208
209
210
# File 'lib/bretels/app_builder.rb', line 206

def init_git
  run 'git init'
  run 'git add .'
  run 'git commit -m "Initial commit" > /dev/null'
end

#initialize_on_precompileObject



81
82
83
84
85
# File 'lib/bretels/app_builder.rb', line 81

def initialize_on_precompile
  inject_into_file 'config/application.rb',
    "\n    config.assets.initialize_on_precompile = false",
    :after => 'config.assets.enabled = true'
end

#lib_in_load_pathObject



87
88
89
90
# File 'lib/bretels/app_builder.rb', line 87

def lib_in_load_path
  inject_into_file 'config/application.rb', "\n\n" + '    config.autoload_paths += Dir["#{config.root}/lib/**/"]',
    after: /class Application < Rails::Application/
end

#raise_delivery_errorsObject



17
18
19
20
# File 'lib/bretels/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

#raise_unpermitted_paramsObject



262
263
264
265
266
267
268
269
# File 'lib/bretels/app_builder.rb', line 262

def raise_unpermitted_params
  config = "\\n\\n  config.action_controller.action_on_unpermitted_parameters = :raise\n  RUBY\n\n  inject_into_file 'config/environments/development.rb', config.rstrip,\n    :after => \"config.assets.debug = true\"\nend\n"

#readmeObject



5
6
7
# File 'lib/bretels/app_builder.rb', line 5

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

#remove_public_indexObject



9
10
11
# File 'lib/bretels/app_builder.rb', line 9

def remove_public_index
  remove_file 'public/index.html'
end

#remove_rails_logo_imageObject



13
14
15
# File 'lib/bretels/app_builder.rb', line 13

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

#remove_routes_comment_linesObject



242
243
244
245
246
# File 'lib/bretels/app_builder.rb', line 242

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



115
116
117
118
# File 'lib/bretels/app_builder.rb', line 115

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

#set_ruby_to_version_being_usedObject



120
121
122
123
# File 'lib/bretels/app_builder.rb', line 120

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



256
257
258
259
260
# File 'lib/bretels/app_builder.rb', line 256

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

#setup_foremanObject



182
183
184
185
# File 'lib/bretels/app_builder.rb', line 182

def setup_foreman
  copy_file 'unicorn.rb', 'config/unicorn.rb'
  copy_file 'Procfile', 'Procfile'
end

#setup_staging_environmentObject



77
78
79
# File 'lib/bretels/app_builder.rb', line 77

def setup_staging_environment
  template 'staging.rb.erb', 'config/environments/staging.rb'
end

#setup_stylesheetsObject



187
188
189
190
191
# File 'lib/bretels/app_builder.rb', line 187

def setup_stylesheets
  copy_file 'app/assets/stylesheets/application.css',
    'app/assets/stylesheets/application.css.scss'
  remove_file 'app/assets/stylesheets/application.css'
end

#test_factories_firstObject



26
27
28
# File 'lib/bretels/app_builder.rb', line 26

def test_factories_first
  copy_file 'factories_spec.rb', 'spec/models/factories_spec.rb'
end

#use_postgres_config_templateObject



110
111
112
113
# File 'lib/bretels/app_builder.rb', line 110

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