bakeware 1.1.5

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 (44) hide show
  1. data/CONTRIBUTING.md +38 -0
  2. data/Gemfile +3 -0
  3. data/Gemfile.lock +114 -0
  4. data/LICENSE +21 -0
  5. data/README.md +146 -0
  6. data/Rakefile +8 -0
  7. data/bakeware.gemspec +35 -0
  8. data/bin/bakeware +11 -0
  9. data/features/clearance_false.feature +10 -0
  10. data/features/github_repo.feature +8 -0
  11. data/features/heroku_true.feature +9 -0
  12. data/features/rake_clean.feature +15 -0
  13. data/features/step_definitions/bakeware_steps.rb +79 -0
  14. data/features/support/bin/heroku +5 -0
  15. data/features/support/bin/hub +5 -0
  16. data/features/support/env.rb +10 -0
  17. data/features/support/fake_github.rb +21 -0
  18. data/features/support/fake_heroku.rb +21 -0
  19. data/lib/bakeware/actions.rb +35 -0
  20. data/lib/bakeware/app_builder.rb +215 -0
  21. data/lib/bakeware/generators/app_generator.rb +194 -0
  22. data/lib/bakeware/version.rb +3 -0
  23. data/templates/Gemfile_additions +25 -0
  24. data/templates/Gemfile_extra_meat +9 -0
  25. data/templates/Guardfile +9 -0
  26. data/templates/Procfile +1 -0
  27. data/templates/README.md.erb +8 -0
  28. data/templates/_flashes.html.erb +5 -0
  29. data/templates/_javascript.html.erb +9 -0
  30. data/templates/bakeware_gitignore +10 -0
  31. data/templates/bakeware_layout.html.erb.erb +22 -0
  32. data/templates/config_locales_en.yml +11 -0
  33. data/templates/email_validator.rb +7 -0
  34. data/templates/errors.rb +28 -0
  35. data/templates/import_scss_styles +1 -0
  36. data/templates/javascripts/prefilled_input.js +62 -0
  37. data/templates/override_recipient_smtp.rb +38 -0
  38. data/templates/postgresql_database.yml.erb +11 -0
  39. data/templates/sample.env +2 -0
  40. data/templates/script_setup +8 -0
  41. data/templates/simplecov_init.rb +2 -0
  42. data/templates/time_formats.rb +0 -0
  43. data/templates/unicorn_config +33 -0
  44. metadata +183 -0
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require File.expand_path(File.join('..', '..', 'support', 'fake_heroku'), File.dirname(__FILE__))
4
+
5
+ FakeHeroku.new(ARGV).run!
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require File.expand_path(File.join('..', '..', 'support', 'fake_github'), File.dirname(__FILE__))
4
+
5
+ FakeGithub.new(ARGV).run!
@@ -0,0 +1,10 @@
1
+ Before do
2
+ ENV['TESTING'] = 'true'
3
+ @aruba_timeout_seconds = 560
4
+ end
5
+
6
+ After do
7
+ FakeHeroku.clear!
8
+ FakeGithub.clear!
9
+ FileUtils.rm_rf 'test_project'
10
+ end
@@ -0,0 +1,21 @@
1
+ class FakeGithub
2
+ RECORDER = File.expand_path(File.join('..', '..', 'tmp', 'hub_commands'), File.dirname(__FILE__))
3
+
4
+ def initialize(args)
5
+ @args = args
6
+ end
7
+
8
+ def run!
9
+ File.open(RECORDER, 'a') do |file|
10
+ file.write @args.join(' ')
11
+ end
12
+ end
13
+
14
+ def self.clear!
15
+ FileUtils.rm_rf RECORDER
16
+ end
17
+
18
+ def self.has_created_repo?(repo_name)
19
+ File.open(RECORDER, 'r').read.include?("create #{repo_name}")
20
+ end
21
+ end
@@ -0,0 +1,21 @@
1
+ class FakeHeroku
2
+ RECORDER = File.expand_path(File.join('..', '..', 'tmp', 'heroku_commands'), File.dirname(__FILE__))
3
+
4
+ def initialize(args)
5
+ @args = args
6
+ end
7
+
8
+ def run!
9
+ File.open(RECORDER, 'a') do |file|
10
+ file.write @args.join(' ')
11
+ end
12
+ end
13
+
14
+ def self.clear!
15
+ FileUtils.rm_rf RECORDER
16
+ end
17
+
18
+ def self.has_created_app?(app_name)
19
+ File.open(RECORDER, 'r').read.include?("create #{app_name}")
20
+ end
21
+ end
@@ -0,0 +1,35 @@
1
+ module Bakeware
2
+ module Actions
3
+ def concat_file(source, destination)
4
+ contents = IO.read(find_in_source_paths(source))
5
+ append_file destination, contents
6
+ end
7
+
8
+ def replace_in_file(relative_path, find, replace)
9
+ path = File.join(destination_root, relative_path)
10
+ contents = IO.read(path)
11
+ unless contents.gsub!(find, replace)
12
+ raise "#{find.inspect} not found in #{relative_path}"
13
+ end
14
+ File.open(path, "w") { |file| file.write(contents) }
15
+ end
16
+
17
+ def action_mailer_host(rails_env, host)
18
+ inject_into_file(
19
+ "config/environments/#{rails_env}.rb",
20
+ "\n\n config.action_mailer.default_url_options = { :host => '#{host}' }",
21
+ :before => "\nend"
22
+ )
23
+ end
24
+
25
+ def download_file(uri_string, destination)
26
+ uri = URI.parse(uri_string)
27
+ http = Net::HTTP.new(uri.host, uri.port)
28
+ http.use_ssl = true if uri_string =~ /^https/
29
+ request = Net::HTTP::Get.new(uri.path)
30
+ contents = http.request(request).body
31
+ path = File.join(destination_root, destination)
32
+ File.open(path, "w") { |file| file.write(contents) }
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,215 @@
1
+ module Bakeware
2
+ class AppBuilder < Rails::AppBuilder
3
+ include Bakeware::Actions
4
+
5
+ def readme
6
+ template 'README.md.erb', 'README.md'
7
+ end
8
+
9
+ def remove_public_index
10
+ remove_file 'public/index.html'
11
+ end
12
+
13
+ def remove_rails_logo_image
14
+ remove_file 'app/assets/images/rails.png'
15
+ end
16
+
17
+ def raise_delivery_errors
18
+ replace_in_file 'config/environments/development.rb',
19
+ 'raise_delivery_errors = false', 'raise_delivery_errors = true'
20
+ end
21
+
22
+ def provide_setup_script
23
+ copy_file 'script_setup', 'script/setup'
24
+ run 'chmod a+x script/setup'
25
+ end
26
+
27
+ def setup_staging_environment
28
+ run 'cp config/environments/production.rb config/environments/staging.rb'
29
+ inject_into_file 'config/environments/staging.rb',
30
+ "\n config.action_mailer.delivery_method = :override_recipient_smtp, to: 'staging@example.com'",
31
+ :after => 'config.action_mailer.raise_delivery_errors = false'
32
+ end
33
+
34
+ def initialize_on_precompile
35
+ inject_into_file 'config/application.rb',
36
+ "\n config.assets.initialize_on_precompile = false",
37
+ :after => 'config.assets.enabled = true'
38
+ end
39
+
40
+ def create_partials_directory
41
+ empty_directory 'app/views/application'
42
+ end
43
+
44
+ def create_shared_flashes
45
+ copy_file '_flashes.html.erb', 'app/views/application/_flashes.html.erb'
46
+ end
47
+
48
+ def create_shared_javascripts
49
+ copy_file '_javascript.html.erb', 'app/views/application/_javascript.html.erb'
50
+ end
51
+
52
+ def create_application_layout
53
+ template 'bakeware_layout.html.erb.erb',
54
+ 'app/views/layouts/application.html.erb',
55
+ :force => true
56
+ end
57
+
58
+ def create_common_javascripts
59
+ directory 'javascripts', 'app/assets/javascripts'
60
+ end
61
+
62
+ def add_jquery_ui
63
+ inject_into_file 'app/assets/javascripts/application.js',
64
+ "//= require jquery-ui\n", :before => '//= require_tree .'
65
+ end
66
+
67
+ def use_postgres_config_template
68
+ template 'postgresql_database.yml.erb', 'config/database.yml',
69
+ :force => true
70
+ end
71
+
72
+ def create_database
73
+ bundle_command 'exec rake db:create'
74
+ end
75
+
76
+ def set_ruby_to_version_being_used
77
+ inject_into_file 'Gemfile', "\n\nruby '#{RUBY_VERSION}'",
78
+ :after => /source 'https:\/\/rubygems.org'/
79
+ end
80
+
81
+ def add_custom_gems
82
+ additions_path = find_in_source_paths('Gemfile_additions')
83
+ new_gems = File.open(additions_path).read
84
+ inject_into_file 'Gemfile', "\n#{new_gems}",
85
+ :after => /gem 'jquery-rails'/
86
+ end
87
+
88
+ def add_meaty_gems
89
+ meaty_path = find_in_source_paths('Gemfile_extra_meat')
90
+ meaty_gems = File.open(meaty_path).read
91
+ inject_into_file 'Gemfile', "\n#{meaty_gems}",
92
+ :after => /gem 'haml'/
93
+ end
94
+
95
+ def add_extra_config
96
+ copy_file 'unicorn_config', 'config/unicorn.rb'
97
+ end
98
+
99
+ def configure_time_zone
100
+ time_zone_config = <<-RUBY
101
+ config.active_record.default_timezone = :utc
102
+ RUBY
103
+ inject_into_class "config/application.rb", "Application", time_zone_config
104
+ end
105
+
106
+ def configure_time_formats
107
+ remove_file 'config/locales/en.yml'
108
+ copy_file 'config_locales_en.yml', 'config/locales/en.yml'
109
+ end
110
+
111
+ def configure_action_mailer
112
+ action_mailer_host 'development', "#{app_name}.local"
113
+ action_mailer_host 'test', 'www.example.com'
114
+ action_mailer_host 'staging', "staging.#{app_name}.com"
115
+ action_mailer_host 'production', "#{app_name}.com"
116
+ end
117
+
118
+ def setup_guard_spork
119
+ copy_file 'Guardfile', 'Guardfile'
120
+ end
121
+
122
+ def setup_foreman
123
+ copy_file 'sample.env', 'sample.env'
124
+ copy_file 'Procfile', 'Procfile'
125
+ end
126
+
127
+ def setup_stylesheets
128
+ copy_file 'app/assets/stylesheets/application.css',
129
+ 'app/assets/stylesheets/application.css.scss'
130
+ remove_file 'app/assets/stylesheets/application.css'
131
+ concat_file 'import_scss_styles', 'app/assets/stylesheets/application.css.scss'
132
+ create_file 'app/assets/stylesheets/_screen.scss'
133
+ end
134
+
135
+ def gitignore_files
136
+ concat_file 'bakeware_gitignore', '.gitignore'
137
+ [
138
+ 'app/models',
139
+ 'app/assets/images',
140
+ 'app/views/pages',
141
+ 'db/migrate',
142
+ 'log'
143
+ ].each do |dir|
144
+ empty_directory_with_gitkeep dir
145
+ end
146
+ end
147
+
148
+ def init_git
149
+ run 'git init'
150
+ end
151
+
152
+ def create_heroku_apps
153
+ path_addition = override_path_for_tests
154
+ run "#{path_addition} heroku create #{app_name}-production --remote=production"
155
+ run "#{path_addition} heroku create #{app_name}-staging --remote=staging"
156
+ end
157
+
158
+ def create_github_repo(repo_name)
159
+ path_addition = override_path_for_tests
160
+ run "#{path_addition} hub create #{repo_name}"
161
+ end
162
+
163
+ def copy_libraries
164
+ copy_file 'override_recipient_smtp.rb', 'lib/override_recipient_smtp.rb'
165
+ end
166
+
167
+ def copy_miscellaneous_files
168
+ copy_file 'errors.rb', 'config/initializers/errors.rb'
169
+ end
170
+
171
+ def customize_error_pages
172
+ meta_tags =<<-EOS
173
+ <meta charset='utf-8' />
174
+ <meta name='ROBOTS' content='NOODP' />
175
+ EOS
176
+ style_tags =<<-EOS
177
+ <link href='/assets/application.css' media='all' rel='stylesheet' type='text/css' />
178
+ EOS
179
+ %w(500 404 422).each do |page|
180
+ inject_into_file "public/#{page}.html", meta_tags, :after => "<head>\n"
181
+ replace_in_file "public/#{page}.html", /<style.+>.+<\/style>/mi, style_tags.strip
182
+ replace_in_file "public/#{page}.html", /<!--.+-->\n/, ''
183
+ end
184
+ end
185
+
186
+ def remove_routes_comment_lines
187
+ replace_in_file 'config/routes.rb',
188
+ /Application\.routes\.draw do.*end/m,
189
+ "Application.routes.draw do\nend"
190
+ end
191
+
192
+ def add_email_validator
193
+ copy_file 'email_validator.rb', 'app/validators/email_validator.rb'
194
+ end
195
+
196
+ def setup_default_rake_task
197
+ # append_file 'Rakefile' do
198
+ # "task(:default).clear\n"
199
+ # end
200
+ end
201
+
202
+ private
203
+
204
+ def override_path_for_tests
205
+ if ENV['TESTING']
206
+ support_bin = File.expand_path(File.join('..', '..', '..', 'features', 'support', 'bin'))
207
+ "PATH=#{support_bin}:$PATH"
208
+ end
209
+ end
210
+
211
+ def simplecov_init
212
+ IO.read find_in_source_paths('simplecov_init.rb')
213
+ end
214
+ end
215
+ end
@@ -0,0 +1,194 @@
1
+ require 'rails/generators'
2
+ require 'rails/generators/rails/app/app_generator'
3
+
4
+ module Bakeware
5
+ class AppGenerator < Rails::Generators::AppGenerator
6
+ class_option :meaty, :type => :boolean, :aliases => '-M', :default => false,
7
+ :desc => 'Add the Meaty Extra Goodness (more gems)'
8
+
9
+ class_option :database, :type => :string, :aliases => '-d', :default => 'postgresql',
10
+ :desc => "Preconfigure for selected database (options: #{DATABASES.join('/')})"
11
+
12
+ class_option :heroku, :type => :boolean, :aliases => '-H', :default => false,
13
+ :desc => 'Create staging and production Heroku apps'
14
+
15
+ class_option :github, :type => :string, :aliases => '-G', :default => nil,
16
+ :desc => 'Create Github repository and add remote origin pointed to repo'
17
+
18
+ class_option :skip_test_unit, :type => :boolean, :aliases => '-T', :default => false,
19
+ :desc => 'Skip Test::Unit files'
20
+
21
+ def finish_template
22
+ invoke :bakeware_customization
23
+ super
24
+ end
25
+
26
+ def bakeware_customization
27
+ invoke :remove_files_we_dont_need
28
+ invoke :customize_gemfile
29
+ invoke :setup_development_environment
30
+ invoke :setup_test_environment
31
+ invoke :setup_staging_environment
32
+ invoke :create_bakeware_views
33
+ invoke :create_common_javascripts
34
+ invoke :add_jquery_ui
35
+ invoke :setup_database
36
+ invoke :configure_app
37
+ invoke :setup_stylesheets
38
+ invoke :copy_libraries
39
+ invoke :copy_miscellaneous_files
40
+ invoke :customize_error_pages
41
+ invoke :remove_routes_comment_lines
42
+ invoke :setup_git
43
+ invoke :create_heroku_apps
44
+ invoke :create_github_repo
45
+ invoke :outro
46
+ end
47
+
48
+ def remove_files_we_dont_need
49
+ build :remove_public_index
50
+ build :remove_rails_logo_image
51
+ end
52
+
53
+ def setup_development_environment
54
+ say 'Setting up the development environment'
55
+ build :raise_delivery_errors
56
+ build :provide_setup_script
57
+ end
58
+
59
+ def setup_test_environment
60
+ say 'Setting up the test environment'
61
+ #still need some database cleaners in here
62
+ build :setup_guard_spork
63
+ end
64
+
65
+ def setup_staging_environment
66
+ say 'Setting up the staging environment'
67
+ build :setup_staging_environment
68
+ build :initialize_on_precompile
69
+ end
70
+
71
+ def create_bakeware_views
72
+ say 'Creating bakeware views'
73
+ build :create_partials_directory
74
+ build :create_shared_flashes
75
+ build :create_shared_javascripts
76
+ build :create_application_layout
77
+ end
78
+
79
+ def create_common_javascripts
80
+ say 'Pulling in some common javascripts'
81
+ build :create_common_javascripts
82
+ end
83
+
84
+ def add_jquery_ui
85
+ say 'Add jQuery ui to the standard application.js'
86
+ build :add_jquery_ui
87
+ end
88
+
89
+ def customize_gemfile
90
+ build :set_ruby_to_version_being_used
91
+ build :add_custom_gems
92
+
93
+ if options[:meaty]
94
+ build :add_meaty_gems
95
+ build :add_extra_config
96
+ end
97
+ say 'installing gems - BE PATIENT'
98
+
99
+ bundle_command 'install --binstubs=bin/stubs'
100
+ end
101
+
102
+ def setup_database
103
+ say 'Setting up database'
104
+
105
+ if 'postgresql' == options[:database]
106
+ build :use_postgres_config_template
107
+ end
108
+
109
+ build :create_database
110
+ end
111
+
112
+ def configure_app
113
+ say 'Configuring app'
114
+ build :configure_action_mailer
115
+ build :configure_time_zone
116
+ build :configure_time_formats
117
+
118
+ build :add_email_validator
119
+ build :setup_default_rake_task
120
+ build :setup_foreman
121
+ end
122
+
123
+ def setup_stylesheets
124
+ say 'Set up stylesheets'
125
+ build :setup_stylesheets
126
+ end
127
+
128
+ def setup_git
129
+ say 'Initializing git'
130
+ invoke :setup_gitignore
131
+ invoke :init_git
132
+ end
133
+
134
+ def create_heroku_apps
135
+ if options[:heroku]
136
+ say 'Creating Heroku apps'
137
+ build :create_heroku_apps
138
+ end
139
+ end
140
+
141
+ def create_github_repo
142
+ if options[:github]
143
+ say 'Creating Github repo'
144
+ build :create_github_repo, options[:github]
145
+ end
146
+ end
147
+
148
+ def setup_gitignore
149
+ build :gitignore_files
150
+ end
151
+
152
+ def init_git
153
+ build :init_git
154
+ end
155
+
156
+ def copy_libraries
157
+ say 'Copying libraries'
158
+ build :copy_libraries
159
+ end
160
+
161
+ def copy_miscellaneous_files
162
+ say 'Copying miscellaneous support files'
163
+ build :copy_miscellaneous_files
164
+ end
165
+
166
+ def customize_error_pages
167
+ say 'Customizing the 500/404/422 pages'
168
+ build :customize_error_pages
169
+ end
170
+
171
+ def remove_routes_comment_lines
172
+ build :remove_routes_comment_lines
173
+ end
174
+
175
+ def outro
176
+ say 'Congratulations! You just baked up a project with bakeware.'
177
+ say "Remember to run 'rails generate airbrake' with your API key."
178
+ end
179
+
180
+ def run_bundle
181
+ # Let's not: We'll bundle manually at the right spot
182
+ end
183
+
184
+ protected
185
+
186
+ def get_builder_class
187
+ Bakeware::AppBuilder
188
+ end
189
+
190
+ def using_active_record?
191
+ !options[:skip_active_record]
192
+ end
193
+ end
194
+ end