anadea-spark 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +5 -0
  3. data/.ruby-version +1 -0
  4. data/.travis.yml +11 -0
  5. data/CONTRIBUTING.md +32 -0
  6. data/Gemfile +3 -0
  7. data/LICENSE +21 -0
  8. data/NEWS.md +8 -0
  9. data/README.md +154 -0
  10. data/Rakefile +11 -0
  11. data/anadea-spark.gemspec +35 -0
  12. data/bin/rake +16 -0
  13. data/bin/rspec +16 -0
  14. data/bin/setup +9 -0
  15. data/bin/spark +13 -0
  16. data/lib/spark.rb +4 -0
  17. data/lib/spark/actions.rb +33 -0
  18. data/lib/spark/app_builder.rb +373 -0
  19. data/lib/spark/generators/app_generator.rb +204 -0
  20. data/lib/spark/version.rb +5 -0
  21. data/spec/features/new_project_spec.rb +136 -0
  22. data/spec/spec_helper.rb +34 -0
  23. data/spec/support/spark.rb +51 -0
  24. data/templates/Gemfile.erb +53 -0
  25. data/templates/Procfile +2 -0
  26. data/templates/README.md.erb +14 -0
  27. data/templates/assets/application.css.scss +4 -0
  28. data/templates/assets/application.js +3 -0
  29. data/templates/bin/setup.erb +30 -0
  30. data/templates/config/application.yml.sample +3 -0
  31. data/templates/config/i18n_tasks.yml +13 -0
  32. data/templates/config/initializers/disable_xml_params.rb +3 -0
  33. data/templates/config/initializers/errors.rb +34 -0
  34. data/templates/config/initializers/exception_notification.rb.erb +8 -0
  35. data/templates/config/initializers/json_encoding.rb +1 -0
  36. data/templates/config/initializers/mail_interceptor.rb +4 -0
  37. data/templates/config/initializers/rack_timeout.rb +1 -0
  38. data/templates/config/locales_en.yml.erb +19 -0
  39. data/templates/config/newrelic.yml.erb +30 -0
  40. data/templates/config/postgresql_database.yml.erb +12 -0
  41. data/templates/config/rails_secrets.yml +11 -0
  42. data/templates/dot_gitignore +15 -0
  43. data/templates/spec/rails_helper.rb +23 -0
  44. data/templates/spec/spec_helper.rb +32 -0
  45. data/templates/spec/support/action_mailer.rb +5 -0
  46. data/templates/spec/support/database_cleaner_rspec.rb +21 -0
  47. data/templates/spec/support/factory_girl_rspec.rb +3 -0
  48. data/templates/spec/support/i18n.rb +3 -0
  49. data/templates/tasks/bundler_audit.rake +12 -0
  50. data/templates/tasks/development_seeds.rake +12 -0
  51. data/templates/views/application/_analytics.html.haml +11 -0
  52. data/templates/views/application/_flashes.html.haml +4 -0
  53. data/templates/views/application/_footer.html.haml +9 -0
  54. data/templates/views/application/_javascript.html.haml +8 -0
  55. data/templates/views/application/_navigation.html.haml +12 -0
  56. data/templates/views/application/_navigation_links.html.haml +2 -0
  57. data/templates/views/layouts/application.html.haml +23 -0
  58. data/templates/views/pages/home.html.haml +4 -0
  59. metadata +178 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 8b4a5d40799eccfd20674829cc63da15c0e4a2a1
4
+ data.tar.gz: 9ad2a6f97f3013e8799ac90b2756f09cc9e95e21
5
+ SHA512:
6
+ metadata.gz: 48c3b3498386f6bc105303b8b7d32a5df0c331891e83059cfd1d3ca717fbe29c4ed252e13feb17ee042841ff05f9b101f3f9c5a6fcd01167dbab892301db11f4
7
+ data.tar.gz: 904735ad69739d8b3b1da093cfbbf92ffdab5641144c985e09ec7127b96a7e66aaa8c895214915d1b3c4c73fea97623c0a0971bf8ab610e71a23e48a4b3939b1
@@ -0,0 +1,5 @@
1
+ *.gem
2
+ *.swp
3
+ /.bundle
4
+ /tmp
5
+ /Gemfile.lock
@@ -0,0 +1 @@
1
+ 2.2.1
@@ -0,0 +1,11 @@
1
+ language: ruby
2
+ rvm: 2.2.1
3
+ cache: bundler
4
+ sudo: false
5
+ before_install:
6
+ - "echo '--colour' > ~/.rspec"
7
+ - git config --global user.name 'Travis CI'
8
+ - git config --global user.email 'travis-ci@example.com'
9
+ install: bundle install
10
+ notifications:
11
+ email: false
@@ -0,0 +1,32 @@
1
+ # Contributing
2
+
3
+ Fork the repo.
4
+
5
+ Set up your machine:
6
+
7
+ ./bin/setup
8
+
9
+ Make sure the tests pass:
10
+
11
+ rake
12
+
13
+ Make your change.
14
+ Write tests.
15
+ Make the tests pass:
16
+
17
+ rake
18
+
19
+ Write a [good commit message][commit].
20
+ Push to your fork.
21
+ [Submit a pull request][pr].
22
+
23
+ [commit]: http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html
24
+ [pr]: https://github.com/Anadea/spark/compare/
25
+
26
+ Wait for us.
27
+ We try to at least comment on pull requests within one business day.
28
+ We may suggest changes.
29
+
30
+ ## Versions
31
+
32
+ To update the Ruby version, change `.ruby-version`.
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License
2
+
3
+ Copyright (c) 2015 Dmitriy Kiriyenko and Anadea Inc.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/NEWS.md ADDED
@@ -0,0 +1,8 @@
1
+ 0.1.0 (March 27, 2015)
2
+
3
+ * We're clean and ready to become powerful!
4
+
5
+
6
+ 0.0.1 (March 26, 2015)
7
+
8
+ * We're out!
@@ -0,0 +1,154 @@
1
+ # Spark
2
+
3
+ Spark is the base Rails application used at
4
+ [Anadea](http://anadea.info).
5
+
6
+ ![Spark](https://dl.dropboxusercontent.com/u/8790751/spark.jpg)
7
+
8
+ ## Installation
9
+
10
+ First install the gem:
11
+
12
+ gem install anadea-spark
13
+
14
+ Then run:
15
+
16
+ spark projectname
17
+
18
+ This will create a Rails app in `projectname` using the latest version of Rails.
19
+
20
+ ## Customizations
21
+
22
+ Application gems:
23
+
24
+ * [Bootstrap](https://github.com/twbs/bootstrap-sass) attached
25
+ and layout configured.
26
+ * [Coffee Rails](https://github.com/rails/coffee-rails) as a Rails default.
27
+ * [Email Validator](https://github.com/balexand/email_validator) for email
28
+ validation.
29
+ * [Exception Notification](https://github.com/smartinez87/exception_notification)
30
+ for email reporting runtime errors.
31
+ * [Figaro](https://github.com/laserlemon/figaro) for application configuration.
32
+ * [Haml Rails](https://github.com/indirect/haml-rails) for templates.
33
+ * [High Voltage](https://github.com/thoughtbot/high_voltage) for static pages.
34
+ * [Jquery Rails](https://github.com/rails/jquery-rails) for JQuery as a Rails
35
+ default.
36
+ * [Postgres](https://github.com/ged/ruby-pg) for access to Postgresql database.
37
+ * [Puma](https://github.com/puma/puma) as an application server for both
38
+ development and production.
39
+ * [Rack Timeout](https://github.com/heroku/rack-timeout) to abort requests that
40
+ take too long.
41
+ * [Recipient Interceptor](https://github.com/croaky/recipient_interceptor) to
42
+ avoid accidentally sending emails to real people from staging.
43
+ * [Sass Rails](https://github.com/rails/sass-rails) as a Rails default.
44
+ * [Simple Form](https://github.com/plataformatec/simple_form) for form markup
45
+ and style – initialized for bootstrap.
46
+ * [Title](https://github.com/calebthompson/title) for storing titles in
47
+ translations.
48
+ * [Uglifier](https://github.com/lautis/uglifier) as a Rails default.
49
+
50
+ Development gems:
51
+
52
+ * [Bundler Audit](https://github.com/rubysec/bundler-audit) for scanning the
53
+ Gemfile for insecure dependencies based on published CVEs.
54
+ * [ByeBug](https://github.com/deivid-rodriguez/byebug) for interactively
55
+ debugging behavior
56
+ * [Pry Rails](https://github.com/rweng/pry-rails) for interactively exploring
57
+ objects
58
+ * [Spring](https://github.com/rails/spring) for fast Rails actions via
59
+ pre-loading
60
+ * [Spring Commands Rspec](https://github.com/jonleighton/spring-commands-rspec)
61
+ for springifying `bin/rspec` command (already initialized).
62
+ * [Web Console](https://github.com/rails/web-console) for better debugging via
63
+ in-browser IRB consoles.
64
+
65
+ Testing gems:
66
+
67
+ * [Capybara](https://github.com/jnicklas/capybara) and
68
+ [Poltergeist](https://github.com/teampoltergeist/poltergeist) for
69
+ integration testing.
70
+ * [Factory Girl](https://github.com/thoughtbot/factory_girl) for test data.
71
+ * [Formulaic](https://github.com/thoughtbot/formulaic) for integration testing
72
+ HTML forms.
73
+ * [RSpec](https://github.com/rspec/rspec) for unit testing.
74
+ * [RSpec Mocks](https://github.com/rspec/rspec-mocks) for stubbing and spying.
75
+ * [SimpleCov](https://github.com/colszowka/simplecov) for code coverage.
76
+ * [Shoulda Matchers](https://github.com/thoughtbot/shoulda-matchers) for common
77
+ RSpec matchers.
78
+ * [Timecop](https://github.com/jtrupiano/timecop-console) for testing time.
79
+ * [Webmock](https://github.com/bblimke/webmock) for testing external requests.
80
+
81
+ Tweaks and goodies:
82
+
83
+ * The [`./bin/setup`][setup] convention for new developer setup.
84
+ * Application layout set up for twitter bootstrap.
85
+ * A few nice time formats set up for localization.
86
+ * `Rack::Deflater` to [compress responses with Gzip][compress].
87
+ * A [low database connection pool limit][pool].
88
+ * `t()` and `l()` in specs without prefixing with I18n.
89
+ * An automatically-created `SECRET_KEY_BASE` environment variable in all
90
+ environments
91
+ * Google analytics set up and waiting for key.
92
+ * [Rails 12 factor][rails12factor] to deploy on Heroku
93
+ and similar.
94
+ * `Procfile` for both development and deploy to Heroku and similar.
95
+ * Configure email delivery to mailcatcher in development, install and launch
96
+ [Mailcatcher][mailcatcher].
97
+ * Raise on unpermitted parameters in all environments.
98
+ * Raise on missing translations in development and test.
99
+ * Add `.ruby-version` for Rbenv and other Ruby version managers.
100
+ * Remove comment blocks from `config/routes.rb`.
101
+
102
+ [setup]: http://robots.thoughtbot.com/bin-setup
103
+ [compress]: http://robots.thoughtbot.com/content-compression-with-rack-deflater/
104
+ [pool]: https://devcenter.heroku.com/articles/concurrency-and-database-connections
105
+ [rails12factor]: https://github.com/heroku/rails_12factor
106
+ [mailcatcher]: http://mailcatcher.me/
107
+
108
+ ## Dependencies
109
+
110
+ Spark requires the latest version of Ruby.
111
+
112
+ Some gems included in Spark have native extensions. You should have GCC
113
+ installed on your machine before generating an app with Spark.
114
+
115
+ Use [OS X GCC Installer](https://github.com/kennethreitz/osx-gcc-installer/) for
116
+ Snow Leopard (OS X 10.6).
117
+
118
+ Use [Command Line Tools for XCode](https://developer.apple.com/downloads/index.action)
119
+ for Lion (OS X 10.7) or Mountain Lion (OS X 10.8).
120
+
121
+ We use [Poltergeist](https://github.com/teampoltergeist/poltergeist) for
122
+ full-stack JavaScript integration testing. It requires PhantomJS. Instructions for
123
+ installing it are
124
+ [here](https://github.com/teampoltergeist/poltergeist#installing-phantomjs).
125
+
126
+ PostgreSQL needs to be installed and running for the `db:create` rake task.
127
+
128
+ ## Issues
129
+
130
+ If you have problems, please create a
131
+ [GitHub Issue](https://github.com/Anadea/spark/issues).
132
+
133
+ ## License
134
+
135
+ Spark is Copyright © 2015 Anadea.
136
+ It is free software,
137
+ and may be redistributed under the terms specified in the [LICENSE] file.
138
+
139
+ [LICENSE]: LICENSE
140
+
141
+ ## Thanks
142
+
143
+ To [suspenders](https://github.com/thoughtbot/suspenders).
144
+
145
+ ## About Anadea
146
+
147
+ ![anadea](https://avatars2.githubusercontent.com/u/4539766?v=3&s=200)
148
+
149
+ Spark is maintained and funded by Anadea, inc.
150
+ The names and logos for Anadea are trademarks of Anadea, inc.
151
+
152
+ We are [available for hire][hire].
153
+
154
+ [hire]: https://anadea.info/en?utm_source=github
@@ -0,0 +1,11 @@
1
+ require 'bundler/setup'
2
+ require 'bundler/gem_tasks'
3
+ require 'rspec/core/rake_task'
4
+
5
+ RSpec::Core::RakeTask.new(:rspec)
6
+ RSpec::Core::RakeTask.new(:smoke) do |t|
7
+ t.rspec_opts = "--tag smoke"
8
+ end
9
+
10
+ desc 'Run the test suite'
11
+ task :default => :rspec
@@ -0,0 +1,35 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path('../lib', __FILE__)
3
+ require 'spark/version'
4
+ require 'date'
5
+
6
+ Gem::Specification.new do |s|
7
+ s.required_ruby_version = ">= #{Spark::RUBY_VERSION}"
8
+ s.authors = ['anadea']
9
+ s.date = Date.today.strftime('%Y-%m-%d')
10
+
11
+ s.description = <<-HERE
12
+ Spark is a base Rails project that you can upgrade. It is used by anadea
13
+ to get a jump start on a working app. Use Spark if you're in a rush
14
+ to build something amazing; don't use it if you like missing deadlines.
15
+ HERE
16
+
17
+ s.email = 'dmitriy.kiriyenko@anahoret.com'
18
+ s.executables = ['spark']
19
+ s.extra_rdoc_files = %w[README.md LICENSE]
20
+ s.files = `git ls-files`.split("\n")
21
+ s.homepage = 'http://github.com/Anadea/spark'
22
+ s.license = 'MIT'
23
+ s.name = 'anadea-spark'
24
+ s.rdoc_options = ['--charset=UTF-8']
25
+ s.require_paths = ['lib']
26
+ s.summary = "Generate a Rails app using Anadea's best practices."
27
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
28
+ s.version = Spark::VERSION
29
+
30
+ s.add_dependency 'bundler', '~> 1.3'
31
+ s.add_dependency 'rails', Spark::RAILS_VERSION
32
+
33
+ s.add_development_dependency 'rspec', '>= 3.2.0', '<4'
34
+ s.add_development_dependency 'capybara', '~> 2.2', '>= 2.2.0'
35
+ end
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This file was generated by Bundler.
4
+ #
5
+ # The application 'rake' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require 'pathname'
10
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
11
+ Pathname.new(__FILE__).realpath)
12
+
13
+ require 'rubygems'
14
+ require 'bundler/setup'
15
+
16
+ load Gem.bin_path('rake', 'rake')
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This file was generated by Bundler.
4
+ #
5
+ # The application 'rspec' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require 'pathname'
10
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
11
+ Pathname.new(__FILE__).realpath)
12
+
13
+ require 'rubygems'
14
+ require 'bundler/setup'
15
+
16
+ load Gem.bin_path('rspec-core', 'rspec')
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env sh
2
+
3
+ # Run this script immediately after cloning the codebase.
4
+
5
+ # Exit if any subcommand fails
6
+ set -e
7
+
8
+ # Set up Ruby dependencies via Bundler
9
+ bundle install
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env ruby
2
+ require 'pathname'
3
+
4
+ source_path = (Pathname.new(__FILE__).dirname + '../lib').expand_path
5
+ $LOAD_PATH << source_path
6
+
7
+ require 'spark'
8
+
9
+ templates_root = File.expand_path(File.join("..", "templates"), File.dirname(__FILE__))
10
+ Spark::AppGenerator.source_root templates_root
11
+ Spark::AppGenerator.source_paths << Rails::Generators::AppGenerator.source_root << templates_root
12
+
13
+ Spark::AppGenerator.start
@@ -0,0 +1,4 @@
1
+ require 'spark/version'
2
+ require 'spark/generators/app_generator'
3
+ require 'spark/actions'
4
+ require 'spark/app_builder'
@@ -0,0 +1,33 @@
1
+ module Spark
2
+ module Actions
3
+ def replace_in_file(relative_path, find, replace)
4
+ path = File.join(destination_root, relative_path)
5
+ contents = IO.read(path)
6
+ unless contents.gsub!(find, replace)
7
+ raise "#{find.inspect} not found in #{relative_path}"
8
+ end
9
+ File.open(path, "w") { |file| file.write(contents) }
10
+ end
11
+
12
+ def action_mailer_host(rails_env, host)
13
+ config = "config.action_mailer.default_url_options = { host: #{host} }"
14
+ configure_environment(rails_env, config)
15
+ end
16
+
17
+ def configure_application_file(config)
18
+ inject_into_file(
19
+ "config/application.rb",
20
+ "\n\n #{config}",
21
+ before: "\n end"
22
+ )
23
+ end
24
+
25
+ def configure_environment(rails_env, config)
26
+ inject_into_file(
27
+ "config/environments/#{rails_env}.rb",
28
+ "\n\n #{config}",
29
+ before: "\nend"
30
+ )
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,373 @@
1
+ module Spark
2
+ class AppBuilder < Rails::AppBuilder
3
+ include Spark::Actions
4
+
5
+ def readme
6
+ template 'README.md.erb', 'README.md'
7
+ end
8
+
9
+ def raise_on_delivery_errors
10
+ replace_in_file 'config/environments/development.rb',
11
+ 'raise_delivery_errors = false', 'raise_delivery_errors = true'
12
+ end
13
+
14
+ def set_test_delivery_method
15
+ config = <<-RUBY
16
+
17
+ config.action_mailer.delivery_method = :smtp
18
+ config.action_mailer.smtp_settings = { :address => "localhost", :port => 1025 }
19
+ RUBY
20
+
21
+ inject_into_file(
22
+ "config/environments/development.rb",
23
+ config,
24
+ after: "config.action_mailer.raise_delivery_errors = true",
25
+ )
26
+ end
27
+
28
+ def raise_on_unpermitted_parameters
29
+ config = <<-RUBY
30
+ config.action_controller.action_on_unpermitted_parameters = :raise
31
+ RUBY
32
+
33
+ inject_into_class "config/application.rb", "Application", config
34
+ end
35
+
36
+ def provide_setup_script
37
+ template "bin/setup.erb", "bin/setup", force: true
38
+ run "chmod a+x bin/setup"
39
+ end
40
+
41
+ def provide_dev_prime_task
42
+ copy_file 'tasks/development_seeds.rake', 'lib/tasks/development_seeds.rake'
43
+ end
44
+
45
+ def configure_generators
46
+ config = <<-RUBY
47
+
48
+ config.generators do |generate|
49
+ generate.helper false
50
+ generate.javascript_engine false
51
+ generate.request_specs false
52
+ generate.routing_specs false
53
+ generate.stylesheets false
54
+ generate.test_framework :rspec
55
+ generate.view_specs false
56
+ end
57
+
58
+ RUBY
59
+
60
+ inject_into_class 'config/application.rb', 'Application', config
61
+ end
62
+
63
+ def set_up_factory_girl_for_rspec
64
+ copy_file 'spec/support/factory_girl_rspec.rb', 'spec/support/factory_girl.rb'
65
+ end
66
+
67
+ def configure_exception_notification
68
+ template 'config/initializers/exception_notification.rb.erb',
69
+ 'config/initializers/exception_notification.rb'
70
+ end
71
+
72
+ def configure_mailsocio
73
+ config = <<-RUBY
74
+
75
+ config.action_mailer.delivery_method = :mailsocio
76
+ config.action_mailer.smtp_settings = {
77
+ account_id: ENV.fetch("MAILSOCIO_ACCOUNT_ID"),
78
+ api_key: ENV.fetch("MAILSOCIO_API_KEY")
79
+ }
80
+ RUBY
81
+
82
+ inject_into_file 'config/environments/production.rb', config,
83
+ :after => 'config.action_mailer.raise_delivery_errors = false'
84
+ end
85
+
86
+ def enable_rack_deflater
87
+ config = <<-RUBY
88
+
89
+ # Enable deflate / gzip compression of controller-generated responses
90
+ config.middleware.use Rack::Deflater
91
+ RUBY
92
+
93
+ inject_into_file(
94
+ "config/environments/production.rb",
95
+ config,
96
+ after: serve_static_files_line
97
+ )
98
+ end
99
+
100
+ def setup_asset_host
101
+ replace_in_file 'config/environments/production.rb',
102
+ "# config.action_controller.asset_host = 'http://assets.example.com'",
103
+ 'config.action_controller.asset_host = ENV.fetch("ASSET_HOST", ENV.fetch("HOST"))'
104
+
105
+ replace_in_file 'config/initializers/assets.rb',
106
+ "config.assets.version = '1.0'",
107
+ 'config.assets.version = ENV.fetch("ASSETS_VERSION", "1.0")'
108
+
109
+ inject_into_file(
110
+ "config/environments/production.rb",
111
+ ' config.static_cache_control = "public, max-age=#{1.year.to_i}"',
112
+ after: serve_static_files_line
113
+ )
114
+ end
115
+
116
+ def setup_secret_token
117
+ template 'config/rails_secrets.yml', 'config/secrets.yml', force: true
118
+ end
119
+
120
+ def disallow_wrapping_parameters
121
+ remove_file "config/initializers/wrap_parameters.rb"
122
+ end
123
+
124
+ def create_partials
125
+ empty_directory 'app/views/application'
126
+
127
+ copy_file 'views/application/_flashes.html.haml',
128
+ 'app/views/application/_flashes.html.haml'
129
+ copy_file 'views/application/_javascript.html.haml',
130
+ 'app/views/application/_javascript.html.haml'
131
+ copy_file 'views/application/_navigation.html.haml',
132
+ 'app/views/application/_navigation.html.haml'
133
+ copy_file 'views/application/_navigation_links.html.haml',
134
+ 'app/views/application/_navigation_links.html.haml'
135
+ copy_file 'views/application/_analytics.html.haml',
136
+ 'app/views/application/_analytics.html.haml'
137
+ copy_file 'views/application/_footer.html.haml',
138
+ 'app/views/application/_footer.html.haml'
139
+ end
140
+
141
+ def create_home_page
142
+ copy_file 'views/pages/home.html.haml',
143
+ 'app/views/pages/home.html.haml'
144
+ end
145
+
146
+ def create_application_layout
147
+ remove_file 'app/views/layouts/application.html.erb'
148
+ copy_file 'views/layouts/application.html.haml',
149
+ 'app/views/layouts/application.html.haml'
150
+ end
151
+
152
+ def use_postgres_config_template
153
+ template 'config/postgresql_database.yml.erb', 'config/database.yml',
154
+ force: true
155
+ end
156
+
157
+ def create_database
158
+ bundle_command 'exec rake db:create db:migrate'
159
+ end
160
+
161
+ def replace_gemfile
162
+ remove_file 'Gemfile'
163
+ template 'Gemfile.erb', 'Gemfile'
164
+ end
165
+
166
+ def set_ruby_to_version_being_used
167
+ create_file '.ruby-version', "#{Spark::RUBY_VERSION}\n"
168
+ end
169
+
170
+ def enable_database_cleaner
171
+ copy_file 'spec/support/database_cleaner_rspec.rb', 'spec/support/database_cleaner.rb'
172
+ end
173
+
174
+ def configure_spec_support_features
175
+ empty_directory_with_keep_file 'spec/lib'
176
+ empty_directory_with_keep_file 'spec/features'
177
+
178
+ empty_directory_with_keep_file 'spec/support/matchers'
179
+ empty_directory_with_keep_file 'spec/support/mixins'
180
+ empty_directory_with_keep_file 'spec/support/shared_examples'
181
+ empty_directory_with_keep_file 'spec/support/features'
182
+ end
183
+
184
+ def configure_rspec
185
+ remove_file "spec/rails_helper.rb"
186
+ remove_file "spec/spec_helper.rb"
187
+ copy_file "spec/rails_helper.rb", "spec/rails_helper.rb"
188
+ copy_file "spec/spec_helper.rb", "spec/spec_helper.rb"
189
+ end
190
+
191
+ def configure_i18n_for_test_environment
192
+ copy_file "spec/support/i18n.rb", "spec/support/i18n.rb"
193
+ end
194
+
195
+ def configure_i18n_for_missing_translations
196
+ raise_on_missing_translations_in("development")
197
+ raise_on_missing_translations_in("test")
198
+ end
199
+
200
+ def configure_i18n_tasks
201
+ run "cp $(i18n-tasks gem-path)/templates/rspec/i18n_spec.rb spec/"
202
+ copy_file "config/i18n_tasks.yml", "config/i18n-tasks.yml"
203
+ end
204
+
205
+ def configure_background_jobs_for_rspec
206
+ run 'rails g delayed_job:active_record'
207
+ end
208
+
209
+ def configure_action_mailer_in_specs
210
+ copy_file 'spec/support/action_mailer.rb', 'spec/support/action_mailer.rb'
211
+ end
212
+
213
+ def configure_time_formats
214
+ remove_file "config/locales/en.yml"
215
+ template "config/locales_en.yml.erb", "config/locales/en.yml"
216
+ end
217
+
218
+ def configure_rack_timeout
219
+ copy_file 'config/initializers/rack_timeout.rb',
220
+ 'config/initializers/rack_timeout.rb'
221
+ end
222
+
223
+ def configure_mail_interceptor
224
+ copy_file 'config/initializers/mail_interceptor.rb',
225
+ 'config/initializers/mail_interceptor.rb'
226
+ end
227
+
228
+ def configure_simple_form
229
+ # Here we suppress simple_form warning that simple_form hasn't been configured
230
+ bundle_command "exec rails generate simple_form:install --bootstrap > /dev/null 2>&1"
231
+ end
232
+
233
+ def configure_action_mailer
234
+ action_mailer_host "development", %{"localhost:3000"}
235
+ action_mailer_host "test", %{"www.example.com"}
236
+ action_mailer_host "production", %{ENV.fetch("HOST")}
237
+ end
238
+
239
+ def configure_active_job
240
+ configure_application_file(
241
+ "config.active_job.queue_adapter = :delayed_job"
242
+ )
243
+ configure_environment "test", "config.active_job.queue_adapter = :inline"
244
+ end
245
+
246
+ def fix_i18n_deprecation_warning
247
+ config = <<-RUBY
248
+ config.i18n.enforce_available_locales = true
249
+ RUBY
250
+
251
+ inject_into_class 'config/application.rb', 'Application', config
252
+ end
253
+
254
+ def generate_rspec
255
+ generate 'rspec:install'
256
+ end
257
+
258
+ def configure_puma
259
+ bundle_command 'binstub puma'
260
+ remove_file 'bin/pumactl'
261
+ end
262
+
263
+ def setup_foreman
264
+ copy_file 'Procfile', 'Procfile'
265
+ end
266
+
267
+ def setup_figaro
268
+ copy_file 'config/application.yml.sample', 'config/application.yml.sample'
269
+ end
270
+
271
+ def setup_stylesheets
272
+ remove_file 'app/assets/stylesheets/application.css'
273
+ copy_file 'assets/application.css.scss',
274
+ 'app/assets/stylesheets/application.css.scss'
275
+ end
276
+
277
+ def setup_javascripts
278
+ remove_file 'app/assets/javascripts/application.js'
279
+ copy_file 'assets/application.js',
280
+ 'app/assets/javascripts/application.js'
281
+ end
282
+
283
+ def gitignore_files
284
+ remove_file '.gitignore'
285
+ copy_file 'dot_gitignore', '.gitignore'
286
+ end
287
+
288
+ def init_git
289
+ run 'git init'
290
+ end
291
+
292
+ def setup_bundler_audit
293
+ copy_file "tasks/bundler_audit.rake", "lib/tasks/bundler_audit.rake"
294
+ append_file "Rakefile", %{\ntask default: "bundler:audit"\n}
295
+ end
296
+
297
+ def copy_miscellaneous_files
298
+ copy_file "config/initializers/errors.rb", "config/initializers/errors.rb"
299
+ copy_file "config/initializers/json_encoding.rb", "config/initializers/json_encoding.rb"
300
+ end
301
+
302
+ def customize_error_pages
303
+ meta_tags =<<-EOS
304
+ <meta charset="utf-8" />
305
+ <meta name="ROBOTS" content="NOODP" />
306
+ <meta name="viewport" content="initial-scale=1" />
307
+ EOS
308
+
309
+ %w(500 404 422).each do |page|
310
+ inject_into_file "public/#{page}.html", meta_tags, :after => "<head>\n"
311
+ replace_in_file "public/#{page}.html", /<!--.+-->\n/, ''
312
+ end
313
+ end
314
+
315
+ def remove_routes_comment_lines
316
+ replace_in_file 'config/routes.rb',
317
+ /Rails\.application\.routes\.draw do.*end/m,
318
+ "Rails.application.routes.draw do\nend"
319
+ end
320
+
321
+ def add_root_route
322
+ route "root 'high_voltage/pages#show', id: 'home'"
323
+ end
324
+
325
+ def disable_xml_params
326
+ copy_file 'config/initializers/disable_xml_params.rb',
327
+ 'config/initializers/disable_xml_params.rb'
328
+ end
329
+
330
+ def setup_default_rake_task
331
+ append_file 'Rakefile' do
332
+ <<-EOS
333
+ task(:default).clear
334
+ task default: [:spec]
335
+
336
+ if defined? RSpec
337
+ task(:spec).clear
338
+ RSpec::Core::RakeTask.new(:spec) do |t|
339
+ t.verbose = false
340
+ end
341
+ end
342
+ EOS
343
+ end
344
+ end
345
+
346
+ def run_bin_setup
347
+ run "./bin/setup"
348
+ end
349
+
350
+ private
351
+
352
+ def raise_on_missing_translations_in(environment)
353
+ config = 'config.action_view.raise_on_missing_translations = true'
354
+
355
+ uncomment_lines("config/environments/#{environment}.rb", config)
356
+ end
357
+
358
+ def override_path_for_tests
359
+ if ENV['TESTING']
360
+ support_bin = File.expand_path(File.join('..', '..', 'spec', 'fakes', 'bin'))
361
+ "PATH=#{support_bin}:$PATH"
362
+ end
363
+ end
364
+
365
+ def generate_secret
366
+ SecureRandom.hex(64)
367
+ end
368
+
369
+ def serve_static_files_line
370
+ "config.serve_static_files = ENV['RAILS_SERVE_STATIC_FILES'].present?\n"
371
+ end
372
+ end
373
+ end