intersect_rails_composer 0.0.2

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 (43) hide show
  1. checksums.yaml +7 -0
  2. data/README.textile +433 -0
  3. data/bin/intersect_rails_composer +7 -0
  4. data/lib/rails_wizard/command.rb +204 -0
  5. data/lib/rails_wizard/config.rb +88 -0
  6. data/lib/rails_wizard/diagnostics.rb +68 -0
  7. data/lib/rails_wizard/recipe.rb +114 -0
  8. data/lib/rails_wizard/recipes.rb +56 -0
  9. data/lib/rails_wizard/template.rb +111 -0
  10. data/lib/rails_wizard.rb +7 -0
  11. data/recipes/apps4.rb +150 -0
  12. data/recipes/controllers.rb +75 -0
  13. data/recipes/core.rb +14 -0
  14. data/recipes/email.rb +110 -0
  15. data/recipes/example.rb +70 -0
  16. data/recipes/extras.rb +187 -0
  17. data/recipes/frontend.rb +45 -0
  18. data/recipes/gems.rb +277 -0
  19. data/recipes/git.rb +20 -0
  20. data/recipes/init.rb +136 -0
  21. data/recipes/models.rb +109 -0
  22. data/recipes/prelaunch.rb +119 -0
  23. data/recipes/railsapps.rb +277 -0
  24. data/recipes/readme.rb +85 -0
  25. data/recipes/routes.rb +45 -0
  26. data/recipes/saas.rb +218 -0
  27. data/recipes/setup.rb +134 -0
  28. data/recipes/testing.rb +276 -0
  29. data/recipes/views.rb +57 -0
  30. data/spec/rails_wizard/config_spec.rb +108 -0
  31. data/spec/rails_wizard/recipe_spec.rb +115 -0
  32. data/spec/rails_wizard/recipes/sanity_spec.rb +30 -0
  33. data/spec/rails_wizard/recipes_spec.rb +41 -0
  34. data/spec/rails_wizard/template_spec.rb +92 -0
  35. data/spec/spec_helper.rb +11 -0
  36. data/spec/support/rails_directory.rb +17 -0
  37. data/spec/support/template_runner.rb +28 -0
  38. data/spec/test_recipes/test_recipe_in_file.rb +9 -0
  39. data/templates/helpers.erb +135 -0
  40. data/templates/layout.erb +232 -0
  41. data/templates/recipe.erb +13 -0
  42. data/version.rb +3 -0
  43. metadata +210 -0
data/recipes/core.rb ADDED
@@ -0,0 +1,14 @@
1
+ # Application template recipe for the rails_apps_composer. Change the recipe here:
2
+ # https://github.com/RailsApps/rails_apps_composer/blob/master/recipes/core.rb
3
+
4
+ ## Git
5
+ say_wizard "selected all core recipes"
6
+
7
+ __END__
8
+
9
+ name: core
10
+ description: "Select all core recipes."
11
+ author: RailsApps
12
+
13
+ requires: [git, railsapps, setup, readme, gems, testing, email, models, controllers, views, routes, frontend, init, apps4, prelaunch, saas, extras]
14
+ category: collections
data/recipes/email.rb ADDED
@@ -0,0 +1,110 @@
1
+ # Application template recipe for the rails_apps_composer. Change the recipe here:
2
+ # https://github.com/RailsApps/rails_apps_composer/blob/master/recipes/email.rb
3
+
4
+ after_bundler do
5
+ say_wizard "recipe running after 'bundle install'"
6
+ unless prefer :email, 'none'
7
+ if rails_4?
8
+ send_email_text = <<-TEXT
9
+ # Send email in development mode.
10
+ config.action_mailer.perform_deliveries = true
11
+ TEXT
12
+ inject_into_file 'config/environments/development.rb', send_email_text, :after => "config.assets.debug = true"
13
+ else
14
+ ### DEVELOPMENT
15
+ gsub_file 'config/environments/development.rb', /# Don't care if the mailer can't send/, '# ActionMailer Config'
16
+ gsub_file 'config/environments/development.rb', /config.action_mailer.raise_delivery_errors = false/ do
17
+ <<-RUBY
18
+ config.action_mailer.default_url_options = { :host => 'localhost:3000' }
19
+ config.action_mailer.delivery_method = :smtp
20
+ # change to true to allow email to be sent during development
21
+ config.action_mailer.perform_deliveries = false
22
+ config.action_mailer.raise_delivery_errors = true
23
+ config.action_mailer.default :charset => "utf-8"
24
+ RUBY
25
+ end
26
+ ### TEST
27
+ inject_into_file 'config/environments/test.rb', :before => "\nend" do
28
+ <<-RUBY
29
+ \n
30
+ # ActionMailer Config
31
+ config.action_mailer.default_url_options = { :host => 'example.com' }
32
+ RUBY
33
+ end
34
+ ### PRODUCTION
35
+ gsub_file 'config/environments/production.rb', /config.active_support.deprecation = :notify/ do
36
+ <<-RUBY
37
+ config.active_support.deprecation = :notify
38
+
39
+ config.action_mailer.default_url_options = { :host => 'example.com' }
40
+ # ActionMailer Config
41
+ # Setup for production - deliveries, no errors raised
42
+ config.action_mailer.delivery_method = :smtp
43
+ config.action_mailer.perform_deliveries = true
44
+ config.action_mailer.raise_delivery_errors = false
45
+ config.action_mailer.default :charset => "utf-8"
46
+ RUBY
47
+ end
48
+ end
49
+ end
50
+ ### GMAIL ACCOUNT
51
+ if prefer :email, 'gmail'
52
+ gmail_configuration_text = <<-TEXT
53
+ \n
54
+ config.action_mailer.smtp_settings = {
55
+ address: "smtp.gmail.com",
56
+ port: 587,
57
+ domain: ENV["DOMAIN_NAME"],
58
+ authentication: "plain",
59
+ enable_starttls_auto: true,
60
+ user_name: ENV["GMAIL_USERNAME"],
61
+ password: ENV["GMAIL_PASSWORD"]
62
+ }
63
+ TEXT
64
+ inject_into_file 'config/environments/development.rb', gmail_configuration_text, :after => "config.assets.debug = true"
65
+ inject_into_file 'config/environments/production.rb', gmail_configuration_text, :after => "config.active_support.deprecation = :notify"
66
+ end
67
+ ### SENDGRID ACCOUNT
68
+ if prefer :email, 'sendgrid'
69
+ sendgrid_configuration_text = <<-TEXT
70
+ \n
71
+ config.action_mailer.smtp_settings = {
72
+ address: "smtp.sendgrid.net",
73
+ port: 25,
74
+ domain: ENV["DOMAIN_NAME"],
75
+ authentication: "plain",
76
+ user_name: ENV["SENDGRID_USERNAME"],
77
+ password: ENV["SENDGRID_PASSWORD"]
78
+ }
79
+ TEXT
80
+ inject_into_file 'config/environments/development.rb', sendgrid_configuration_text, :after => "config.assets.debug = true"
81
+ inject_into_file 'config/environments/production.rb', sendgrid_configuration_text, :after => "config.active_support.deprecation = :notify"
82
+ end
83
+ ### MANDRILL ACCOUNT
84
+ if prefer :email, 'mandrill'
85
+ mandrill_configuration_text = <<-TEXT
86
+ \n
87
+ config.action_mailer.smtp_settings = {
88
+ :address => "smtp.mandrillapp.com",
89
+ :port => 25,
90
+ :user_name => ENV["MANDRILL_USERNAME"],
91
+ :password => ENV["MANDRILL_API_KEY"]
92
+ }
93
+ TEXT
94
+ inject_into_file 'config/environments/development.rb', mandrill_configuration_text, :after => "config.assets.debug = true"
95
+ inject_into_file 'config/environments/production.rb', mandrill_configuration_text, :after => "config.active_support.deprecation = :notify"
96
+ end
97
+ ### GIT
98
+ git :add => '-A' if prefer :git, true
99
+ git :commit => '-qm "rails_apps_composer: set email accounts"' if prefer :git, true
100
+ end # after_bundler
101
+
102
+ __END__
103
+
104
+ name: email
105
+ description: "Configure email accounts."
106
+ author: RailsApps
107
+
108
+ requires: [setup]
109
+ run_after: [setup]
110
+ category: configuration
@@ -0,0 +1,70 @@
1
+ # Application template recipe for the rails_apps_composer. Change the recipe here:
2
+ # https://github.com/RailsApps/rails_apps_composer/blob/master/recipes/example.rb
3
+
4
+ before_config do
5
+ # Code here is run before any configuration prompts.
6
+ say_wizard "recipe running before configuration"
7
+ end
8
+
9
+ if config['space_test']
10
+ say_wizard "running a space test"
11
+ test_count = config['test_count']
12
+ say_wizard "will run the test #{test_count} times"
13
+ say_wizard "will run the test in #{config['orbit']} orbit"
14
+ unless config['mars_test']
15
+ say_wizard "Mars test not available"
16
+ end
17
+ # the @config@ hash is only available to the recipe
18
+ # the @prefs{}@ hash is available to all the recipes
19
+ case config['orbit']
20
+ when 'leo'
21
+ prefs[:test_orbit] = 'leo'
22
+ when 'spy'
23
+ prefs[:test_orbit] = 'spy'
24
+ when 'gps'
25
+ prefs[:test_orbit] = 'gps'
26
+ end
27
+ end
28
+
29
+ after_bundler do
30
+ # Code here is run after Bundler installs all the gems for the project.
31
+ # Use this section to run generators and rake tasks.
32
+ # Download any files from a repository for models, controllers, views, and routes.
33
+ say_wizard "recipe running after 'bundle install'"
34
+ end
35
+
36
+ after_everything do
37
+ # This block is run after the 'after_bundler' block.
38
+ # Use this section to finalize the application.
39
+ # Run database migrations or make a final git commit.
40
+ say_wizard "recipe running after everything"
41
+ end
42
+
43
+ # A recipe has two parts: the Ruby code and YAML matter that comes after a blank line with the __END__ keyword.
44
+
45
+ __END__
46
+
47
+ name: example
48
+ description: "Example of a recipe."
49
+ author: githubname
50
+
51
+ category: example
52
+
53
+ config:
54
+ - space_test:
55
+ type: boolean
56
+ prompt: Do you want to test your application in space?
57
+ - mars_test:
58
+ type: boolean
59
+ prompt: Do you also want to test your application on Mars?
60
+ if: space_test
61
+ if_recipe: mars_lander
62
+ - test_count:
63
+ type: string
64
+ prompt: How many times would you like to repeat the test?
65
+ if: space_test
66
+ - orbit:
67
+ type: multiple_choice
68
+ prompt: "What orbit do you want?"
69
+ choices: [ [Low Earth orbit, leo], [Sun-synchronous, spy], [Geostationary, gps] ]
70
+ if: space_test
data/recipes/extras.rb ADDED
@@ -0,0 +1,187 @@
1
+ # Application template recipe for the rails_apps_composer. Change the recipe here:
2
+ # https://github.com/RailsApps/rails_apps_composer/blob/master/recipes/extras.rb
3
+
4
+ ## RVMRC
5
+ rvmrc_detected = false
6
+ if File.exist?('.rvmrc')
7
+ rvmrc_file = File.read('.rvmrc')
8
+ rvmrc_detected = rvmrc_file.include? app_name
9
+ end
10
+ if File.exist?('.ruby-gemset')
11
+ rvmrc_file = File.read('.ruby-gemset')
12
+ rvmrc_detected = rvmrc_file.include? app_name
13
+ end
14
+ unless rvmrc_detected || (prefs.has_key? :rvmrc)
15
+ prefs[:rvmrc] = yes_wizard? "Use or create a project-specific rvm gemset?"
16
+ end
17
+ if prefs[:rvmrc]
18
+ if which("rvm")
19
+ say_wizard "recipe creating project-specific rvm gemset and .rvmrc"
20
+ # using the rvm Ruby API, see:
21
+ # http://blog.thefrontiergroup.com.au/2010/12/a-brief-introduction-to-the-rvm-ruby-api/
22
+ # https://rvm.io/integration/passenger
23
+ if ENV['MY_RUBY_HOME'] && ENV['MY_RUBY_HOME'].include?('rvm')
24
+ begin
25
+ gems_path = ENV['MY_RUBY_HOME'].split(/@/)[0].sub(/rubies/,'gems')
26
+ ENV['GEM_PATH'] = "#{gems_path}:#{gems_path}@global"
27
+ require 'rvm'
28
+ RVM.use_from_path! File.dirname(File.dirname(__FILE__))
29
+ rescue LoadError
30
+ raise "RVM gem is currently unavailable."
31
+ end
32
+ end
33
+ say_wizard "creating RVM gemset '#{app_name}'"
34
+ RVM.gemset_create app_name
35
+ say_wizard "switching to gemset '#{app_name}'"
36
+ # RVM.gemset_use! requires rvm version 1.11.3.5 or newer
37
+ rvm_spec =
38
+ if Gem::Specification.respond_to?(:find_by_name)
39
+ Gem::Specification.find_by_name("rvm")
40
+ else
41
+ Gem.source_index.find_name("rvm").last
42
+ end
43
+ unless rvm_spec.version > Gem::Version.create('1.11.3.4')
44
+ say_wizard "rvm gem version: #{rvm_spec.version}"
45
+ raise "Please update rvm gem to 1.11.3.5 or newer"
46
+ end
47
+ begin
48
+ RVM.gemset_use! app_name
49
+ rescue => e
50
+ say_wizard "rvm failure: unable to use gemset #{app_name}, reason: #{e}"
51
+ raise
52
+ end
53
+ run "rvm gemset list"
54
+ if File.exist?('.ruby-version')
55
+ say_wizard ".ruby-version file already exists"
56
+ else
57
+ create_file '.ruby-version', "#{RUBY_VERSION}\n"
58
+ end
59
+ if File.exist?('.ruby-gemset')
60
+ say_wizard ".ruby-gemset file already exists"
61
+ else
62
+ create_file '.ruby-gemset', "#{app_name}\n"
63
+ end
64
+ else
65
+ say_wizard "WARNING! RVM does not appear to be available."
66
+ end
67
+ end
68
+
69
+ ## QUIET ASSETS
70
+ if config['quiet_assets']
71
+ prefs[:quiet_assets] = true
72
+ end
73
+ if prefs[:quiet_assets]
74
+ say_wizard "recipe setting quiet_assets for reduced asset pipeline logging"
75
+ add_gem 'quiet_assets', :group => :development
76
+ end
77
+
78
+ ## LOCAL_ENV.YML FILE
79
+ if config['local_env_file']
80
+ prefs[:local_env_file] = true
81
+ end
82
+ if prefs[:local_env_file]
83
+ say_wizard "recipe creating application.yml file for environment variables"
84
+ add_gem 'figaro'
85
+ end
86
+
87
+ ## BETTER ERRORS
88
+ if config['better_errors']
89
+ prefs[:better_errors] = true
90
+ end
91
+ if prefs[:better_errors]
92
+ say_wizard "recipe adding better_errors gem"
93
+ add_gem 'better_errors', :group => :development
94
+ add_gem 'binding_of_caller', :group => :development, :platforms => [:mri_19, :mri_20, :rbx]
95
+ end
96
+
97
+ ## BAN SPIDERS
98
+ if config['ban_spiders']
99
+ prefs[:ban_spiders] = true
100
+ end
101
+ if prefs[:ban_spiders]
102
+ say_wizard "recipe banning spiders by modifying 'public/robots.txt'"
103
+ after_bundler do
104
+ gsub_file 'public/robots.txt', /# User-Agent/, 'User-Agent'
105
+ gsub_file 'public/robots.txt', /# Disallow/, 'Disallow'
106
+ end
107
+ end
108
+
109
+ ## JSRUNTIME
110
+ case RbConfig::CONFIG['host_os']
111
+ when /linux/i
112
+ prefs[:jsruntime] = yes_wizard? "Add 'therubyracer' JavaScript runtime (for Linux users without node.js)?" unless prefs.has_key? :jsruntime
113
+ if prefs[:jsruntime]
114
+ say_wizard "recipe adding 'therubyracer' JavaScript runtime gem"
115
+ add_gem 'therubyracer', :platform => :ruby
116
+ end
117
+ end
118
+
119
+ ## AFTER_EVERYTHING
120
+ after_everything do
121
+ say_wizard "recipe removing unnecessary files and whitespace"
122
+ %w{
123
+ public/index.html
124
+ app/assets/images/rails.png
125
+ }.each { |file| remove_file file }
126
+ # remove commented lines and multiple blank lines from Gemfile
127
+ # thanks to https://github.com/perfectline/template-bucket/blob/master/cleanup.rb
128
+ gsub_file 'Gemfile', /#.*\n/, "\n"
129
+ gsub_file 'Gemfile', /\n^\s*\n/, "\n"
130
+ # remove commented lines and multiple blank lines from config/routes.rb
131
+ gsub_file 'config/routes.rb', / #.*\n/, "\n"
132
+ gsub_file 'config/routes.rb', /\n^\s*\n/, "\n"
133
+ # GIT
134
+ git :add => '-A' if prefer :git, true
135
+ git :commit => '-qm "rails_apps_composer: extras"' if prefer :git, true
136
+ end
137
+
138
+ ## GITHUB
139
+ if config['github']
140
+ prefs[:github] = true
141
+ end
142
+ if prefs[:github]
143
+ add_gem 'hub', :require => nil, :group => [:development]
144
+ after_everything do
145
+ say_wizard "recipe creating GitHub repository"
146
+ git_uri = `git config remote.origin.url`.strip
147
+ unless git_uri.size == 0
148
+ say_wizard "Repository already exists:"
149
+ say_wizard "#{git_uri}"
150
+ else
151
+ run "hub create #{app_name}"
152
+ unless prefer :railsapps, 'rails-prelaunch-signup'
153
+ run "hub push -u origin master"
154
+ else
155
+ run "hub push -u origin #{prefs[:prelaunch_branch]}"
156
+ run "hub push -u origin #{prefs[:main_branch]}" unless prefer :main_branch, 'none'
157
+ end
158
+ end
159
+ end
160
+ end
161
+
162
+ __END__
163
+
164
+ name: extras
165
+ description: "Various extras."
166
+ author: RailsApps
167
+
168
+ requires: [gems]
169
+ run_after: [gems, init, prelaunch]
170
+ category: other
171
+
172
+ config:
173
+ - ban_spiders:
174
+ type: boolean
175
+ prompt: Set a robots.txt file to ban spiders?
176
+ - github:
177
+ type: boolean
178
+ prompt: Create a GitHub repository?
179
+ - local_env_file:
180
+ type: boolean
181
+ prompt: Use application.yml file for environment variables?
182
+ - quiet_assets:
183
+ type: boolean
184
+ prompt: Reduce assets logger noise during development?
185
+ - better_errors:
186
+ type: boolean
187
+ prompt: Improve error reporting with 'better_errors' during development?
@@ -0,0 +1,45 @@
1
+ # Application template recipe for the rails_apps_composer. Change the recipe here:
2
+ # https://github.com/RailsApps/rails_apps_composer/blob/master/recipes/frontend.rb
3
+
4
+ after_bundler do
5
+ say_wizard "recipe running after 'bundle install'"
6
+ # set up a front-end framework using the rails_layout gem
7
+ case prefs[:frontend]
8
+ when 'simple'
9
+ generate 'layout simple -f'
10
+ when 'bootstrap2'
11
+ generate 'layout bootstrap2 -f'
12
+ when 'bootstrap3'
13
+ generate 'layout bootstrap3 -f'
14
+ when 'foundation4'
15
+ generate 'layout foundation4 -f'
16
+ end
17
+
18
+ # specialized navigation partials
19
+ if prefer :authorization, 'cancan'
20
+ case prefs[:authentication]
21
+ when 'devise'
22
+ copy_from_repo 'app/views/layouts/_navigation-cancan.html.erb', :prefs => 'cancan'
23
+ when 'omniauth'
24
+ copy_from 'https://raw.github.com/RailsApps/rails-composer/master/files/app/views/layouts/_navigation-cancan-omniauth.html.erb', 'app/views/layouts/_navigation.html.erb'
25
+ end
26
+ else
27
+ copy_from_repo 'app/views/layouts/_navigation-devise.html.erb', :prefs => 'devise'
28
+ copy_from_repo 'app/views/layouts/_navigation-omniauth.html.erb', :prefs => 'omniauth'
29
+ end
30
+ copy_from_repo 'app/views/layouts/_navigation-subdomains_app.html.erb', :prefs => 'subdomains_app'
31
+
32
+ ### GIT ###
33
+ git :add => '-A' if prefer :git, true
34
+ git :commit => '-qm "rails_apps_composer: front-end framework"' if prefer :git, true
35
+ end # after_bundler
36
+
37
+ __END__
38
+
39
+ name: frontend
40
+ description: "Install a front-end framework for HTML5 and CSS."
41
+ author: RailsApps
42
+
43
+ requires: [setup, gems]
44
+ run_after: [setup, gems]
45
+ category: frontend