rails_apps_composer 1.5.5 → 2.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (69) hide show
  1. data/README.textile +185 -254
  2. data/lib/rails_wizard/command.rb +54 -13
  3. data/lib/rails_wizard/config.rb +1 -1
  4. data/lib/rails_wizard/diagnostics.rb +22 -0
  5. data/lib/rails_wizard/template.rb +36 -2
  6. data/lib/rails_wizard.rb +1 -0
  7. data/recipes/auth.rb +84 -0
  8. data/recipes/controllers.rb +58 -0
  9. data/recipes/{seed_database.rb → database.rb} +35 -22
  10. data/recipes/{action_mailer.rb → email.rb} +29 -50
  11. data/recipes/example.rb +70 -0
  12. data/recipes/extras.rb +91 -30
  13. data/recipes/frontend.rb +59 -0
  14. data/recipes/gems.rb +128 -0
  15. data/recipes/models.rb +61 -0
  16. data/recipes/prelaunch.rb +45 -0
  17. data/recipes/readme.rb +83 -0
  18. data/recipes/routes.rb +36 -0
  19. data/recipes/setup.rb +148 -0
  20. data/recipes/testing.rb +187 -0
  21. data/recipes/views.rb +39 -0
  22. data/spec/rails_wizard/template_spec.rb +4 -2
  23. data/templates/helpers.erb +53 -2
  24. data/templates/layout.erb +81 -20
  25. data/version.rb +1 -1
  26. metadata +19 -49
  27. data/recipes/active_admin.rb +0 -36
  28. data/recipes/activerecord.rb +0 -37
  29. data/recipes/add_user.rb +0 -140
  30. data/recipes/airbrake.rb +0 -34
  31. data/recipes/backbone.rb +0 -23
  32. data/recipes/capybara.rb +0 -34
  33. data/recipes/cleanup.rb +0 -40
  34. data/recipes/cloudfiles.rb +0 -36
  35. data/recipes/compass.rb +0 -46
  36. data/recipes/compass_960.rb +0 -48
  37. data/recipes/cucumber.rb +0 -75
  38. data/recipes/datamapper.rb +0 -111
  39. data/recipes/devise.rb +0 -114
  40. data/recipes/git.rb +0 -40
  41. data/recipes/guard.rb +0 -89
  42. data/recipes/haml.rb +0 -23
  43. data/recipes/heroku.rb +0 -61
  44. data/recipes/home_page.rb +0 -58
  45. data/recipes/home_page_users.rb +0 -47
  46. data/recipes/html5.rb +0 -152
  47. data/recipes/inherited_resources.rb +0 -23
  48. data/recipes/less.rb +0 -12
  49. data/recipes/mongohq.rb +0 -59
  50. data/recipes/mongoid.rb +0 -38
  51. data/recipes/mongolab.rb +0 -59
  52. data/recipes/omniauth.rb +0 -194
  53. data/recipes/omniauth_email.rb +0 -82
  54. data/recipes/paperclip.rb +0 -79
  55. data/recipes/prelaunch_signup.rb +0 -586
  56. data/recipes/rails_admin.rb +0 -29
  57. data/recipes/redis.rb +0 -23
  58. data/recipes/responders.rb +0 -10
  59. data/recipes/resque.rb +0 -25
  60. data/recipes/rspec.rb +0 -131
  61. data/recipes/sass.rb +0 -25
  62. data/recipes/settingslogic.rb +0 -43
  63. data/recipes/simple_form.rb +0 -54
  64. data/recipes/slim.rb +0 -46
  65. data/recipes/static_page.rb +0 -43
  66. data/recipes/subdomains.rb +0 -121
  67. data/recipes/turnip.rb +0 -18
  68. data/recipes/unicorn.rb +0 -29
  69. data/recipes/users_page.rb +0 -165
@@ -8,9 +8,11 @@ module RailsWizard
8
8
  method_option :recipes, :type => :array, :aliases => "-r"
9
9
  method_option :defaults, :type => :string, :aliases => "-d"
10
10
  def new(name)
11
+ args = ask_for_args
11
12
  recipes, defaults = load_defaults
12
13
  recipes = ask_for_recipes(recipes)
13
- run_template(name, recipes, defaults, nil)
14
+ gems = ask_for_gems
15
+ run_template(name, recipes, gems, args, defaults, nil)
14
16
  end
15
17
 
16
18
  desc "template TEMPLATE_FILE", "create a new Rails template"
@@ -19,7 +21,8 @@ module RailsWizard
19
21
  def template(template_name)
20
22
  recipes, defaults = load_defaults
21
23
  recipes = ask_for_recipes(recipes)
22
- run_template(nil, recipes, defaults, template_name)
24
+ gems = ask_for_gems
25
+ run_template(nil, recipes, gems, nil, defaults, template_name)
23
26
  end
24
27
 
25
28
  desc "list [CATEGORY]", "list available recipes (optionally by category)"
@@ -85,29 +88,67 @@ module RailsWizard
85
88
  recipes
86
89
  end
87
90
 
91
+ def ask_for_gems
92
+ gems = []
93
+ while getgem = ask("#{bold}What gem would you like to add? #{clear}#{yellow}(blank to finish)#{clear}")
94
+ if getgem == ''
95
+ break
96
+ else
97
+ gems << getgem.downcase
98
+ end
99
+ end
100
+ gems
101
+ end
102
+
103
+ def ask_for_args
104
+ args = []
105
+ question = "#{bold}Would you like to skip Test::Unit? (yes for RSpec) \033[33m(y/n)\033[0m#{clear}"
106
+ while getT = ask(question)
107
+ case getT.downcase
108
+ when "yes", "y"
109
+ args << "-T"
110
+ break
111
+ when "no", "n"
112
+ args << ""
113
+ break
114
+ end
115
+ end
116
+ question = "#{bold}Would you like to skip Active Record? (yes for NoSQL) \033[33m(y/n)\033[0m#{clear}"
117
+ while getO = ask(question)
118
+ case getO.downcase
119
+ when "yes", "y"
120
+ args << "-O"
121
+ break
122
+ when "no", "n"
123
+ args << ""
124
+ break
125
+ end
126
+ end
127
+ args
128
+ end
129
+
88
130
  #pass in name if you want to create a rails app
89
131
  #pass in file_name if you want to create a template
90
- def run_template(name, recipes, defaults, file_name=nil)
91
- puts
92
- puts
93
- puts "#{bold}Generating#{name ? " and Running" : ''} Template..."
94
- puts
95
-
132
+ def run_template(name, recipes, gems, args, defaults, file_name=nil)
96
133
  if file_name
97
134
  file = File.new(file_name,'w')
98
135
  else
99
136
  file = Tempfile.new('template')
100
137
  end
101
138
  begin
102
- template = RailsWizard::Template.new(recipes, defaults)
139
+ template = RailsWizard::Template.new(recipes, gems, args, defaults)
103
140
  file.write template.compile
104
141
  file.close
105
142
  if name
106
- system "rails new #{name} -m #{file.path} #{template.args.join(' ')}"
143
+ args_list = (args | template.args).join(' ')
144
+ puts "Generating basic application, using:"
145
+ puts "\"rails new #{name} -m <temp_file> #{args_list}\""
146
+ system "rails new #{name} -m #{file.path} #{args_list}"
107
147
  else
108
- puts "install with the command:"
109
- puts
110
- puts "rails new <APP_NAME> -m #{file.path} #{template.args.join(' ')}"
148
+ puts "Generating and saving application template..."
149
+ puts "Done."
150
+ puts "Generate a new application with the command:"
151
+ puts "\"rails new <APP_NAME> -m #{file.path} #{template.args.join(' ')}\""
111
152
  end
112
153
  rescue RailsWizard::UnknownRecipeError
113
154
  raise Thor::Error.new("> #{red}#{$!.message}.#{clear}")
@@ -22,7 +22,7 @@ module RailsWizard
22
22
  values.merge!(defaults) if defaults
23
23
  result << "config = #{values.inspect}"
24
24
  @questions.each_pair do |key, question|
25
- result << "config['#{key}'] = #{question.compile} unless config.key?('#{key}')"
25
+ result << "config['#{key}'] = #{question.compile} unless config.key?('#{key}') || prefs.has_key?(:#{key})"
26
26
  end
27
27
  result.join("\n")
28
28
  end
@@ -0,0 +1,22 @@
1
+ module RailsWizard
2
+ module Diagnostics
3
+ # collections of recipes that are known to work together
4
+ @@recipes = []
5
+ @@recipes << ["example"]
6
+ @@recipes << ["setup"]
7
+ @@recipes << ["gems", "setup"]
8
+ @@recipes << ["gems", "readme", "setup"]
9
+ @@recipes << ["extras", "gems", "readme", "setup"]
10
+
11
+ # collections of preferences that are known to work together
12
+ @@prefs = []
13
+ @@prefs << {:database=>"sqlite", :templates=>"erb"}
14
+ def self.recipes
15
+ @@recipes
16
+ end
17
+
18
+ def self.prefs
19
+ @@prefs
20
+ end
21
+ end
22
+ end
@@ -1,10 +1,21 @@
1
1
  module RailsWizard
2
2
  class Template
3
- attr_reader :recipes, :defaults
3
+ attr_reader :recipes, :gems, :args, :defaults
4
4
 
5
- def initialize(recipes, defaults={})
5
+ def initialize(recipes, gems=[], args=[], defaults={})
6
6
  @recipes = recipes.map{|r| RailsWizard::Recipe.from_mongo(r)}
7
+ @args = args
7
8
  @defaults = defaults
9
+ unless defaults['prefs'].nil?
10
+ @prefs = defaults['prefs']
11
+ else
12
+ @prefs = {}
13
+ end
14
+ unless defaults['gems'].nil?
15
+ @gems = gems | defaults['gems']
16
+ else
17
+ @gems = gems
18
+ end
8
19
  end
9
20
 
10
21
  def self.template_root
@@ -17,7 +28,30 @@ module RailsWizard
17
28
  end
18
29
  def render(template_name, binding = nil); self.class.render(template_name, binding) end
19
30
 
31
+ def resolve_preferences
32
+ @resolve_preferences ||= begin
33
+ @prefs.inspect
34
+ end
35
+ end
36
+
37
+ def resolve_gems
38
+ @resolve_gems ||= begin
39
+ @gems.uniq.inspect
40
+ end
41
+ end
42
+
43
+ def resolve_diagnostics_recipes
44
+ @resolve_diagnostics_recipes ||= begin
45
+ RailsWizard::Diagnostics.recipes.inspect
46
+ end
47
+ end
20
48
 
49
+ def resolve_diagnostics_prefs
50
+ @resolve_diagnostics_prefs ||= begin
51
+ RailsWizard::Diagnostics.prefs.inspect
52
+ end
53
+ end
54
+
21
55
  # Sort the recipes list taking 'run_after' directives into account.
22
56
  def resolve_recipes
23
57
  @resolve_recipes ||= begin
data/lib/rails_wizard.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  require 'rails_wizard/recipes'
2
2
  require 'rails_wizard/recipe'
3
3
  require 'rails_wizard/config'
4
+ require 'rails_wizard/diagnostics'
4
5
  require 'rails_wizard/template'
5
6
 
6
7
  Dir[File.dirname(__FILE__) + '/../recipes/*.rb'].each do |path|
data/recipes/auth.rb ADDED
@@ -0,0 +1,84 @@
1
+ # Application template recipe for the rails_apps_composer. Change the recipe here:
2
+ # https://github.com/RailsApps/rails_apps_composer/blob/master/recipes/auth.rb
3
+
4
+ after_bundler do
5
+ say_wizard "recipe running after 'bundle install'"
6
+ ### DEVISE ###
7
+ if prefer :authentication, 'devise'
8
+ # Prevent logging of password_confirmation
9
+ gsub_file 'config/application.rb', /:password/, ':password, :password_confirmation'
10
+ generate 'devise:install'
11
+ generate 'devise_invitable:install' if prefer :devise_modules, 'invitable'
12
+ generate 'devise user'
13
+ ## DEVISE AND CUCUMBER
14
+ if prefer :integration, 'cucumber'
15
+ # Cucumber wants to test GET requests not DELETE requests for destroy_user_session_path
16
+ # (see https://github.com/RailsApps/rails3-devise-rspec-cucumber/issues/3)
17
+ gsub_file 'config/initializers/devise.rb', 'config.sign_out_via = :delete', 'config.sign_out_via = Rails.env.test? ? :get : :delete'
18
+ end
19
+ ## DEVISE MODULES
20
+ if (prefer :devise_modules, 'confirmable') || (prefer :devise_modules, 'invitable')
21
+ gsub_file 'app/models/user.rb', /:registerable,/, ":registerable, :confirmable,"
22
+ gsub_file 'app/models/user.rb', /:remember_me/, ':remember_me, :confirmed_at'
23
+ if prefer :orm, 'mongoid'
24
+ gsub_file 'app/models/user.rb', /# field :confirmation_token/, "field :confirmation_token"
25
+ gsub_file 'app/models/user.rb', /# field :confirmed_at/, "field :confirmed_at"
26
+ gsub_file 'app/models/user.rb', /# field :confirmation_sent_at/, "field :confirmation_sent_at"
27
+ gsub_file 'app/models/user.rb', /# field :unconfirmed_email/, "field :unconfirmed_email"
28
+ end
29
+ end
30
+ if prefer :devise_modules, 'invitable'
31
+ if prefer :orm, 'mongoid'
32
+ gsub_file 'app/models/user.rb', /\bend\s*\Z/ do
33
+ <<-RUBY
34
+ #invitable
35
+ field :invitation_token, :type => String
36
+ field :invitation_sent_at, :type => Time
37
+ field :invitation_accepted_at, :type => Time
38
+ field :invitation_limit, :type => Integer
39
+ field :invited_by_id, :type => String
40
+ field :invited_by_type, :type => String
41
+ end
42
+ RUBY
43
+ end
44
+ end
45
+ end
46
+ end
47
+ ### OMNIAUTH ###
48
+ if prefer :authentication, 'omniauth'
49
+ # Don't use single-quote-style-heredoc: we want interpolation.
50
+ create_file 'config/initializers/omniauth.rb' do <<-RUBY
51
+ Rails.application.config.middleware.use OmniAuth::Builder do
52
+ provider :#{prefs[:omniauth_provider]}, ENV['OMNIAUTH_PROVIDER_KEY'], ENV['OMNIAUTH_PROVIDER_SECRET']
53
+ end
54
+ RUBY
55
+ end
56
+ end
57
+ ### CANCAN ###
58
+ if prefer :authorization, 'cancan'
59
+ generate 'cancan:ability'
60
+ if prefer :starter_app, 'admin_dashboard'
61
+ # Limit access to the users#index page
62
+ inject_into_file 'app/models/ability.rb', :after => "def initialize(user)\n" do <<-RUBY
63
+ user ||= User.new # guest user (not logged in)
64
+ if user.has_role? :admin
65
+ can :manage, :all
66
+ end
67
+ RUBY
68
+ end
69
+ end
70
+ end
71
+ ### GIT ###
72
+ git :add => '.' if prefer :git, true
73
+ git :commit => "-aqm 'rails_apps_composer: authentication and authorization'" if prefer :git, true
74
+ end # after_bundler
75
+
76
+ __END__
77
+
78
+ name: auth
79
+ description: "Add authentication and authorization."
80
+ author: RailsApps
81
+
82
+ requires: [setup, gems]
83
+ run_after: [setup, gems]
84
+ category: auth
@@ -0,0 +1,58 @@
1
+ # Application template recipe for the rails_apps_composer. Change the recipe here:
2
+ # https://github.com/RailsApps/rails_apps_composer/blob/master/recipes/controllers.rb
3
+
4
+ after_bundler do
5
+ say_wizard "recipe running after 'bundle install'"
6
+ ### APPLICATION_CONTROLLER ###
7
+ if prefer :authentication, 'omniauth'
8
+ copy_from_repo 'app/controllers/application_controller.rb', :repo => 'https://raw.github.com/RailsApps/rails3-mongoid-omniauth/master/'
9
+ end
10
+ if prefer :authorization, 'cancan'
11
+ inject_into_file 'app/controllers/application_controller.rb', :before => 'end' do <<-RUBY
12
+ rescue_from CanCan::AccessDenied do |exception|
13
+ redirect_to root_path, :alert => exception.message
14
+ end
15
+ RUBY
16
+ end
17
+ end
18
+ ### HOME_CONTROLLER ###
19
+ if ['home_app','users_app','admin_app','subdomains_app'].include? prefs[:starter_app]
20
+ generate(:controller, "home index")
21
+ end
22
+ if ['users_app','admin_app','subdomains_app'].include? prefs[:starter_app]
23
+ gsub_file 'app/controllers/home_controller.rb', /def index/, "def index\n @users = User.all"
24
+ end
25
+ ### USERS_CONTROLLER ###
26
+ if ['users_app','admin_app','subdomains_app'].include? prefs[:starter_app]
27
+ if prefer :authentication, 'devise'
28
+ copy_from_repo 'app/controllers/users_controller.rb', :repo => 'https://raw.github.com/RailsApps/rails3-devise-rspec-cucumber/master/'
29
+ elsif prefer :authentication, 'omniauth'
30
+ copy_from_repo 'app/controllers/users_controller.rb', :repo => 'https://raw.github.com/RailsApps/rails3-mongoid-omniauth/master/'
31
+ end
32
+ if prefer :authorization, 'cancan'
33
+ inject_into_file 'app/controllers/users_controller.rb', " authorize! :index, @user, :message => 'Not authorized as an administrator.'\n", :after => "def index\n"
34
+ end
35
+ end
36
+ gsub_file 'app/controllers/users_controller.rb', /before_filter :authenticate_user!/, '' if prefer :starter_app, 'subdomains'
37
+ ### SESSIONS_CONTROLLER ###
38
+ if prefer :authentication, 'omniauth'
39
+ filename = 'app/controllers/sessions_controller.rb'
40
+ copy_from_repo filename, :repo => 'https://raw.github.com/RailsApps/rails3-mongoid-omniauth/master/'
41
+ gsub_file filename, /twitter/, prefs[:omniauth_provider] unless prefer :omniauth_provider, 'twitter'
42
+ end
43
+ ### PROFILES_CONTROLLER ###
44
+ copy_from_repo 'app/controllers/profiles_controller.rb', :repo => 'https://raw.github.com/RailsApps/rails3-subdomains/master/' if prefer :starter_app, 'subdomains'
45
+ ### GIT ###
46
+ git :add => '.' if prefer :git, true
47
+ git :commit => "-aqm 'rails_apps_composer: controllers'" if prefer :git, true
48
+ end # after_bundler
49
+
50
+ __END__
51
+
52
+ name: controllers
53
+ description: "Add controllers needed for starter apps."
54
+ author: RailsApps
55
+
56
+ requires: [setup, gems, auth, models]
57
+ run_after: [setup, gems, auth, models]
58
+ category: mvc
@@ -1,10 +1,12 @@
1
- # Application template recipe for the rails_apps_composer. Check for a newer version here:
2
- # https://github.com/RailsApps/rails_apps_composer/blob/master/recipes/seed_database.rb
1
+ # Application template recipe for the rails_apps_composer. Change the recipe here:
2
+ # https://github.com/RailsApps/rails_apps_composer/blob/master/recipes/database.rb
3
3
 
4
- after_bundler do
5
- say_wizard "SeedDatabase recipe running 'after bundler'"
6
- if recipes.include? 'devise'
7
- if recipes.include? 'devise-confirmable'
4
+ after_everything do
5
+ say_wizard "recipe running after everything"
6
+ ### PREPARE SEED ###
7
+ if prefer :authentication, 'devise'
8
+ if (prefer :devise_modules, 'confirmable') || (prefer :devise_modules, 'invitable')
9
+ ## DEVISE-CONFIRMABLE
8
10
  append_file 'db/seeds.rb' do <<-FILE
9
11
  puts 'SETTING UP DEFAULT USER LOGIN'
10
12
  user = User.create! :name => 'First User', :email => 'user@example.com', :password => 'please', :password_confirmation => 'please', :confirmed_at => Time.now.utc
@@ -14,6 +16,7 @@ puts 'New user created: ' << user2.name
14
16
  FILE
15
17
  end
16
18
  else
19
+ ## DEVISE-DEFAULT
17
20
  append_file 'db/seeds.rb' do <<-FILE
18
21
  puts 'SETTING UP DEFAULT USER LOGIN'
19
22
  user = User.create! :name => 'First User', :email => 'user@example.com', :password => 'please', :password_confirmation => 'please'
@@ -23,36 +26,46 @@ puts 'New user created: ' << user2.name
23
26
  FILE
24
27
  end
25
28
  end
26
- if recipes.include? 'authorization'
29
+ if prefer :starter_app, 'subdomains'
30
+ gsub_file 'db/seeds.rb', /First User/, 'user1'
31
+ gsub_file 'db/seeds.rb', /Second User/, 'user2'
32
+ end
33
+ if prefer :authorization, 'cancan'
27
34
  append_file 'db/seeds.rb' do <<-FILE
28
35
  user.add_role :admin
29
36
  FILE
30
37
  end
31
38
  end
39
+ ## DEVISE-INVITABLE
40
+ if prefer :devise_modules, 'invitable'
41
+ run 'bundle exec rake db:migrate'
42
+ generate 'devise_invitable user'
43
+ end
32
44
  end
33
- end
34
-
35
- after_everything do
36
- if recipes.include? 'devise-invitable'
37
- run 'bundle exec rake db:migrate'
38
- generate 'devise_invitable user'
39
- end
40
- unless recipes.include? 'mongoid'
45
+ ### APPLY SEED ###
46
+ unless prefer :orm, 'mongoid'
47
+ ## MONGOID
41
48
  say_wizard "applying migrations and seeding the database"
42
49
  run 'bundle exec rake db:migrate'
43
50
  run 'bundle exec rake db:test:prepare'
44
51
  else
45
- say_wizard "creating indexes and seeding the database"
46
- run 'rake db:mongoid:create_indexes'
52
+ ## ACTIVE_RECORD
53
+ say_wizard "dropping database, creating indexes and seeding the database"
54
+ run 'bundle exec rake db:drop'
55
+ run 'bundle exec rake db:mongoid:create_indexes'
47
56
  end
48
57
  run 'bundle exec rake db:seed'
49
- end
58
+ ### GIT ###
59
+ git :add => '.' if prefer :git, true
60
+ git :commit => "-aqm 'rails_apps_composer: set up database'" if prefer :git, true
61
+ end # after_everything
50
62
 
51
63
  __END__
52
64
 
53
- name: SeedDatabase
54
- description: "Create a database seed file with a default user."
65
+ name: database
66
+ description: "Set up and initialize database."
55
67
  author: RailsApps
56
68
 
57
- category: other
58
- tags: [utilities, configuration]
69
+ requires: [setup, gems, models]
70
+ run_after: [setup, gems, models]
71
+ category: initialize
@@ -1,25 +1,12 @@
1
- # Application template recipe for the rails_apps_composer. Check for a newer version here:
2
- # https://github.com/RailsApps/rails_apps_composer/blob/master/recipes/action_mailer.rb
3
-
4
- case config['mailer']
5
- when 'smtp'
6
- recipes << 'smtp'
7
- when 'gmail'
8
- recipes << 'gmail'
9
- when 'sendgrid'
10
- gem 'sendgrid'
11
- recipes << 'sendgrid'
12
- when 'mandrill'
13
- gem 'hominid'
14
- recipes << 'mandrill'
15
- end
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
16
3
 
17
4
  after_bundler do
18
- ### modifying environment configuration files for ActionMailer
19
- say_wizard "ActionMailer recipe running 'after bundler'"
20
- ### development environment
21
- gsub_file 'config/environments/development.rb', /# Don't care if the mailer can't send/, '# ActionMailer Config'
22
- gsub_file 'config/environments/development.rb', /config.action_mailer.raise_delivery_errors = false/ do
5
+ say_wizard "recipe running after 'bundle install'"
6
+ unless prefer :email, 'none'
7
+ ### DEVELOPMENT
8
+ gsub_file 'config/environments/development.rb', /# Don't care if the mailer can't send/, '# ActionMailer Config'
9
+ gsub_file 'config/environments/development.rb', /config.action_mailer.raise_delivery_errors = false/ do
23
10
  <<-RUBY
24
11
  config.action_mailer.default_url_options = { :host => 'localhost:3000' }
25
12
  config.action_mailer.delivery_method = :smtp
@@ -28,17 +15,17 @@ config.action_mailer.default_url_options = { :host => 'localhost:3000' }
28
15
  config.action_mailer.raise_delivery_errors = true
29
16
  config.action_mailer.default :charset => "utf-8"
30
17
  RUBY
31
- end
32
- ### test environment
33
- inject_into_file 'config/environments/test.rb', :before => "\nend" do
18
+ end
19
+ ### TEST
20
+ inject_into_file 'config/environments/test.rb', :before => "\nend" do
34
21
  <<-RUBY
35
22
  \n
36
23
  # ActionMailer Config
37
24
  config.action_mailer.default_url_options = { :host => 'example.com' }
38
25
  RUBY
39
- end
40
- ### production environment
41
- gsub_file 'config/environments/production.rb', /config.active_support.deprecation = :notify/ do
26
+ end
27
+ ### PRODUCTION
28
+ gsub_file 'config/environments/production.rb', /config.active_support.deprecation = :notify/ do
42
29
  <<-RUBY
43
30
  config.active_support.deprecation = :notify
44
31
 
@@ -50,10 +37,10 @@ config.active_support.deprecation = :notify
50
37
  config.action_mailer.raise_delivery_errors = false
51
38
  config.action_mailer.default :charset => "utf-8"
52
39
  RUBY
40
+ end
53
41
  end
54
-
55
- ### modifying environment configuration files to send email using a GMail account
56
- if recipes.include? 'gmail'
42
+ ### GMAIL ACCOUNT
43
+ if prefer :email, 'gmail'
57
44
  gmail_configuration_text = <<-TEXT
58
45
  \n
59
46
  config.action_mailer.smtp_settings = {
@@ -66,13 +53,11 @@ RUBY
66
53
  password: ENV["GMAIL_PASSWORD"]
67
54
  }
68
55
  TEXT
69
- say_wizard gmail_configuration_text
70
56
  inject_into_file 'config/environments/development.rb', gmail_configuration_text, :after => 'config.action_mailer.default :charset => "utf-8"'
71
57
  inject_into_file 'config/environments/production.rb', gmail_configuration_text, :after => 'config.action_mailer.default :charset => "utf-8"'
72
58
  end
73
-
74
- ### modifying environment configuration files to send email using a SendGrid account
75
- if recipes.include? 'sendgrid'
59
+ ### SENDGRID ACCOUNT
60
+ if prefer :email, 'sendgrid'
76
61
  sendgrid_configuration_text = <<-TEXT
77
62
  \n
78
63
  config.action_mailer.smtp_settings = {
@@ -84,13 +69,11 @@ TEXT
84
69
  password: ENV["SENDGRID_PASSWORD"]
85
70
  }
86
71
  TEXT
87
- say_wizard gmail_configuration_text
88
72
  inject_into_file 'config/environments/development.rb', sendgrid_configuration_text, :after => 'config.action_mailer.default :charset => "utf-8"'
89
73
  inject_into_file 'config/environments/production.rb', sendgrid_configuration_text, :after => 'config.action_mailer.default :charset => "utf-8"'
90
74
  end
91
-
92
- ### modifying environment configuration files to send email using a Mandrill account
93
- if recipes.include? 'mandrill'
75
+ ### MANDRILL ACCOUNT
76
+ if prefer :email, 'mandrill'
94
77
  mandrill_configuration_text = <<-TEXT
95
78
  \n
96
79
  config.action_mailer.smtp_settings = {
@@ -100,24 +83,20 @@ TEXT
100
83
  :password => ENV["MANDRILL_API_KEY"]
101
84
  }
102
85
  TEXT
103
- say_wizard gmail_configuration_text
104
86
  inject_into_file 'config/environments/development.rb', mandrill_configuration_text, :after => 'config.action_mailer.default :charset => "utf-8"'
105
87
  inject_into_file 'config/environments/production.rb', mandrill_configuration_text, :after => 'config.action_mailer.default :charset => "utf-8"'
106
88
  end
107
-
108
- end
89
+ ### GIT
90
+ git :add => '.' if prefer :git, true
91
+ git :commit => "-aqm 'rails_apps_composer: set email accounts'" if prefer :git, true
92
+ end # after_bundler
109
93
 
110
94
  __END__
111
95
 
112
- name: ActionMailer
113
- description: "Configure ActionMailer for email."
96
+ name: email
97
+ description: "Configure email accounts."
114
98
  author: RailsApps
115
99
 
116
- category: other
117
- tags: [utilities, configuration]
118
-
119
- config:
120
- - mailer:
121
- type: multiple_choice
122
- prompt: "How will you send email?"
123
- choices: [["SMTP account", smtp], ["Gmail account", gmail], ["SendGrid account", sendgrid], ["Mandrill by MailChimp account", mandrill]]
100
+ requires: [setup]
101
+ run_after: [setup]
102
+ 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