rails-base 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +23 -0
- data/bin/rbase +18 -0
- data/lib/template.rb +3171 -0
- data/lib/version.rb +3 -0
- data/rails-base.gemspec +42 -0
- metadata +90 -0
data/lib/template.rb
ADDED
@@ -0,0 +1,3171 @@
|
|
1
|
+
module Generator
|
2
|
+
# >---------------------------------------------------------------------------<
|
3
|
+
#
|
4
|
+
# _____ _ _
|
5
|
+
# | __ \ (_) | /\
|
6
|
+
# | |__) |__ _ _| |___ / \ _ __ _ __ ___
|
7
|
+
# | _ // _` | | / __| / /\ \ | '_ \| '_ \/ __|
|
8
|
+
# | | \ \ (_| | | \__ \/ ____ \| |_) | |_) \__ \
|
9
|
+
# |_| \_\__,_|_|_|___/_/ \_\ .__/| .__/|___/
|
10
|
+
# | | | |
|
11
|
+
# |_| |_|
|
12
|
+
#
|
13
|
+
# Application template generated by the rails_apps_composer gem.
|
14
|
+
# Restrain your impulse to make changes to this file; instead,
|
15
|
+
# make changes to the recipes in the rails_apps_composer gem.
|
16
|
+
#
|
17
|
+
# For more information, see:
|
18
|
+
# https://github.com/RailsApps/rails_apps_composer/
|
19
|
+
#
|
20
|
+
# Thank you to Michael Bleigh for leading the way with the RailsWizard gem.
|
21
|
+
#
|
22
|
+
# Primarily generated by file:
|
23
|
+
# https://github.com/RailsApps/rails_apps_composer/templates/layout.erb
|
24
|
+
#
|
25
|
+
# >---------------------------------------------------------------------------<
|
26
|
+
|
27
|
+
# >----------------------------[ Initial Setup ]------------------------------<
|
28
|
+
|
29
|
+
module Gemfile
|
30
|
+
class GemInfo
|
31
|
+
def initialize(name) @name=name; @group=[]; @opts={}; end
|
32
|
+
attr_accessor :name, :version
|
33
|
+
attr_reader :group, :opts
|
34
|
+
|
35
|
+
def opts=(new_opts={})
|
36
|
+
new_group = new_opts.delete(:group)
|
37
|
+
if (new_group && self.group != new_group)
|
38
|
+
@group = ([self.group].flatten + [new_group].flatten).compact.uniq.sort
|
39
|
+
end
|
40
|
+
@opts = (self.opts || {}).merge(new_opts)
|
41
|
+
end
|
42
|
+
|
43
|
+
def group_key() @group end
|
44
|
+
|
45
|
+
def gem_args_string
|
46
|
+
args = ["'#{@name}'"]
|
47
|
+
args << "'#{@version}'" if @version
|
48
|
+
@opts.each do |name,value|
|
49
|
+
args << ":#{name}=>#{value.inspect}"
|
50
|
+
end
|
51
|
+
args.join(', ')
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
@geminfo = {}
|
56
|
+
|
57
|
+
class << self
|
58
|
+
# add(name, version, opts={})
|
59
|
+
def add(name, *args)
|
60
|
+
name = name.to_s
|
61
|
+
version = args.first && !args.first.is_a?(Hash) ? args.shift : nil
|
62
|
+
opts = args.first && args.first.is_a?(Hash) ? args.shift : {}
|
63
|
+
@geminfo[name] = (@geminfo[name] || GemInfo.new(name)).tap do |info|
|
64
|
+
info.version = version if version
|
65
|
+
info.opts = opts
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def write
|
70
|
+
File.open('Gemfile', 'a') do |file|
|
71
|
+
file.puts
|
72
|
+
grouped_gem_names.sort.each do |group, gem_names|
|
73
|
+
indent = ""
|
74
|
+
unless group.empty?
|
75
|
+
file.puts "group :#{group.join(', :')} do" unless group.empty?
|
76
|
+
indent=" "
|
77
|
+
end
|
78
|
+
gem_names.sort.each do |gem_name|
|
79
|
+
file.puts "#{indent}gem #{@geminfo[gem_name].gem_args_string}"
|
80
|
+
end
|
81
|
+
file.puts "end" unless group.empty?
|
82
|
+
file.puts
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
private
|
88
|
+
#returns {group=>[...gem names...]}, ie {[:development, :test]=>['rspec-rails', 'mocha'], :assets=>[], ...}
|
89
|
+
def grouped_gem_names
|
90
|
+
{}.tap do |_groups|
|
91
|
+
@geminfo.each do |gem_name, geminfo|
|
92
|
+
(_groups[geminfo.group_key] ||= []).push(gem_name)
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
def add_gem(*all) Gemfile.add(*all); end
|
99
|
+
|
100
|
+
@recipes = ["core", "git", "railsapps", "setup", "readme", "admin", "email", "gems", "frontend", "models", "testing", "init", "apps4", "controllers", "views", "prelaunch", "saas", "routes", "extras", "email_dev"]
|
101
|
+
@prefs = {}
|
102
|
+
@gems = ["rails_12factor", "uuidtools", "whenever", "god"]
|
103
|
+
@diagnostics_recipes = [["example"], ["setup"], ["railsapps"], ["gems", "setup"], ["gems", "readme", "setup"], ["extras", "gems", "readme", "setup"], ["example", "git"], ["git", "setup"], ["git", "railsapps"], ["gems", "git", "setup"], ["gems", "git", "readme", "setup"], ["extras", "gems", "git", "readme", "setup"], ["controllers", "email", "extras", "frontend", "gems", "git", "init", "models", "railsapps", "readme", "routes", "setup", "testing", "views"], ["controllers", "core", "email", "extras", "frontend", "gems", "git", "init", "models", "railsapps", "readme", "routes", "setup", "testing", "views"], ["controllers", "core", "email", "extras", "frontend", "gems", "git", "init", "models", "prelaunch", "railsapps", "readme", "routes", "setup", "testing", "views"], ["controllers", "core", "email", "extras", "frontend", "gems", "git", "init", "models", "prelaunch", "railsapps", "readme", "routes", "saas", "setup", "testing", "views"], ["controllers", "email", "example", "extras", "frontend", "gems", "git", "init", "models", "railsapps", "readme", "routes", "setup", "testing", "views"], ["controllers", "email", "example", "extras", "frontend", "gems", "git", "init", "models", "prelaunch", "railsapps", "readme", "routes", "setup", "testing", "views"], ["controllers", "email", "example", "extras", "frontend", "gems", "git", "init", "models", "prelaunch", "railsapps", "readme", "routes", "saas", "setup", "testing", "views"], ["apps4", "controllers", "core", "email", "extras", "frontend", "gems", "git", "init", "models", "prelaunch", "railsapps", "readme", "routes", "saas", "setup", "testing", "views"]]
|
104
|
+
@diagnostics_prefs = [{:railsapps=>"rails-recurly-subscription-saas", :database=>"sqlite", :unit_test=>"rspec", :integration=>"cucumber", :fixtures=>"factory_girl", :frontend=>"bootstrap", :bootstrap=>"sass", :email=>"gmail", :authentication=>"devise", :devise_modules=>"default", :authorization=>"cancan", :starter_app=>"admin_app", :form_builder=>"simple_form"}, {:railsapps=>"rails-stripe-membership-saas", :database=>"sqlite", :unit_test=>"rspec", :integration=>"cucumber", :fixtures=>"factory_girl", :frontend=>"bootstrap", :bootstrap=>"sass", :email=>"gmail", :authentication=>"devise", :devise_modules=>"default", :authorization=>"cancan", :starter_app=>"admin_app", :form_builder=>"simple_form"}, {:railsapps=>"rails-stripe-membership-saas", :database=>"sqlite", :unit_test=>"rspec", :integration=>"cucumber", :fixtures=>"factory_girl", :frontend=>"bootstrap", :bootstrap=>"sass", :email=>"mandrill", :authentication=>"devise", :devise_modules=>"confirmable", :authorization=>"cancan", :starter_app=>"admin_app", :form_builder=>"simple_form"}, {:railsapps=>"rails-prelaunch-signup", :database=>"sqlite", :unit_test=>"rspec", :integration=>"cucumber", :fixtures=>"factory_girl", :frontend=>"bootstrap", :bootstrap=>"sass", :email=>"mandrill", :authentication=>"devise", :devise_modules=>"confirmable", :authorization=>"cancan", :starter_app=>"admin_app", :form_builder=>"simple_form"}, {:railsapps=>"rails3-bootstrap-devise-cancan", :database=>"sqlite", :unit_test=>"rspec", :integration=>"cucumber", :fixtures=>"factory_girl", :frontend=>"bootstrap", :bootstrap=>"sass", :email=>"gmail", :authentication=>"devise", :devise_modules=>"default", :authorization=>"cancan", :starter_app=>"admin_app", :form_builder=>"simple_form"}, {:railsapps=>"rails3-bootstrap-devise-cancan", :database=>"sqlite", :unit_test=>"rspec", :integration=>"cucumber", :fixtures=>"factory_girl", :frontend=>"bootstrap", :bootstrap=>"sass", :email=>"gmail", :authentication=>"devise", :devise_modules=>"default", :authorization=>"cancan", :starter_app=>"admin_app", :form_builder=>"simple_form", :local_env_file=>"figaro", :continuous_testing=>"none"}, {:railsapps=>"rails3-devise-rspec-cucumber", :database=>"sqlite", :unit_test=>"rspec", :integration=>"cucumber", :fixtures=>"factory_girl", :frontend=>"none", :email=>"gmail", :authentication=>"devise", :devise_modules=>"default", :authorization=>"none", :starter_app=>"users_app", :form_builder=>"none"}, {:railsapps=>"rails3-mongoid-devise", :database=>"mongodb", :orm=>"mongoid", :unit_test=>"rspec", :integration=>"cucumber", :fixtures=>"factory_girl", :frontend=>"none", :email=>"gmail", :authentication=>"devise", :devise_modules=>"default", :authorization=>"none", :starter_app=>"users_app", :form_builder=>"none"}, {:railsapps=>"rails3-mongoid-omniauth", :database=>"mongodb", :orm=>"mongoid", :unit_test=>"rspec", :integration=>"cucumber", :fixtures=>"factory_girl", :frontend=>"none", :email=>"none", :authentication=>"omniauth", :omniauth_provider=>"twitter", :authorization=>"none", :starter_app=>"users_app", :form_builder=>"none"}, {:railsapps=>"rails3-subdomains", :database=>"mongodb", :orm=>"mongoid", :unit_test=>"rspec", :integration=>"cucumber", :fixtures=>"factory_girl", :frontend=>"none", :email=>"gmail", :authentication=>"devise", :devise_modules=>"default", :authorization=>"none", :starter_app=>"subdomains_app", :form_builder=>"none"}, {:railsapps=>"none", :database=>"sqlite", :unit_test=>"rspec", :integration=>"rspec-capybara", :fixtures=>"factory_girl", :frontend=>"bootstrap", :bootstrap=>"sass", :email=>"none", :authentication=>"omniauth", :omniauth_provider=>"twitter", :authorization=>"cancan", :form_builder=>"none", :starter_app=>"admin_app"}, {:railsapps=>"none", :database=>"sqlite", :unit_test=>"rspec", :integration=>"cucumber", :fixtures=>"none", :frontend=>"bootstrap", :bootstrap=>"sass", :email=>"gmail", :authentication=>"devise", :devise_modules=>"invitable", :authorization=>"cancan", :form_builder=>"simple_form", :starter_app=>"admin_app"}, {:railsapps=>"none", :database=>"sqlite", :unit_test=>"rspec", :integration=>"cucumber", :fixtures=>"factory_girl", :frontend=>"bootstrap", :bootstrap=>"sass", :email=>"gmail", :authentication=>"devise", :devise_modules=>"default", :authorization=>"cancan", :form_builder=>"none", :starter_app=>"admin_app"}, {:railsapps=>"none", :database=>"sqlite", :unit_test=>"test_unit", :integration=>"none", :fixtures=>"none", :frontend=>"bootstrap", :bootstrap=>"less", :email=>"sendgrid", :authentication=>"devise", :devise_modules=>"confirmable", :authorization=>"cancan", :form_builder=>"none", :starter_app=>"admin_app"}]
|
105
|
+
diagnostics = {}
|
106
|
+
|
107
|
+
# >-------------------------- templates/helpers.erb --------------------------start<
|
108
|
+
def recipes; @recipes end
|
109
|
+
def recipe?(name); @recipes.include?(name) end
|
110
|
+
def prefs; @prefs end
|
111
|
+
def prefer(key, value); @prefs[key].eql? value end
|
112
|
+
def gems; @gems end
|
113
|
+
def diagnostics_recipes; @diagnostics_recipes end
|
114
|
+
def diagnostics_prefs; @diagnostics_prefs end
|
115
|
+
|
116
|
+
def say_custom(tag, text); say "\033[1m\033[36m" + tag.to_s.rjust(10) + "\033[0m" + " #{text}" end
|
117
|
+
def say_recipe(name); say "\033[1m\033[36m" + "recipe".rjust(10) + "\033[0m" + " Running #{name} recipe..." end
|
118
|
+
def say_wizard(text); say_custom(@current_recipe || 'composer', text) end
|
119
|
+
|
120
|
+
def rails_4?
|
121
|
+
Rails::VERSION::MAJOR.to_s == "4"
|
122
|
+
end
|
123
|
+
|
124
|
+
def rails_4_1?
|
125
|
+
Rails::VERSION::MAJOR.to_s == "4" && Rails::VERSION::MINOR.to_s == "1"
|
126
|
+
end
|
127
|
+
|
128
|
+
def ask_wizard(question)
|
129
|
+
ask "\033[1m\033[36m" + (@current_recipe || "prompt").rjust(10) + "\033[1m\033[36m" + " #{question}\033[0m"
|
130
|
+
end
|
131
|
+
|
132
|
+
def yes_wizard?(question)
|
133
|
+
answer = ask_wizard(question + " \033[33m(y/n)\033[0m")
|
134
|
+
case answer.downcase
|
135
|
+
when "yes", "y"
|
136
|
+
true
|
137
|
+
when "no", "n"
|
138
|
+
false
|
139
|
+
else
|
140
|
+
yes_wizard?(question)
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
def no_wizard?(question); !yes_wizard?(question) end
|
145
|
+
|
146
|
+
def multiple_choice(question, choices)
|
147
|
+
say_custom('question', question)
|
148
|
+
values = {}
|
149
|
+
choices.each_with_index do |choice,i|
|
150
|
+
values[(i + 1).to_s] = choice[1]
|
151
|
+
say_custom( (i + 1).to_s + ')', choice[0] )
|
152
|
+
end
|
153
|
+
answer = ask_wizard("Enter your selection:") while !values.keys.include?(answer)
|
154
|
+
values[answer]
|
155
|
+
end
|
156
|
+
|
157
|
+
@current_recipe = nil
|
158
|
+
@configs = {}
|
159
|
+
|
160
|
+
@after_blocks = []
|
161
|
+
def after_bundler(&block); @after_blocks << [@current_recipe, block]; end
|
162
|
+
@after_everything_blocks = []
|
163
|
+
def after_everything(&block); @after_everything_blocks << [@current_recipe, block]; end
|
164
|
+
@before_configs = {}
|
165
|
+
def before_config(&block); @before_configs[@current_recipe] = block; end
|
166
|
+
|
167
|
+
def copy_from(source, destination)
|
168
|
+
begin
|
169
|
+
remove_file destination
|
170
|
+
get source, destination
|
171
|
+
rescue OpenURI::HTTPError
|
172
|
+
say_wizard "Unable to obtain #{source}"
|
173
|
+
end
|
174
|
+
end
|
175
|
+
|
176
|
+
def copy_from_repo(filename, opts = {})
|
177
|
+
repo = 'https://raw.github.com/RailsApps/rails-composer/master/files/'
|
178
|
+
repo = opts[:repo] unless opts[:repo].nil?
|
179
|
+
if (!opts[:prefs].nil?) && (!prefs.has_value? opts[:prefs])
|
180
|
+
return
|
181
|
+
end
|
182
|
+
source_filename = filename
|
183
|
+
destination_filename = filename
|
184
|
+
unless opts[:prefs].nil?
|
185
|
+
if filename.include? opts[:prefs]
|
186
|
+
destination_filename = filename.gsub(/\-#{opts[:prefs]}/, '')
|
187
|
+
end
|
188
|
+
end
|
189
|
+
if (prefer :templates, 'haml') && (filename.include? 'views')
|
190
|
+
remove_file destination_filename
|
191
|
+
destination_filename = destination_filename.gsub(/.erb/, '.haml')
|
192
|
+
end
|
193
|
+
if (prefer :templates, 'slim') && (filename.include? 'views')
|
194
|
+
remove_file destination_filename
|
195
|
+
destination_filename = destination_filename.gsub(/.erb/, '.slim')
|
196
|
+
end
|
197
|
+
begin
|
198
|
+
remove_file destination_filename
|
199
|
+
if (prefer :templates, 'haml') && (filename.include? 'views')
|
200
|
+
create_file destination_filename, html_to_haml(repo + source_filename)
|
201
|
+
elsif (prefer :templates, 'slim') && (filename.include? 'views')
|
202
|
+
create_file destination_filename, html_to_slim(repo + source_filename)
|
203
|
+
else
|
204
|
+
get repo + source_filename, destination_filename
|
205
|
+
end
|
206
|
+
rescue OpenURI::HTTPError
|
207
|
+
say_wizard "Unable to obtain #{source_filename} from the repo #{repo}"
|
208
|
+
end
|
209
|
+
end
|
210
|
+
|
211
|
+
def html_to_haml(source)
|
212
|
+
begin
|
213
|
+
html = open(source) {|input| input.binmode.read }
|
214
|
+
Haml::HTML.new(html, :erb => true, :xhtml => true).render
|
215
|
+
rescue RubyParser::SyntaxError
|
216
|
+
say_wizard "Ignoring RubyParser::SyntaxError"
|
217
|
+
# special case to accommodate https://github.com/RailsApps/rails-composer/issues/55
|
218
|
+
html = open(source) {|input| input.binmode.read }
|
219
|
+
say_wizard "applying patch" if html.include? 'card_month'
|
220
|
+
say_wizard "applying patch" if html.include? 'card_year'
|
221
|
+
html = html.gsub(/, {add_month_numbers: true}, {name: nil, id: "card_month"}/, '')
|
222
|
+
html = html.gsub(/, {start_year: Date\.today\.year, end_year: Date\.today\.year\+10}, {name: nil, id: "card_year"}/, '')
|
223
|
+
result = Haml::HTML.new(html, :erb => true, :xhtml => true).render
|
224
|
+
result = result.gsub(/select_month nil/, "select_month nil, {add_month_numbers: true}, {name: nil, id: \"card_month\"}")
|
225
|
+
result = result.gsub(/select_year nil/, "select_year nil, {start_year: Date.today.year, end_year: Date.today.year+10}, {name: nil, id: \"card_year\"}")
|
226
|
+
end
|
227
|
+
end
|
228
|
+
|
229
|
+
def html_to_slim(source)
|
230
|
+
html = open(source) {|input| input.binmode.read }
|
231
|
+
haml = Haml::HTML.new(html, :erb => true, :xhtml => true).render
|
232
|
+
Haml2Slim.convert!(haml)
|
233
|
+
end
|
234
|
+
|
235
|
+
# full credit to @mislav in this StackOverflow answer for the #which() method:
|
236
|
+
# - http://stackoverflow.com/a/5471032
|
237
|
+
def which(cmd)
|
238
|
+
exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : ['']
|
239
|
+
ENV['PATH'].split(File::PATH_SEPARATOR).each do |path|
|
240
|
+
exts.each do |ext|
|
241
|
+
exe = "#{path}#{File::SEPARATOR}#{cmd}#{ext}"
|
242
|
+
return exe if File.executable? exe
|
243
|
+
end
|
244
|
+
end
|
245
|
+
return nil
|
246
|
+
end
|
247
|
+
# >-------------------------- templates/helpers.erb --------------------------end<
|
248
|
+
|
249
|
+
if diagnostics_recipes.sort.include? recipes.sort
|
250
|
+
diagnostics[:recipes] = 'success'
|
251
|
+
say_wizard("WOOT! The recipes you've selected are known to work together.")
|
252
|
+
else
|
253
|
+
diagnostics[:recipes] = 'fail'
|
254
|
+
say_wizard("\033[1m\033[36m" + "WARNING! The recipes you've selected might not work together." + "\033[0m")
|
255
|
+
say_wizard("Help us out by reporting whether this combination works or fails.")
|
256
|
+
say_wizard("Please open an issue for rails_apps_composer on GitHub.")
|
257
|
+
say_wizard("Your new application will contain diagnostics in its README file.")
|
258
|
+
say_wizard("Continuing...")
|
259
|
+
end
|
260
|
+
|
261
|
+
# this application template only supports Rails version 3.1 and newer
|
262
|
+
case Rails::VERSION::MAJOR.to_s
|
263
|
+
when "3"
|
264
|
+
case Rails::VERSION::MINOR.to_s
|
265
|
+
when "0"
|
266
|
+
say_wizard "You are using Rails version #{Rails::VERSION::STRING} which is not supported. Try 3.1 or newer."
|
267
|
+
raise StandardError.new "Rails #{Rails::VERSION::STRING} is not supported. Try 3.1 or newer."
|
268
|
+
end
|
269
|
+
when "4"
|
270
|
+
say_wizard "You are using Rails version #{Rails::VERSION::STRING}."
|
271
|
+
else
|
272
|
+
say_wizard "You are using Rails version #{Rails::VERSION::STRING} which is not supported. Try 3.1 or newer."
|
273
|
+
raise StandardError.new "Rails #{Rails::VERSION::STRING} is not supported. Try 3.1 or newer."
|
274
|
+
end
|
275
|
+
|
276
|
+
say_wizard "Using rails_apps_composer recipes to generate an application."
|
277
|
+
|
278
|
+
# >---------------------------[ Autoload Modules/Classes ]-----------------------------<
|
279
|
+
|
280
|
+
inject_into_file 'config/application.rb', :after => 'config.autoload_paths += %W(#{config.root}/extras)' do <<-'RUBY'
|
281
|
+
|
282
|
+
config.autoload_paths += %W(#{config.root}/lib)
|
283
|
+
RUBY
|
284
|
+
end
|
285
|
+
|
286
|
+
# >---------------------------------[ Recipes ]----------------------------------<
|
287
|
+
|
288
|
+
# >-------------------------- templates/recipe.erb ---------------------------start<
|
289
|
+
# >---------------------------------[ core ]----------------------------------<
|
290
|
+
@current_recipe = "core"
|
291
|
+
@before_configs["core"].call if @before_configs["core"]
|
292
|
+
say_recipe 'core'
|
293
|
+
@configs[@current_recipe] = config
|
294
|
+
# >----------------------------- recipes/core.rb -----------------------------start<
|
295
|
+
|
296
|
+
# Application template recipe for the rails_apps_composer. Change the recipe here:
|
297
|
+
# https://github.com/RailsApps/rails_apps_composer/blob/master/recipes/core.rb
|
298
|
+
|
299
|
+
## Git
|
300
|
+
say_wizard "selected all core recipes"
|
301
|
+
# >----------------------------- recipes/core.rb -----------------------------end<
|
302
|
+
# >-------------------------- templates/recipe.erb ---------------------------end<
|
303
|
+
|
304
|
+
# >-------------------------- templates/recipe.erb ---------------------------start<
|
305
|
+
# >----------------------------------[ git ]----------------------------------<
|
306
|
+
@current_recipe = "git"
|
307
|
+
@before_configs["git"].call if @before_configs["git"]
|
308
|
+
say_recipe 'git'
|
309
|
+
@configs[@current_recipe] = config
|
310
|
+
# >----------------------------- recipes/git.rb ------------------------------start<
|
311
|
+
|
312
|
+
# Application template recipe for the rails_apps_composer. Change the recipe here:
|
313
|
+
# https://github.com/RailsApps/rails_apps_composer/blob/master/recipes/git.rb
|
314
|
+
|
315
|
+
## Git
|
316
|
+
say_wizard "initialize git"
|
317
|
+
prefs[:git] = true unless prefs.has_key? :git
|
318
|
+
if prefer :git, true
|
319
|
+
copy_from 'https://raw.github.com/RailsApps/rails-composer/master/files/gitignore.txt', '.gitignore'
|
320
|
+
git :init
|
321
|
+
git :add => '-A'
|
322
|
+
git :commit => '-qm "rails_apps_composer: initial commit"'
|
323
|
+
else
|
324
|
+
after_everything do
|
325
|
+
say_wizard "removing .gitignore and .gitkeep files"
|
326
|
+
git_files = Dir[File.join('**','.gitkeep')] + Dir[File.join('**','.gitignore')]
|
327
|
+
File.unlink git_files
|
328
|
+
end
|
329
|
+
end
|
330
|
+
# >----------------------------- recipes/git.rb ------------------------------end<
|
331
|
+
# >-------------------------- templates/recipe.erb ---------------------------end<
|
332
|
+
|
333
|
+
# >-------------------------- templates/recipe.erb ---------------------------start<
|
334
|
+
# >-------------------------------[ railsapps ]-------------------------------<
|
335
|
+
@current_recipe = "railsapps"
|
336
|
+
@before_configs["railsapps"].call if @before_configs["railsapps"]
|
337
|
+
say_recipe 'railsapps'
|
338
|
+
@configs[@current_recipe] = config
|
339
|
+
# >-------------------------- recipes/railsapps.rb ---------------------------start<
|
340
|
+
|
341
|
+
# Application template recipe for the rails_apps_composer. Change the recipe here:
|
342
|
+
# https://github.com/RailsApps/rails_apps_composer/blob/master/recipes/railsapps.rb
|
343
|
+
|
344
|
+
raise if (defined? defaults) || (defined? preferences) # Shouldn't happen.
|
345
|
+
if options[:verbose]
|
346
|
+
print "\nrecipes: ";p recipes
|
347
|
+
print "\ngems: " ;p gems
|
348
|
+
print "\nprefs: " ;p prefs
|
349
|
+
print "\nconfig: " ;p config
|
350
|
+
end
|
351
|
+
|
352
|
+
case Rails::VERSION::MAJOR.to_s
|
353
|
+
when "3"
|
354
|
+
prefs[:railsapps] = multiple_choice "Install an example application for Rails 3.2?",
|
355
|
+
[["I want to build my own application", "none"],
|
356
|
+
["membership/subscription/saas", "saas"],
|
357
|
+
["rails-prelaunch-signup", "rails-prelaunch-signup"],
|
358
|
+
["rails3-bootstrap-devise-cancan", "rails3-bootstrap-devise-cancan"],
|
359
|
+
["rails3-devise-rspec-cucumber", "rails3-devise-rspec-cucumber"],
|
360
|
+
["rails3-mongoid-devise", "rails3-mongoid-devise"],
|
361
|
+
["rails3-mongoid-omniauth", "rails3-mongoid-omniauth"],
|
362
|
+
["rails3-subdomains", "rails3-subdomains"]] unless prefs.has_key? :railsapps
|
363
|
+
when "4"
|
364
|
+
prefs[:apps4] = multiple_choice "Install an example application for Rails 4.0?",
|
365
|
+
[["Build a RailsApps starter application", "railsapps"],
|
366
|
+
["Build a contributed application", "contributed_app"],
|
367
|
+
["I want to build my own application", "none"]] unless prefs.has_key? :apps4
|
368
|
+
case prefs[:apps4]
|
369
|
+
when 'railsapps'
|
370
|
+
prefs[:apps4] = multiple_choice "Starter apps for Rails 4.0. More to come.",
|
371
|
+
[["learn-rails", "learn-rails"],
|
372
|
+
["rails-bootstrap", "rails-bootstrap"],
|
373
|
+
["rails-foundation", "rails-foundation"],
|
374
|
+
["rails-devise", "rails-devise"],
|
375
|
+
["rails-omniauth", "rails-omniauth"]]
|
376
|
+
when 'contributed_app'
|
377
|
+
prefs[:apps4] = multiple_choice "No contributed applications are available.",
|
378
|
+
[["continue", "none"]]
|
379
|
+
end
|
380
|
+
end
|
381
|
+
|
382
|
+
case prefs[:apps4]
|
383
|
+
when 'simple-test'
|
384
|
+
prefs[:dev_webserver] = 'webrick'
|
385
|
+
prefs[:prod_webserver] = 'same'
|
386
|
+
prefs[:templates] = 'erb'
|
387
|
+
prefs[:git] = false
|
388
|
+
prefs[:github] = false
|
389
|
+
prefs[:database] = 'sqlite'
|
390
|
+
prefs[:unit_test] = false
|
391
|
+
prefs[:integration] = false
|
392
|
+
prefs[:fixtures] = false
|
393
|
+
prefs[:frontend] = false
|
394
|
+
prefs[:email] = false
|
395
|
+
prefs[:authentication] = false
|
396
|
+
prefs[:devise_modules] = false
|
397
|
+
prefs[:authorization] = false
|
398
|
+
prefs[:starter_app] = false
|
399
|
+
prefs[:form_builder] = false
|
400
|
+
prefs[:quiet_assets] = false
|
401
|
+
prefs[:local_env_file] = 'none'
|
402
|
+
prefs[:better_errors] = false
|
403
|
+
prefs[:ban_spiders] = false
|
404
|
+
prefs[:continuous_testing] = false
|
405
|
+
when 'learn-rails'
|
406
|
+
prefs[:git] = true
|
407
|
+
prefs[:database] = 'default'
|
408
|
+
prefs[:unit_test] = false
|
409
|
+
prefs[:integration] = false
|
410
|
+
prefs[:fixtures] = false
|
411
|
+
prefs[:email] = 'gmail'
|
412
|
+
prefs[:authentication] = false
|
413
|
+
prefs[:devise_modules] = false
|
414
|
+
prefs[:authorization] = false
|
415
|
+
prefs[:starter_app] = false
|
416
|
+
prefs[:form_builder] = 'simple_form'
|
417
|
+
prefs[:quiet_assets] = true
|
418
|
+
prefs[:local_env_file] = 'figaro'
|
419
|
+
prefs[:better_errors] = true
|
420
|
+
when 'rails-bootstrap'
|
421
|
+
prefs[:git] = true
|
422
|
+
prefs[:database] = 'default'
|
423
|
+
prefs[:unit_test] = false
|
424
|
+
prefs[:integration] = false
|
425
|
+
prefs[:fixtures] = false
|
426
|
+
prefs[:frontend] = 'bootstrap3'
|
427
|
+
prefs[:email] = 'none'
|
428
|
+
prefs[:authentication] = false
|
429
|
+
prefs[:devise_modules] = false
|
430
|
+
prefs[:authorization] = false
|
431
|
+
prefs[:starter_app] = false
|
432
|
+
prefs[:form_builder] = 'simple_form'
|
433
|
+
prefs[:quiet_assets] = true
|
434
|
+
prefs[:local_env_file] = 'figaro'
|
435
|
+
prefs[:better_errors] = true
|
436
|
+
when 'rails-foundation'
|
437
|
+
prefs[:git] = true
|
438
|
+
prefs[:database] = 'default'
|
439
|
+
prefs[:unit_test] = false
|
440
|
+
prefs[:integration] = false
|
441
|
+
prefs[:fixtures] = false
|
442
|
+
prefs[:frontend] = 'foundation5'
|
443
|
+
prefs[:email] = 'none'
|
444
|
+
prefs[:authentication] = false
|
445
|
+
prefs[:devise_modules] = false
|
446
|
+
prefs[:authorization] = false
|
447
|
+
prefs[:starter_app] = false
|
448
|
+
prefs[:form_builder] = 'simple_form'
|
449
|
+
prefs[:quiet_assets] = true
|
450
|
+
prefs[:local_env_file] = 'figaro'
|
451
|
+
prefs[:better_errors] = true
|
452
|
+
when 'rails-devise'
|
453
|
+
prefs[:git] = true
|
454
|
+
prefs[:unit_test] = false
|
455
|
+
prefs[:integration] = false
|
456
|
+
prefs[:fixtures] = false
|
457
|
+
prefs[:authentication] = 'devise'
|
458
|
+
prefs[:authorization] = false
|
459
|
+
prefs[:starter_app] = false
|
460
|
+
prefs[:quiet_assets] = true
|
461
|
+
prefs[:local_env_file] = 'figaro'
|
462
|
+
prefs[:better_errors] = true
|
463
|
+
when 'rails-omniauth'
|
464
|
+
prefs[:git] = true
|
465
|
+
prefs[:unit_test] = false
|
466
|
+
prefs[:integration] = false
|
467
|
+
prefs[:fixtures] = false
|
468
|
+
prefs[:email] = 'none'
|
469
|
+
prefs[:authentication] = 'omniauth'
|
470
|
+
prefs[:authorization] = 'none'
|
471
|
+
prefs[:starter_app] = false
|
472
|
+
prefs[:form_builder] = 'none'
|
473
|
+
prefs[:quiet_assets] = true
|
474
|
+
prefs[:local_env_file] = 'figaro'
|
475
|
+
prefs[:better_errors] = true
|
476
|
+
end
|
477
|
+
|
478
|
+
case prefs[:railsapps]
|
479
|
+
when 'saas'
|
480
|
+
prefs[:railsapps] = multiple_choice "Billing with Stripe or Recurly?",
|
481
|
+
[["Stripe", "rails-stripe-membership-saas"],
|
482
|
+
["Recurly", "rails-recurly-subscription-saas"]]
|
483
|
+
end
|
484
|
+
|
485
|
+
case prefs[:railsapps]
|
486
|
+
when 'rails-stripe-membership-saas'
|
487
|
+
prefs[:git] = true
|
488
|
+
prefs[:database] = 'sqlite'
|
489
|
+
prefs[:unit_test] = 'rspec'
|
490
|
+
prefs[:integration] = 'cucumber'
|
491
|
+
prefs[:fixtures] = 'factory_girl'
|
492
|
+
prefs[:frontend] = 'bootstrap2'
|
493
|
+
prefs[:email] = 'gmail'
|
494
|
+
prefs[:authentication] = 'devise'
|
495
|
+
prefs[:devise_modules] = 'default'
|
496
|
+
prefs[:authorization] = 'cancan'
|
497
|
+
prefs[:starter_app] = 'admin_app'
|
498
|
+
prefs[:form_builder] = 'simple_form'
|
499
|
+
prefs[:quiet_assets] = true
|
500
|
+
prefs[:local_env_file] = 'figaro'
|
501
|
+
prefs[:better_errors] = true
|
502
|
+
when 'rails-recurly-subscription-saas'
|
503
|
+
prefs[:git] = true
|
504
|
+
prefs[:database] = 'sqlite'
|
505
|
+
prefs[:unit_test] = 'rspec'
|
506
|
+
prefs[:integration] = 'cucumber'
|
507
|
+
prefs[:fixtures] = 'factory_girl'
|
508
|
+
prefs[:frontend] = 'bootstrap2'
|
509
|
+
prefs[:email] = 'gmail'
|
510
|
+
prefs[:authentication] = 'devise'
|
511
|
+
prefs[:devise_modules] = 'default'
|
512
|
+
prefs[:authorization] = 'cancan'
|
513
|
+
prefs[:starter_app] = 'admin_app'
|
514
|
+
prefs[:form_builder] = 'simple_form'
|
515
|
+
prefs[:quiet_assets] = true
|
516
|
+
prefs[:local_env_file] = 'figaro'
|
517
|
+
prefs[:better_errors] = true
|
518
|
+
when 'rails-prelaunch-signup'
|
519
|
+
prefs[:git] = true
|
520
|
+
prefs[:database] = 'sqlite'
|
521
|
+
prefs[:unit_test] = 'rspec'
|
522
|
+
prefs[:integration] = 'cucumber'
|
523
|
+
prefs[:fixtures] = 'factory_girl'
|
524
|
+
prefs[:frontend] = 'bootstrap2'
|
525
|
+
prefs[:email] = 'mandrill'
|
526
|
+
prefs[:authentication] = 'devise'
|
527
|
+
prefs[:devise_modules] = 'confirmable'
|
528
|
+
prefs[:authorization] = 'cancan'
|
529
|
+
prefs[:starter_app] = 'admin_app'
|
530
|
+
prefs[:form_builder] = 'simple_form'
|
531
|
+
prefs[:quiet_assets] = true
|
532
|
+
prefs[:local_env_file] = 'figaro'
|
533
|
+
prefs[:better_errors] = true
|
534
|
+
if prefer :git, true
|
535
|
+
prefs[:prelaunch_branch] = multiple_choice "Git branch for the prelaunch app?",
|
536
|
+
[["wip (work-in-progress)", "wip"],
|
537
|
+
["master", "master"],
|
538
|
+
["prelaunch", "prelaunch"],
|
539
|
+
["staging", "staging"]] unless prefs.has_key? :prelaunch_branch
|
540
|
+
|
541
|
+
prefs[:main_branch] = unless 'master' == prefs[:prelaunch_branch]
|
542
|
+
'master'
|
543
|
+
else
|
544
|
+
multiple_choice "Git branch for the main app?",
|
545
|
+
[["None", "none"],
|
546
|
+
["wip (work-in-progress)", "wip"],
|
547
|
+
["edge", "edge"]]
|
548
|
+
end unless prefs.has_key? :main_branch
|
549
|
+
end
|
550
|
+
when 'rails3-bootstrap-devise-cancan'
|
551
|
+
prefs[:git] = true
|
552
|
+
prefs[:database] = 'sqlite'
|
553
|
+
prefs[:unit_test] = 'rspec'
|
554
|
+
prefs[:integration] = 'cucumber'
|
555
|
+
prefs[:fixtures] = 'factory_girl'
|
556
|
+
prefs[:frontend] = 'bootstrap2'
|
557
|
+
prefs[:email] = 'gmail'
|
558
|
+
prefs[:authentication] = 'devise'
|
559
|
+
prefs[:devise_modules] = 'default'
|
560
|
+
prefs[:authorization] = 'cancan'
|
561
|
+
prefs[:starter_app] = 'admin_app'
|
562
|
+
prefs[:form_builder] = 'simple_form'
|
563
|
+
prefs[:quiet_assets] = true
|
564
|
+
prefs[:local_env_file] = 'figaro'
|
565
|
+
prefs[:better_errors] = true
|
566
|
+
when 'rails3-devise-rspec-cucumber'
|
567
|
+
prefs[:git] = true
|
568
|
+
prefs[:database] = 'sqlite'
|
569
|
+
prefs[:unit_test] = 'rspec'
|
570
|
+
prefs[:integration] = 'cucumber'
|
571
|
+
prefs[:fixtures] = 'factory_girl'
|
572
|
+
prefs[:frontend] = 'none'
|
573
|
+
prefs[:email] = 'gmail'
|
574
|
+
prefs[:authentication] = 'devise'
|
575
|
+
prefs[:devise_modules] = 'default'
|
576
|
+
prefs[:authorization] = 'none'
|
577
|
+
prefs[:starter_app] = 'users_app'
|
578
|
+
prefs[:form_builder] = 'none'
|
579
|
+
prefs[:quiet_assets] = true
|
580
|
+
prefs[:local_env_file] = 'figaro'
|
581
|
+
prefs[:better_errors] = true
|
582
|
+
when 'rails3-devise-rspec-cucumber-fabrication'
|
583
|
+
prefs[:git] = true
|
584
|
+
prefs[:database] = 'sqlite'
|
585
|
+
prefs[:unit_test] = 'rspec'
|
586
|
+
prefs[:integration] = 'cucumber'
|
587
|
+
prefs[:fixtures] = 'fabrication'
|
588
|
+
prefs[:frontend] = 'none'
|
589
|
+
prefs[:email] = 'gmail'
|
590
|
+
prefs[:authentication] = 'devise'
|
591
|
+
prefs[:devise_modules] = 'default'
|
592
|
+
prefs[:authorization] = 'none'
|
593
|
+
prefs[:starter_app] = 'users_app'
|
594
|
+
prefs[:form_builder] = 'none'
|
595
|
+
prefs[:quiet_assets] = true
|
596
|
+
prefs[:local_env_file] = 'figaro'
|
597
|
+
prefs[:better_errors] = true
|
598
|
+
when 'rails3-mongoid-devise'
|
599
|
+
prefs[:git] = true
|
600
|
+
prefs[:database] = 'mongodb'
|
601
|
+
prefs[:orm] = 'mongoid'
|
602
|
+
prefs[:unit_test] = 'rspec'
|
603
|
+
prefs[:integration] = 'cucumber'
|
604
|
+
prefs[:fixtures] = 'factory_girl'
|
605
|
+
prefs[:frontend] = 'none'
|
606
|
+
prefs[:email] = 'gmail'
|
607
|
+
prefs[:authentication] = 'devise'
|
608
|
+
prefs[:devise_modules] = 'default'
|
609
|
+
prefs[:authorization] = 'none'
|
610
|
+
prefs[:starter_app] = 'users_app'
|
611
|
+
prefs[:form_builder] = 'none'
|
612
|
+
prefs[:quiet_assets] = true
|
613
|
+
prefs[:local_env_file] = 'figaro'
|
614
|
+
prefs[:better_errors] = true
|
615
|
+
when 'rails3-mongoid-omniauth'
|
616
|
+
prefs[:git] = true
|
617
|
+
prefs[:database] = 'mongodb'
|
618
|
+
prefs[:orm] = 'mongoid'
|
619
|
+
prefs[:unit_test] = 'rspec'
|
620
|
+
prefs[:integration] = 'cucumber'
|
621
|
+
prefs[:fixtures] = 'factory_girl'
|
622
|
+
prefs[:frontend] = 'none'
|
623
|
+
prefs[:email] = 'none'
|
624
|
+
prefs[:authentication] = 'omniauth'
|
625
|
+
prefs[:omniauth_provider] = 'twitter'
|
626
|
+
prefs[:authorization] = 'none'
|
627
|
+
prefs[:starter_app] = 'users_app'
|
628
|
+
prefs[:form_builder] = 'none'
|
629
|
+
prefs[:quiet_assets] = true
|
630
|
+
prefs[:local_env_file] = 'figaro'
|
631
|
+
prefs[:better_errors] = true
|
632
|
+
when 'rails3-subdomains'
|
633
|
+
prefs[:git] = true
|
634
|
+
prefs[:database] = 'mongodb'
|
635
|
+
prefs[:orm] = 'mongoid'
|
636
|
+
prefs[:unit_test] = 'rspec'
|
637
|
+
prefs[:integration] = 'cucumber'
|
638
|
+
prefs[:fixtures] = 'factory_girl'
|
639
|
+
prefs[:frontend] = 'none'
|
640
|
+
prefs[:email] = 'gmail'
|
641
|
+
prefs[:authentication] = 'devise'
|
642
|
+
prefs[:devise_modules] = 'default'
|
643
|
+
prefs[:authorization] = 'none'
|
644
|
+
prefs[:starter_app] = 'subdomains_app'
|
645
|
+
prefs[:form_builder] = 'none'
|
646
|
+
prefs[:quiet_assets] = true
|
647
|
+
prefs[:local_env_file] = 'figaro'
|
648
|
+
prefs[:better_errors] = true
|
649
|
+
end
|
650
|
+
# >-------------------------- recipes/railsapps.rb ---------------------------end<
|
651
|
+
# >-------------------------- templates/recipe.erb ---------------------------end<
|
652
|
+
|
653
|
+
# >-------------------------- templates/recipe.erb ---------------------------start<
|
654
|
+
# >---------------------------------[ setup ]---------------------------------<
|
655
|
+
@current_recipe = "setup"
|
656
|
+
@before_configs["setup"].call if @before_configs["setup"]
|
657
|
+
say_recipe 'setup'
|
658
|
+
@configs[@current_recipe] = config
|
659
|
+
# >---------------------------- recipes/setup.rb -----------------------------start<
|
660
|
+
|
661
|
+
# Application template recipe for the rails_apps_composer. Change the recipe here:
|
662
|
+
# https://github.com/RailsApps/rails_apps_composer/blob/master/recipes/setup.rb
|
663
|
+
|
664
|
+
## Ruby on Rails
|
665
|
+
HOST_OS = RbConfig::CONFIG['host_os']
|
666
|
+
say_wizard "Your operating system is #{HOST_OS}."
|
667
|
+
say_wizard "You are using Ruby version #{RUBY_VERSION}."
|
668
|
+
say_wizard "You are using Rails version #{Rails::VERSION::STRING}."
|
669
|
+
|
670
|
+
## Is sqlite3 in the Gemfile?
|
671
|
+
gemfile = File.read(destination_root() + '/Gemfile')
|
672
|
+
sqlite_detected = gemfile.include? 'sqlite3'
|
673
|
+
|
674
|
+
## Web Server
|
675
|
+
prefs[:dev_webserver] = multiple_choice "Web server for development?", [["WEBrick (default)", "webrick"],
|
676
|
+
["Thin", "thin"], ["Unicorn", "unicorn"], ["Puma", "puma"], ["Phusion Passenger (Apache/Nginx)", "passenger"],
|
677
|
+
["Phusion Passenger (Standalone)", "passenger_standalone"]] unless prefs.has_key? :dev_webserver
|
678
|
+
prefs[:prod_webserver] = multiple_choice "Web server for production?", [["Same as development", "same"],
|
679
|
+
["Thin", "thin"], ["Unicorn", "unicorn"], ["Puma", "puma"], ["Phusion Passenger (Apache/Nginx)", "passenger"],
|
680
|
+
["Phusion Passenger (Standalone)", "passenger_standalone"]] unless prefs.has_key? :prod_webserver
|
681
|
+
if prefs[:prod_webserver] == 'same'
|
682
|
+
case prefs[:dev_webserver]
|
683
|
+
when 'thin'
|
684
|
+
prefs[:prod_webserver] = 'thin'
|
685
|
+
when 'unicorn'
|
686
|
+
prefs[:prod_webserver] = 'unicorn'
|
687
|
+
when 'puma'
|
688
|
+
prefs[:prod_webserver] = 'puma'
|
689
|
+
when 'passenger'
|
690
|
+
prefs[:prod_webserver] = 'passenger'
|
691
|
+
when 'passenger_standalone'
|
692
|
+
prefs[:prod_webserver] = 'passenger_standalone'
|
693
|
+
end
|
694
|
+
end
|
695
|
+
|
696
|
+
## Database Adapter
|
697
|
+
prefs[:database] = multiple_choice "Database used in development?", [["SQLite", "sqlite"], ["PostgreSQL", "postgresql"],
|
698
|
+
["MySQL", "mysql"], ["MongoDB", "mongodb"], ["Redis", "redis"]] unless prefs.has_key? :database
|
699
|
+
case prefs[:database]
|
700
|
+
when 'redis'
|
701
|
+
prefs[:orm] = multiple_choice "How will you connect to Redis?", [["Redis","Redis"]] unless prefs.has_key? :orm
|
702
|
+
end
|
703
|
+
when 'mongodb'
|
704
|
+
unless sqlite_detected
|
705
|
+
prefs[:orm] = multiple_choice "How will you connect to MongoDB?", [["Mongoid","mongoid"]] unless prefs.has_key? :orm
|
706
|
+
else
|
707
|
+
say_wizard "WARNING! SQLite gem detected in the Gemfile"
|
708
|
+
say_wizard "If you wish to use MongoDB you must skip Active Record."
|
709
|
+
say_wizard "If using rails_apps_composer, choose 'skip Active Record'."
|
710
|
+
say_wizard "If using Rails Composer or an application template, use the '-O' flag as in 'rails new foo -O'."
|
711
|
+
prefs[:fail] = multiple_choice "Abort or continue?", [["abort", "abort"], ["continue", "continue"]]
|
712
|
+
if prefer :fail, 'abort'
|
713
|
+
raise StandardError.new "SQLite detected in the Gemfile. Use '-O' or '--skip-activerecord' as in 'rails new foo -O' if you don't want ActiveRecord and SQLite"
|
714
|
+
end
|
715
|
+
end
|
716
|
+
end
|
717
|
+
|
718
|
+
## Template Engine
|
719
|
+
prefs[:templates] = multiple_choice "Template engine?", [["ERB", "erb"], ["Haml", "haml"], ["Slim", "slim"]] unless prefs.has_key? :templates
|
720
|
+
|
721
|
+
## Testing Framework
|
722
|
+
if recipes.include? 'testing'
|
723
|
+
prefs[:unit_test] = multiple_choice "Unit testing?", [["Test::Unit", "test_unit"], ["RSpec", "rspec"], ["MiniTest", "minitest"]] unless prefs.has_key? :unit_test
|
724
|
+
prefs[:integration] = multiple_choice "Integration testing?", [["None", "none"], ["RSpec with Capybara", "rspec-capybara"],
|
725
|
+
["Cucumber with Capybara", "cucumber"], ["Turnip with Capybara", "turnip"], ["MiniTest with Capybara", "minitest-capybara"]] unless prefs.has_key? :integration
|
726
|
+
prefs[:continuous_testing] = multiple_choice "Continuous testing?", [["None", "none"], ["Guard", "guard"]] unless prefs.has_key? :continuous_testing
|
727
|
+
prefs[:fixtures] = multiple_choice "Fixture replacement?", [["None","none"], ["Factory Girl","factory_girl"], ["Machinist","machinist"], ["Fabrication","fabrication"]] unless prefs.has_key? :fixtures
|
728
|
+
end
|
729
|
+
|
730
|
+
## Front-end Framework
|
731
|
+
if recipes.include? 'frontend'
|
732
|
+
prefs[:frontend] = multiple_choice "Front-end framework?", [["None", "none"],
|
733
|
+
["Zurb Foundation 5.0", "foundation5"], ["Zurb Foundation 4.0", "foundation4"],
|
734
|
+
["Twitter Bootstrap 3.0", "bootstrap3"], ["Twitter Bootstrap 2.3", "bootstrap2"],
|
735
|
+
["Simple CSS", "simple"]] unless prefs.has_key? :frontend
|
736
|
+
end
|
737
|
+
|
738
|
+
## Email
|
739
|
+
if recipes.include? 'email'
|
740
|
+
unless prefs.has_key? :email
|
741
|
+
say_wizard "The Devise 'forgot password' feature requires email." if prefer :authentication, 'devise'
|
742
|
+
prefs[:email] = multiple_choice "Add support for sending email?", [["None", "none"], ["Gmail","gmail"], ["SMTP","smtp"],
|
743
|
+
["SendGrid","sendgrid"], ["Mandrill","mandrill"]]
|
744
|
+
end
|
745
|
+
else
|
746
|
+
prefs[:email] = 'none'
|
747
|
+
end
|
748
|
+
|
749
|
+
## Authentication and Authorization
|
750
|
+
if recipes.include? 'models'
|
751
|
+
prefs[:authentication] = multiple_choice "Authentication?", [["None", "none"], ["Devise", "devise"], ["OmniAuth", "omniauth"]] unless prefs.has_key? :authentication
|
752
|
+
case prefs[:authentication]
|
753
|
+
when 'devise'
|
754
|
+
if prefer :orm, 'mongoid'
|
755
|
+
prefs[:devise_modules] = multiple_choice "Devise modules?", [["Devise with default modules","default"]] unless prefs.has_key? :devise_modules
|
756
|
+
else
|
757
|
+
if rails_4?
|
758
|
+
prefs[:devise_modules] = multiple_choice "Devise modules?", [["Devise with default modules","default"],
|
759
|
+
["Devise with Confirmable module","confirmable"],
|
760
|
+
["Devise with Confirmable and Invitable modules","invitable"]] unless prefs.has_key? :devise_modules
|
761
|
+
else
|
762
|
+
prefs[:devise_modules] = multiple_choice "Devise modules?", [["Devise with default modules","default"],
|
763
|
+
["Devise with Confirmable module","confirmable"]] unless prefs.has_key? :devise_modules
|
764
|
+
end
|
765
|
+
end
|
766
|
+
when 'omniauth'
|
767
|
+
prefs[:omniauth_provider] = multiple_choice "OmniAuth provider?", [["Facebook", "facebook"], ["Twitter", "twitter"], ["GitHub", "github"],
|
768
|
+
["LinkedIn", "linkedin"], ["Google-Oauth-2", "google_oauth2"], ["Tumblr", "tumblr"]] unless prefs.has_key? :omniauth_provider
|
769
|
+
end
|
770
|
+
prefs[:authorization] = multiple_choice "Authorization?", [["None", "none"], ["CanCan with Rolify", "cancan"]] unless prefs.has_key? :authorization
|
771
|
+
end
|
772
|
+
|
773
|
+
## Form Builder
|
774
|
+
prefs[:form_builder] = multiple_choice "Use a form builder gem?", [["None", "none"], ["SimpleForm", "simple_form"]] unless prefs.has_key? :form_builder
|
775
|
+
|
776
|
+
## MVC
|
777
|
+
if (recipes.include? 'models') && (recipes.include? 'controllers') && (recipes.include? 'views') && (recipes.include? 'routes')
|
778
|
+
if prefer :authorization, 'cancan'
|
779
|
+
prefs[:starter_app] = multiple_choice "Install a starter app?", [["None", "none"], ["Home Page", "home_app"],
|
780
|
+
["Home Page, User Accounts", "users_app"], ["Home Page, User Accounts, Admin Dashboard", "admin_app"]] unless prefs.has_key? :starter_app
|
781
|
+
elsif prefer :authentication, 'devise'
|
782
|
+
if prefer :orm, 'mongoid'
|
783
|
+
prefs[:starter_app] = multiple_choice "Install a starter app?", [["None", "none"], ["Home Page", "home_app"],
|
784
|
+
["Home Page, User Accounts", "users_app"], ["Home Page, User Accounts, Subdomains", "subdomains_app"]] unless prefs.has_key? :starter_app
|
785
|
+
else
|
786
|
+
prefs[:starter_app] = multiple_choice "Install a starter app?", [["None", "none"], ["Home Page", "home_app"],
|
787
|
+
["Home Page, User Accounts", "users_app"]] unless prefs.has_key? :starter_app
|
788
|
+
end
|
789
|
+
elsif prefer :authentication, 'omniauth'
|
790
|
+
prefs[:starter_app] = multiple_choice "Install a starter app?", [["None", "none"], ["Home Page", "home_app"],
|
791
|
+
["Home Page, User Accounts", "users_app"]] unless prefs.has_key? :starter_app
|
792
|
+
else
|
793
|
+
prefs[:starter_app] = multiple_choice "Install a starter app?", [["None", "none"], ["Home Page", "home_app"]] unless prefs.has_key? :starter_app
|
794
|
+
end
|
795
|
+
end
|
796
|
+
|
797
|
+
# save diagnostics before anything can fail
|
798
|
+
create_file "README", "RECIPES\n#{recipes.sort.inspect}\n"
|
799
|
+
append_file "README", "PREFERENCES\n#{prefs.inspect}"
|
800
|
+
# >---------------------------- recipes/setup.rb -----------------------------end<
|
801
|
+
# >-------------------------- templates/recipe.erb ---------------------------end<
|
802
|
+
|
803
|
+
# >-------------------------- templates/recipe.erb ---------------------------start<
|
804
|
+
# >--------------------------------[ readme ]---------------------------------<
|
805
|
+
@current_recipe = "readme"
|
806
|
+
@before_configs["readme"].call if @before_configs["readme"]
|
807
|
+
say_recipe 'readme'
|
808
|
+
@configs[@current_recipe] = config
|
809
|
+
# >---------------------------- recipes/readme.rb ----------------------------start<
|
810
|
+
|
811
|
+
# Application template recipe for the rails_apps_composer. Change the recipe here:
|
812
|
+
# https://github.com/RailsApps/rails_apps_composer/blob/master/recipes/readme.rb
|
813
|
+
|
814
|
+
after_everything do
|
815
|
+
say_wizard "recipe running after everything"
|
816
|
+
|
817
|
+
# remove default READMEs
|
818
|
+
%w{
|
819
|
+
README
|
820
|
+
README.rdoc
|
821
|
+
doc/README_FOR_APP
|
822
|
+
}.each { |file| remove_file file }
|
823
|
+
|
824
|
+
# add placeholder READMEs and humans.txt file
|
825
|
+
copy_from_repo 'public/humans.txt'
|
826
|
+
copy_from_repo 'README'
|
827
|
+
copy_from_repo 'README.md'
|
828
|
+
gsub_file "README", /App_Name/, "#{app_name.humanize.titleize}"
|
829
|
+
gsub_file "README.md", /App_Name/, "#{app_name.humanize.titleize}"
|
830
|
+
|
831
|
+
# Diagnostics
|
832
|
+
gsub_file "README.md", /recipes that are known/, "recipes that are NOT known" if diagnostics[:recipes] == 'fail'
|
833
|
+
gsub_file "README.md", /preferences that are known/, "preferences that are NOT known" if diagnostics[:prefs] == 'fail'
|
834
|
+
print_recipes = recipes.sort.map { |r| "\n* #{r}" }.join('')
|
835
|
+
print_preferences = prefs.map { |k, v| "\n* #{k}: #{v}" }.join('')
|
836
|
+
gsub_file "README.md", /RECIPES/, print_recipes
|
837
|
+
gsub_file "README.md", /PREFERENCES/, print_preferences
|
838
|
+
gsub_file "README", /RECIPES/, print_recipes
|
839
|
+
gsub_file "README", /PREFERENCES/, print_preferences
|
840
|
+
|
841
|
+
# Ruby on Rails
|
842
|
+
gsub_file "README.md", /\* Ruby/, "* Ruby version #{RUBY_VERSION}"
|
843
|
+
gsub_file "README.md", /\* Rails/, "* Rails version #{Rails::VERSION::STRING}"
|
844
|
+
|
845
|
+
# Database
|
846
|
+
gsub_file "README.md", /SQLite/, "PostgreSQL" if prefer :database, 'postgresql'
|
847
|
+
gsub_file "README.md", /SQLite/, "MySQL" if prefer :database, 'mysql'
|
848
|
+
gsub_file "README.md", /SQLite/, "MongoDB" if prefer :database, 'mongodb'
|
849
|
+
gsub_file "README.md", /ActiveRecord/, "the Mongoid ORM" if prefer :orm, 'mongoid'
|
850
|
+
|
851
|
+
# Template Engine
|
852
|
+
gsub_file "README.md", /ERB/, "Haml" if prefer :templates, 'haml'
|
853
|
+
gsub_file "README.md", /ERB/, "Slim" if prefer :templates, 'slim'
|
854
|
+
|
855
|
+
# Testing Framework
|
856
|
+
gsub_file "README.md", /Test::Unit/, "RSpec" if prefer :unit_test, 'rspec'
|
857
|
+
gsub_file "README.md", /RSpec/, "RSpec and Cucumber" if prefer :integration, 'cucumber'
|
858
|
+
gsub_file "README.md", /RSpec/, "RSpec and Factory Girl" if prefer :fixtures, 'factory_girl'
|
859
|
+
gsub_file "README.md", /RSpec/, "RSpec and Machinist" if prefer :fixtures, 'machinist'
|
860
|
+
|
861
|
+
# Front-end Framework
|
862
|
+
gsub_file "README.md", /Front-end Framework: None/, "Front-end Framework: Twitter Bootstrap 2.3 (Sass)" if prefer :frontend, 'bootstrap2'
|
863
|
+
gsub_file "README.md", /Front-end Framework: None/, "Front-end Framework: Twitter Bootstrap 3.0 (Sass)" if prefer :frontend, 'bootstrap3'
|
864
|
+
gsub_file "README.md", /Front-end Framework: None/, "Front-end Framework: Zurb Foundation 4" if prefer :frontend, 'foundation4'
|
865
|
+
gsub_file "README.md", /Front-end Framework: None/, "Front-end Framework: Zurb Foundation 5" if prefer :frontend, 'foundation5'
|
866
|
+
|
867
|
+
# Form Builder
|
868
|
+
gsub_file "README.md", /Form Builder: None/, "Form Builder: SimpleForm" if prefer :form_builder, 'simple_form'
|
869
|
+
|
870
|
+
# Email
|
871
|
+
unless prefer :email, 'none'
|
872
|
+
gsub_file "README.md", /Gmail/, "SMTP" if prefer :email, 'smtp'
|
873
|
+
gsub_file "README.md", /Gmail/, "SendGrid" if prefer :email, 'sendgrid'
|
874
|
+
gsub_file "README.md", /Gmail/, "Mandrill" if prefer :email, 'mandrill'
|
875
|
+
gsub_file "README.md", /Email delivery is disabled in development./, "Email delivery is configured via MailCatcher in development." if prefer :mailcatcher, true
|
876
|
+
insert_into_file 'README.md', "\nEmail rendering in development enabled via MailView.", :after => /Email delivery is.*\n/ if prefer :mail_view, true
|
877
|
+
else
|
878
|
+
gsub_file "README.md", /Email/, ""
|
879
|
+
gsub_file "README.md", /-----/, ""
|
880
|
+
gsub_file "README.md", /The application is configured to send email using a Gmail account./, ""
|
881
|
+
gsub_file "README.md", /Email delivery is disabled in development./, ""
|
882
|
+
end
|
883
|
+
|
884
|
+
# Authentication and Authorization
|
885
|
+
gsub_file "README.md", /Authentication: None/, "Authentication: Devise" if prefer :authentication, 'devise'
|
886
|
+
gsub_file "README.md", /Authentication: None/, "Authentication: OmniAuth" if prefer :authentication, 'omniauth'
|
887
|
+
gsub_file "README.md", /Authorization: None/, "Authorization: CanCan" if prefer :authorization, 'cancan'
|
888
|
+
|
889
|
+
# Admin
|
890
|
+
gsub_file "README.md", /Admin: None/, "Admin: ActiveAdmin" if prefer :admin, 'activeadmin'
|
891
|
+
gsub_file "README.md", /Admin: None/, "Admin: RailsAdmin" if prefer :admin, 'rails_admin'
|
892
|
+
|
893
|
+
git :add => '-A' if prefer :git, true
|
894
|
+
git :commit => '-qm "rails_apps_composer: add README files"' if prefer :git, true
|
895
|
+
|
896
|
+
end # after_everything
|
897
|
+
# >---------------------------- recipes/readme.rb ----------------------------end<
|
898
|
+
# >-------------------------- templates/recipe.erb ---------------------------end<
|
899
|
+
|
900
|
+
# >-------------------------- templates/recipe.erb ---------------------------start<
|
901
|
+
# >---------------------------------[ admin ]---------------------------------<
|
902
|
+
@current_recipe = "admin"
|
903
|
+
@before_configs["admin"].call if @before_configs["admin"]
|
904
|
+
say_recipe 'admin'
|
905
|
+
config = {}
|
906
|
+
config['admin'] = multiple_choice("Install admin gem?", [["None", "none"], ["ActiveAdmin", "activeadmin"], ["RailsAdmin", "rails_admin"]]) if true && true unless config.key?('admin') || prefs.has_key?(:admin)
|
907
|
+
@configs[@current_recipe] = config
|
908
|
+
# >---------------------------- recipes/admin.rb -----------------------------start<
|
909
|
+
|
910
|
+
# Application template recipe for the rails_apps_composer. Change the recipe here:
|
911
|
+
# https://github.com/RailsApps/rails_apps_composer/blob/master/recipes/admin.rb
|
912
|
+
|
913
|
+
case config['admin']
|
914
|
+
when 'activeadmin'
|
915
|
+
prefs[:admin] = 'activeadmin'
|
916
|
+
when 'rails_admin'
|
917
|
+
prefs[:admin] = 'rails_admin'
|
918
|
+
end
|
919
|
+
|
920
|
+
if prefer :admin, 'activeadmin'
|
921
|
+
if rails_4?
|
922
|
+
add_gem 'activeadmin', github: 'gregbell/active_admin'
|
923
|
+
else
|
924
|
+
add_gem 'activeadmin'
|
925
|
+
end
|
926
|
+
end
|
927
|
+
add_gem 'rails_admin' if prefer :admin, 'rails_admin'
|
928
|
+
|
929
|
+
after_bundler do
|
930
|
+
if prefer :admin, 'activeadmin'
|
931
|
+
say_wizard "recipe installing activeadmin"
|
932
|
+
generate 'active_admin:install'
|
933
|
+
end
|
934
|
+
if prefer :admin, 'rails_admin'
|
935
|
+
say_wizard "recipe installing rails_admin"
|
936
|
+
generate 'rails_admin:install'
|
937
|
+
end
|
938
|
+
### GIT
|
939
|
+
git :add => '-A' if prefer :git, true
|
940
|
+
git :commit => %Q(-qm "rails_apps_composer: installed #{prefs[:admin]}") if prefer :git, true
|
941
|
+
end
|
942
|
+
# >---------------------------- recipes/admin.rb -----------------------------end<
|
943
|
+
# >-------------------------- templates/recipe.erb ---------------------------end<
|
944
|
+
|
945
|
+
# >-------------------------- templates/recipe.erb ---------------------------start<
|
946
|
+
# >---------------------------------[ email ]---------------------------------<
|
947
|
+
@current_recipe = "email"
|
948
|
+
@before_configs["email"].call if @before_configs["email"]
|
949
|
+
say_recipe 'email'
|
950
|
+
@configs[@current_recipe] = config
|
951
|
+
# >---------------------------- recipes/email.rb -----------------------------start<
|
952
|
+
|
953
|
+
# Application template recipe for the rails_apps_composer. Change the recipe here:
|
954
|
+
# https://github.com/RailsApps/rails_apps_composer/blob/master/recipes/email.rb
|
955
|
+
|
956
|
+
after_bundler do
|
957
|
+
say_wizard "recipe running after 'bundle install'"
|
958
|
+
unless prefer :email, 'none'
|
959
|
+
if rails_4?
|
960
|
+
dev_email_text = <<-TEXT
|
961
|
+
# ActionMailer Config
|
962
|
+
config.action_mailer.default_url_options = { :host => 'localhost:3000' }
|
963
|
+
config.action_mailer.delivery_method = :smtp
|
964
|
+
config.action_mailer.raise_delivery_errors = true
|
965
|
+
# Send email in development mode.
|
966
|
+
config.action_mailer.perform_deliveries = false
|
967
|
+
TEXT
|
968
|
+
prod_email_text = <<-TEXT
|
969
|
+
# ActionMailer Config
|
970
|
+
config.action_mailer.default_url_options = { :host => 'example.com' }
|
971
|
+
config.action_mailer.delivery_method = :smtp
|
972
|
+
config.action_mailer.perform_deliveries = true
|
973
|
+
config.action_mailer.raise_delivery_errors = false
|
974
|
+
TEXT
|
975
|
+
inject_into_file 'config/environments/development.rb', dev_email_text, :after => "config.assets.debug = true"
|
976
|
+
inject_into_file 'config/environments/production.rb', prod_email_text, :after => "config.active_support.deprecation = :notify"
|
977
|
+
else
|
978
|
+
### DEVELOPMENT
|
979
|
+
gsub_file 'config/environments/development.rb', /# Don't care if the mailer can't send/, '# ActionMailer Config'
|
980
|
+
gsub_file 'config/environments/development.rb', /config.action_mailer.raise_delivery_errors = false/ do
|
981
|
+
<<-RUBY
|
982
|
+
config.action_mailer.default_url_options = { :host => 'localhost:3000' }
|
983
|
+
config.action_mailer.delivery_method = :smtp
|
984
|
+
# change to true to allow email to be sent during development
|
985
|
+
config.action_mailer.perform_deliveries = false
|
986
|
+
config.action_mailer.raise_delivery_errors = true
|
987
|
+
config.action_mailer.default :charset => "utf-8"
|
988
|
+
RUBY
|
989
|
+
end
|
990
|
+
### TEST
|
991
|
+
inject_into_file 'config/environments/test.rb', :before => "\nend" do
|
992
|
+
<<-RUBY
|
993
|
+
\n
|
994
|
+
# ActionMailer Config
|
995
|
+
config.action_mailer.default_url_options = { :host => 'example.com' }
|
996
|
+
RUBY
|
997
|
+
end
|
998
|
+
### PRODUCTION
|
999
|
+
gsub_file 'config/environments/production.rb', /config.active_support.deprecation = :notify/ do
|
1000
|
+
<<-RUBY
|
1001
|
+
config.active_support.deprecation = :notify
|
1002
|
+
|
1003
|
+
config.action_mailer.default_url_options = { :host => 'example.com' }
|
1004
|
+
# ActionMailer Config
|
1005
|
+
# Setup for production - deliveries, no errors raised
|
1006
|
+
config.action_mailer.delivery_method = :smtp
|
1007
|
+
config.action_mailer.perform_deliveries = true
|
1008
|
+
config.action_mailer.raise_delivery_errors = false
|
1009
|
+
config.action_mailer.default :charset => "utf-8"
|
1010
|
+
RUBY
|
1011
|
+
end
|
1012
|
+
end
|
1013
|
+
end
|
1014
|
+
### GMAIL ACCOUNT
|
1015
|
+
if prefer :email, 'gmail'
|
1016
|
+
gmail_configuration_text = <<-TEXT
|
1017
|
+
\n
|
1018
|
+
config.action_mailer.smtp_settings = {
|
1019
|
+
address: "smtp.gmail.com",
|
1020
|
+
port: 587,
|
1021
|
+
domain: ENV["DOMAIN_NAME"],
|
1022
|
+
authentication: "plain",
|
1023
|
+
enable_starttls_auto: true,
|
1024
|
+
user_name: ENV["GMAIL_USERNAME"],
|
1025
|
+
password: ENV["GMAIL_PASSWORD"]
|
1026
|
+
}
|
1027
|
+
TEXT
|
1028
|
+
inject_into_file 'config/environments/development.rb', gmail_configuration_text, :after => "config.assets.debug = true"
|
1029
|
+
inject_into_file 'config/environments/production.rb', gmail_configuration_text, :after => "config.active_support.deprecation = :notify"
|
1030
|
+
end
|
1031
|
+
### SENDGRID ACCOUNT
|
1032
|
+
if prefer :email, 'sendgrid'
|
1033
|
+
sendgrid_configuration_text = <<-TEXT
|
1034
|
+
\n
|
1035
|
+
config.action_mailer.smtp_settings = {
|
1036
|
+
address: "smtp.sendgrid.net",
|
1037
|
+
port: 587,
|
1038
|
+
domain: ENV["DOMAIN_NAME"],
|
1039
|
+
authentication: "plain",
|
1040
|
+
user_name: ENV["SENDGRID_USERNAME"],
|
1041
|
+
password: ENV["SENDGRID_PASSWORD"]
|
1042
|
+
}
|
1043
|
+
TEXT
|
1044
|
+
inject_into_file 'config/environments/development.rb', sendgrid_configuration_text, :after => "config.assets.debug = true"
|
1045
|
+
inject_into_file 'config/environments/production.rb', sendgrid_configuration_text, :after => "config.active_support.deprecation = :notify"
|
1046
|
+
end
|
1047
|
+
### MANDRILL ACCOUNT
|
1048
|
+
if prefer :email, 'mandrill'
|
1049
|
+
mandrill_configuration_text = <<-TEXT
|
1050
|
+
\n
|
1051
|
+
config.action_mailer.smtp_settings = {
|
1052
|
+
:address => "smtp.mandrillapp.com",
|
1053
|
+
:port => 587,
|
1054
|
+
:user_name => ENV["MANDRILL_USERNAME"],
|
1055
|
+
:password => ENV["MANDRILL_APIKEY"]
|
1056
|
+
}
|
1057
|
+
TEXT
|
1058
|
+
inject_into_file 'config/environments/development.rb', mandrill_configuration_text, :after => "config.assets.debug = true"
|
1059
|
+
inject_into_file 'config/environments/production.rb', mandrill_configuration_text, :after => "config.active_support.deprecation = :notify"
|
1060
|
+
end
|
1061
|
+
### GIT
|
1062
|
+
git :add => '-A' if prefer :git, true
|
1063
|
+
git :commit => '-qm "rails_apps_composer: set email accounts"' if prefer :git, true
|
1064
|
+
end # after_bundler
|
1065
|
+
# >---------------------------- recipes/email.rb -----------------------------end<
|
1066
|
+
# >-------------------------- templates/recipe.erb ---------------------------end<
|
1067
|
+
|
1068
|
+
# >-------------------------- templates/recipe.erb ---------------------------start<
|
1069
|
+
# >---------------------------------[ gems ]----------------------------------<
|
1070
|
+
@current_recipe = "gems"
|
1071
|
+
@before_configs["gems"].call if @before_configs["gems"]
|
1072
|
+
say_recipe 'gems'
|
1073
|
+
@configs[@current_recipe] = config
|
1074
|
+
# >----------------------------- recipes/gems.rb -----------------------------start<
|
1075
|
+
|
1076
|
+
# Application template recipe for the rails_apps_composer. Change the recipe here:
|
1077
|
+
# https://github.com/RailsApps/rails_apps_composer/blob/master/recipes/gems.rb
|
1078
|
+
|
1079
|
+
### GEMFILE ###
|
1080
|
+
|
1081
|
+
## Ruby on Rails
|
1082
|
+
insert_into_file('Gemfile', "ruby '#{RUBY_VERSION}'\n", :before => /^ *gem 'rails'/, :force => false)
|
1083
|
+
|
1084
|
+
## Cleanup
|
1085
|
+
# remove the 'sdoc' gem
|
1086
|
+
gsub_file 'Gemfile', /group :doc do/, ''
|
1087
|
+
gsub_file 'Gemfile', /\s*gem 'sdoc', require: false\nend/, ''
|
1088
|
+
|
1089
|
+
assets_group = rails_4? ? nil : :assets
|
1090
|
+
|
1091
|
+
## Web Server
|
1092
|
+
if (prefs[:dev_webserver] == prefs[:prod_webserver])
|
1093
|
+
add_gem 'thin' if prefer :dev_webserver, 'thin'
|
1094
|
+
add_gem 'unicorn' if prefer :dev_webserver, 'unicorn'
|
1095
|
+
add_gem 'unicorn-rails' if prefer :dev_webserver, 'unicorn'
|
1096
|
+
add_gem 'puma' if prefer :dev_webserver, 'puma'
|
1097
|
+
add_gem 'passenger' if prefer :dev_webserver, 'passenger_standalone'
|
1098
|
+
else
|
1099
|
+
add_gem 'thin', :group => [:development, :test] if prefer :dev_webserver, 'thin'
|
1100
|
+
add_gem 'unicorn', :group => [:development, :test] if prefer :dev_webserver, 'unicorn'
|
1101
|
+
add_gem 'unicorn-rails', :group => [:development, :test] if prefer :dev_webserver, 'unicorn'
|
1102
|
+
add_gem 'puma', :group => [:development, :test] if prefer :dev_webserver, 'puma'
|
1103
|
+
add_gem 'passenger', :group => [:development, :test] if prefer :dev_webserver, 'passenger_standalone'
|
1104
|
+
add_gem 'thin', :group => :production if prefer :prod_webserver, 'thin'
|
1105
|
+
add_gem 'unicorn', :group => :production if prefer :prod_webserver, 'unicorn'
|
1106
|
+
add_gem 'puma', :group => :production if prefer :prod_webserver, 'puma'
|
1107
|
+
add_gem 'passenger', :group => :production if prefer :prod_webserver, 'passenger_standalone'
|
1108
|
+
end
|
1109
|
+
|
1110
|
+
## Rails 4.0 attr_accessible Compatibility
|
1111
|
+
# if prefer :apps4, false
|
1112
|
+
# add_gem 'protected_attributes' if rails_4?
|
1113
|
+
# end
|
1114
|
+
|
1115
|
+
## Database Adapter
|
1116
|
+
unless prefer :database, 'default'
|
1117
|
+
gsub_file 'Gemfile', /gem 'sqlite3'\n/, '' unless prefer :database, 'sqlite'
|
1118
|
+
end
|
1119
|
+
if rails_4?
|
1120
|
+
add_gem 'mongoid', github: 'mongoid/mongoid' if prefer :orm, 'mongoid'
|
1121
|
+
else
|
1122
|
+
add_gem 'mongoid' if prefer :orm, 'mongoid'
|
1123
|
+
end
|
1124
|
+
gsub_file 'Gemfile', /gem 'pg'.*/, ''
|
1125
|
+
add_gem 'pg' if prefer :database, 'postgresql'
|
1126
|
+
gsub_file 'Gemfile', /gem 'mysql2'.*/, ''
|
1127
|
+
add_gem 'mysql2' if prefer :database, 'mysql'
|
1128
|
+
|
1129
|
+
## Template Engine
|
1130
|
+
if prefer :templates, 'haml'
|
1131
|
+
add_gem 'haml-rails'
|
1132
|
+
add_gem 'html2haml', :group => :development
|
1133
|
+
end
|
1134
|
+
if prefer :templates, 'slim'
|
1135
|
+
add_gem 'slim-rails'
|
1136
|
+
add_gem 'haml2slim', :group => :development
|
1137
|
+
add_gem 'html2haml', :group => :development
|
1138
|
+
end
|
1139
|
+
|
1140
|
+
## Testing Framework
|
1141
|
+
if prefer :unit_test, 'rspec'
|
1142
|
+
add_gem 'rspec-rails', :group => [:development, :test]
|
1143
|
+
add_gem 'capybara', :group => :test if prefer :integration, 'rspec-capybara'
|
1144
|
+
add_gem 'database_cleaner', '1.0.1', :group => :test
|
1145
|
+
if prefer :orm, 'mongoid'
|
1146
|
+
if rails_4?
|
1147
|
+
add_gem 'mongoid-rspec', '>= 1.10.0', :group => :test
|
1148
|
+
else
|
1149
|
+
add_gem 'mongoid-rspec', :group => :test
|
1150
|
+
end
|
1151
|
+
end
|
1152
|
+
add_gem 'email_spec', :group => :test
|
1153
|
+
end
|
1154
|
+
if prefer :unit_test, 'minitest'
|
1155
|
+
add_gem 'minitest-spec-rails', :group => :test
|
1156
|
+
add_gem 'minitest-wscolor', :group => :test
|
1157
|
+
add_gem 'capybara', :group => :test if prefer :integration, 'minitest-capybara'
|
1158
|
+
end
|
1159
|
+
if prefer :integration, 'cucumber'
|
1160
|
+
add_gem 'cucumber-rails', :group => :test, :require => false
|
1161
|
+
add_gem 'database_cleaner', '1.0.1', :group => :test unless prefer :unit_test, 'rspec'
|
1162
|
+
add_gem 'launchy', :group => :test
|
1163
|
+
add_gem 'capybara', :group => :test
|
1164
|
+
end
|
1165
|
+
add_gem 'turnip', '>= 1.1.0', :group => :test if prefer :integration, 'turnip'
|
1166
|
+
if prefer :continuous_testing, 'guard'
|
1167
|
+
add_gem 'guard-bundler', :group => :development
|
1168
|
+
add_gem 'guard-cucumber', :group => :development if prefer :integration, 'cucumber'
|
1169
|
+
add_gem 'guard-rails', :group => :development
|
1170
|
+
add_gem 'guard-rspec', :group => :development if prefer :unit_test, 'rspec'
|
1171
|
+
add_gem 'rb-inotify', :group => :development, :require => false
|
1172
|
+
add_gem 'rb-fsevent', :group => :development, :require => false
|
1173
|
+
add_gem 'rb-fchange', :group => :development, :require => false
|
1174
|
+
end
|
1175
|
+
add_gem 'factory_girl_rails', :group => [:development, :test] if prefer :fixtures, 'factory_girl'
|
1176
|
+
add_gem 'fabrication', :group => [:development, :test] if prefer :fixtures, 'fabrication'
|
1177
|
+
add_gem 'machinist', :group => :test if prefer :fixtures, 'machinist'
|
1178
|
+
|
1179
|
+
## Front-end Framework
|
1180
|
+
add_gem 'rails_layout', :group => :development
|
1181
|
+
case prefs[:frontend]
|
1182
|
+
when 'bootstrap2'
|
1183
|
+
add_gem 'bootstrap-sass', '~> 2.3.2.2'
|
1184
|
+
when 'bootstrap3'
|
1185
|
+
add_gem 'bootstrap-sass', '>= 3.0.0.0'
|
1186
|
+
when 'foundation4'
|
1187
|
+
if rails_4?
|
1188
|
+
add_gem 'zurb-foundation', '~> 4.3.2'
|
1189
|
+
add_gem 'compass-rails', '~> 1.1.2'
|
1190
|
+
else
|
1191
|
+
add_gem 'zurb-foundation', '~> 4.3.2', :group => assets_group
|
1192
|
+
add_gem 'compass-rails', '~> 1.0.3', :group => assets_group
|
1193
|
+
end
|
1194
|
+
when 'foundation5'
|
1195
|
+
add_gem 'foundation-rails'
|
1196
|
+
end
|
1197
|
+
|
1198
|
+
## Email
|
1199
|
+
add_gem 'sendgrid' if prefer :email, 'sendgrid'
|
1200
|
+
|
1201
|
+
## Authentication (Devise)
|
1202
|
+
add_gem 'devise' if prefer :authentication, 'devise'
|
1203
|
+
add_gem 'devise_invitable' if prefer :devise_modules, 'invitable'
|
1204
|
+
|
1205
|
+
## Authentication (OmniAuth)
|
1206
|
+
add_gem 'omniauth' if prefer :authentication, 'omniauth'
|
1207
|
+
add_gem 'omniauth-twitter' if prefer :omniauth_provider, 'twitter'
|
1208
|
+
add_gem 'omniauth-facebook' if prefer :omniauth_provider, 'facebook'
|
1209
|
+
add_gem 'omniauth-github' if prefer :omniauth_provider, 'github'
|
1210
|
+
add_gem 'omniauth-linkedin' if prefer :omniauth_provider, 'linkedin'
|
1211
|
+
add_gem 'omniauth-google-oauth2' if prefer :omniauth_provider, 'google_oauth2'
|
1212
|
+
add_gem 'omniauth-tumblr' if prefer :omniauth_provider, 'tumblr'
|
1213
|
+
|
1214
|
+
## Authorization
|
1215
|
+
if prefer :authorization, 'cancan'
|
1216
|
+
add_gem 'cancan'
|
1217
|
+
add_gem 'rolify'
|
1218
|
+
end
|
1219
|
+
|
1220
|
+
## Form Builder
|
1221
|
+
add_gem 'simple_form' if prefer :form_builder, 'simple_form'
|
1222
|
+
|
1223
|
+
## Membership App
|
1224
|
+
if prefer :railsapps, 'rails-stripe-membership-saas'
|
1225
|
+
add_gem 'stripe'
|
1226
|
+
add_gem 'stripe_event'
|
1227
|
+
end
|
1228
|
+
if prefer :railsapps, 'rails-recurly-subscription-saas'
|
1229
|
+
add_gem 'recurly'
|
1230
|
+
add_gem 'nokogiri'
|
1231
|
+
add_gem 'countries'
|
1232
|
+
add_gem 'httpi'
|
1233
|
+
add_gem 'httpclient'
|
1234
|
+
end
|
1235
|
+
|
1236
|
+
## Signup App
|
1237
|
+
if prefer :railsapps, 'rails-prelaunch-signup'
|
1238
|
+
add_gem 'gibbon'
|
1239
|
+
add_gem 'capybara-webkit', :group => :test
|
1240
|
+
end
|
1241
|
+
|
1242
|
+
## Gems from a defaults file or added interactively
|
1243
|
+
gems.each do |g|
|
1244
|
+
gem(*g)
|
1245
|
+
end
|
1246
|
+
|
1247
|
+
## Git
|
1248
|
+
git :add => '-A' if prefer :git, true
|
1249
|
+
git :commit => '-qm "rails_apps_composer: Gemfile"' if prefer :git, true
|
1250
|
+
|
1251
|
+
### CREATE DATABASE ###
|
1252
|
+
after_bundler do
|
1253
|
+
unless prefer :database, 'default'
|
1254
|
+
copy_from_repo 'config/database-postgresql.yml', :prefs => 'postgresql'
|
1255
|
+
copy_from_repo 'config/database-mysql.yml', :prefs => 'mysql'
|
1256
|
+
generate 'mongoid:config' if prefer :orm, 'mongoid'
|
1257
|
+
remove_file 'config/database.yml' if prefer :orm, 'mongoid'
|
1258
|
+
if prefer :database, 'postgresql'
|
1259
|
+
begin
|
1260
|
+
pg_username = prefs[:pg_username] || ask_wizard("Username for PostgreSQL?(leave blank to use the app name)")
|
1261
|
+
pg_host = prefs[:pg_username] || ask_wizard("Host for PostgreSQL in database.yml? (leave blank to use default socket connection)")
|
1262
|
+
if pg_username.blank?
|
1263
|
+
say_wizard "Creating a user named '#{app_name}' for PostgreSQL"
|
1264
|
+
run "createuser --createdb #{app_name}" if prefer :database, 'postgresql'
|
1265
|
+
gsub_file "config/database.yml", /username: .*/, "username: #{app_name}"
|
1266
|
+
else
|
1267
|
+
gsub_file "config/database.yml", /username: .*/, "username: #{pg_username}"
|
1268
|
+
pg_password = prefs[:pg_password] || ask_wizard("Password for PostgreSQL user #{pg_username}?")
|
1269
|
+
gsub_file "config/database.yml", /password:/, "password: #{pg_password}"
|
1270
|
+
say_wizard "set config/database.yml for username/password #{pg_username}/#{pg_password}"
|
1271
|
+
end
|
1272
|
+
if pg_host.present?
|
1273
|
+
gsub_file "config/database.yml", /#host: localhost/, "host: #{pg_host}"
|
1274
|
+
gsub_file "config/database.yml", /test:/, "test:\n host: #{pg_host}"
|
1275
|
+
end
|
1276
|
+
rescue StandardError => e
|
1277
|
+
raise "unable to create a user for PostgreSQL, reason: #{e}"
|
1278
|
+
end
|
1279
|
+
gsub_file "config/database.yml", /database: myapp_development/, "database: #{app_name}_development"
|
1280
|
+
gsub_file "config/database.yml", /database: myapp_test/, "database: #{app_name}_test"
|
1281
|
+
gsub_file "config/database.yml", /database: myapp_production/, "database: #{app_name}_production"
|
1282
|
+
end
|
1283
|
+
if prefer :database, 'mysql'
|
1284
|
+
mysql_username = prefs[:mysql_username] || ask_wizard("Username for MySQL? (leave blank to use the app name)")
|
1285
|
+
if mysql_username.blank?
|
1286
|
+
gsub_file "config/database.yml", /username: .*/, "username: #{app_name}"
|
1287
|
+
else
|
1288
|
+
gsub_file "config/database.yml", /username: .*/, "username: #{mysql_username}"
|
1289
|
+
mysql_password = prefs[:mysql_password] || ask_wizard("Password for MySQL user #{mysql_username}?")
|
1290
|
+
gsub_file "config/database.yml", /password:/, "password: #{mysql_password}"
|
1291
|
+
say_wizard "set config/database.yml for username/password #{mysql_username}/#{mysql_password}"
|
1292
|
+
end
|
1293
|
+
gsub_file "config/database.yml", /database: myapp_development/, "database: #{app_name}_development"
|
1294
|
+
gsub_file "config/database.yml", /database: myapp_test/, "database: #{app_name}_test"
|
1295
|
+
gsub_file "config/database.yml", /database: myapp_production/, "database: #{app_name}_production"
|
1296
|
+
end
|
1297
|
+
unless prefer :database, 'sqlite'
|
1298
|
+
if (prefs.has_key? :drop_database) ? prefs[:drop_database] :
|
1299
|
+
(yes_wizard? "Okay to drop all existing databases named #{app_name}? 'No' will abort immediately!")
|
1300
|
+
run 'bundle exec rake db:drop'
|
1301
|
+
else
|
1302
|
+
raise "aborted at user's request"
|
1303
|
+
end
|
1304
|
+
end
|
1305
|
+
run 'bundle exec rake db:create:all' unless prefer :orm, 'mongoid'
|
1306
|
+
run 'bundle exec rake db:create' if prefer :orm, 'mongoid'
|
1307
|
+
## Git
|
1308
|
+
git :add => '-A' if prefer :git, true
|
1309
|
+
git :commit => '-qm "rails_apps_composer: create database"' if prefer :git, true
|
1310
|
+
end
|
1311
|
+
end # after_bundler
|
1312
|
+
|
1313
|
+
### GENERATORS ###
|
1314
|
+
after_bundler do
|
1315
|
+
## Form Builder
|
1316
|
+
if prefer :form_builder, 'simple_form'
|
1317
|
+
case prefs[:frontend]
|
1318
|
+
when 'bootstrap2'
|
1319
|
+
say_wizard "recipe installing simple_form for use with Twitter Bootstrap"
|
1320
|
+
generate 'simple_form:install --bootstrap'
|
1321
|
+
when 'bootstrap3'
|
1322
|
+
say_wizard "recipe installing simple_form for use with Twitter Bootstrap"
|
1323
|
+
generate 'simple_form:install --bootstrap'
|
1324
|
+
when 'foundation4'
|
1325
|
+
say_wizard "recipe installing simple_form for use with Zurb Foundation"
|
1326
|
+
generate 'simple_form:install --foundation'
|
1327
|
+
else
|
1328
|
+
say_wizard "recipe installing simple_form"
|
1329
|
+
generate 'simple_form:install'
|
1330
|
+
end
|
1331
|
+
end
|
1332
|
+
## Figaro Gem
|
1333
|
+
if prefer :local_env_file, 'figaro' and not rails_4_1?
|
1334
|
+
generate 'figaro:install'
|
1335
|
+
gsub_file 'config/application.yml', /# PUSHER_.*\n/, ''
|
1336
|
+
gsub_file 'config/application.yml', /# STRIPE_.*\n/, ''
|
1337
|
+
prepend_to_file 'config/application.yml' do <<-FILE
|
1338
|
+
# Add account credentials and API keys here.
|
1339
|
+
# See http://railsapps.github.io/rails-environment-variables.html
|
1340
|
+
# This file should be listed in .gitignore to keep your settings secret!
|
1341
|
+
# Each entry sets a local environment variable and overrides ENV variables in the Unix shell.
|
1342
|
+
# For example, setting:
|
1343
|
+
# GMAIL_USERNAME: Your_Gmail_Username
|
1344
|
+
# makes 'Your_Gmail_Username' available as ENV["GMAIL_USERNAME"]
|
1345
|
+
|
1346
|
+
FILE
|
1347
|
+
end
|
1348
|
+
end
|
1349
|
+
## Foreman Gem
|
1350
|
+
if prefer :local_env_file, 'foreman'
|
1351
|
+
create_file '.env' do <<-FILE
|
1352
|
+
# Add account credentials and API keys here.
|
1353
|
+
# This file should be listed in .gitignore to keep your settings secret!
|
1354
|
+
# Each entry sets a local environment variable and overrides ENV variables in the Unix shell.
|
1355
|
+
# For example, setting:
|
1356
|
+
# GMAIL_USERNAME=Your_Gmail_Username
|
1357
|
+
# makes 'Your_Gmail_Username' available as ENV["GMAIL_USERNAME"]
|
1358
|
+
|
1359
|
+
FILE
|
1360
|
+
end
|
1361
|
+
create_file 'Procfile', 'web: bundle exec rails server -p $PORT' if prefer :prod_webserver, 'thin'
|
1362
|
+
create_file 'Procfile', 'web: bundle exec unicorn -p $PORT' if prefer :prod_webserver, 'unicorn'
|
1363
|
+
create_file 'Procfile', 'web: bundle exec puma -p $PORT' if prefer :prod_webserver, 'puma'
|
1364
|
+
create_file 'Procfile', 'web: bundle exec passenger start -p $PORT' if prefer :prod_webserver, 'passenger_standalone'
|
1365
|
+
if (prefs[:dev_webserver] != prefs[:prod_webserver])
|
1366
|
+
create_file 'Procfile.dev', 'web: bundle exec rails server -p $PORT' if prefer :dev_webserver, 'thin'
|
1367
|
+
create_file 'Procfile.dev', 'web: bundle exec unicorn -p $PORT' if prefer :dev_webserver, 'unicorn'
|
1368
|
+
create_file 'Procfile.dev', 'web: bundle exec puma -p $PORT' if prefer :dev_webserver, 'puma'
|
1369
|
+
create_file 'Procfile.dev', 'web: bundle exec passenger start -p $PORT' if prefer :dev_webserver, 'passenger_standalone'
|
1370
|
+
end
|
1371
|
+
end
|
1372
|
+
## Git
|
1373
|
+
git :add => '-A' if prefer :git, true
|
1374
|
+
git :commit => '-qm "rails_apps_composer: generators"' if prefer :git, true
|
1375
|
+
end # after_bundler
|
1376
|
+
# >----------------------------- recipes/gems.rb -----------------------------end<
|
1377
|
+
# >-------------------------- templates/recipe.erb ---------------------------end<
|
1378
|
+
|
1379
|
+
# >-------------------------- templates/recipe.erb ---------------------------start<
|
1380
|
+
# >-------------------------------[ frontend ]--------------------------------<
|
1381
|
+
@current_recipe = "frontend"
|
1382
|
+
@before_configs["frontend"].call if @before_configs["frontend"]
|
1383
|
+
say_recipe 'frontend'
|
1384
|
+
@configs[@current_recipe] = config
|
1385
|
+
# >--------------------------- recipes/frontend.rb ---------------------------start<
|
1386
|
+
|
1387
|
+
# Application template recipe for the rails_apps_composer. Change the recipe here:
|
1388
|
+
# https://github.com/RailsApps/rails_apps_composer/blob/master/recipes/frontend.rb
|
1389
|
+
|
1390
|
+
after_bundler do
|
1391
|
+
say_wizard "recipe running after 'bundle install'"
|
1392
|
+
# set up a front-end framework using the rails_layout gem
|
1393
|
+
case prefs[:frontend]
|
1394
|
+
when 'simple'
|
1395
|
+
generate 'layout:install simple -f'
|
1396
|
+
when 'bootstrap2'
|
1397
|
+
generate 'layout:install bootstrap2 -f'
|
1398
|
+
when 'bootstrap3'
|
1399
|
+
generate 'layout:install bootstrap3 -f'
|
1400
|
+
when 'foundation4'
|
1401
|
+
generate 'layout:install foundation4 -f'
|
1402
|
+
when 'foundation5'
|
1403
|
+
generate 'layout:install foundation5 -f'
|
1404
|
+
end
|
1405
|
+
# generate Devise views with appropriate styling
|
1406
|
+
if prefer :authentication, 'devise'
|
1407
|
+
case prefs[:frontend]
|
1408
|
+
when 'bootstrap3'
|
1409
|
+
generate 'layout:devise bootstrap3 -f'
|
1410
|
+
when 'foundation5'
|
1411
|
+
generate 'layout:devise foundation5 -f'
|
1412
|
+
end
|
1413
|
+
end
|
1414
|
+
|
1415
|
+
### GIT ###
|
1416
|
+
git :add => '-A' if prefer :git, true
|
1417
|
+
git :commit => '-qm "rails_apps_composer: front-end framework"' if prefer :git, true
|
1418
|
+
end # after_bundler
|
1419
|
+
|
1420
|
+
after_everything do
|
1421
|
+
say_wizard "recipe running after everything"
|
1422
|
+
# create navigation links using the rails_layout gem
|
1423
|
+
generate 'layout:navigation -f'
|
1424
|
+
# replace with specialized navigation partials
|
1425
|
+
copy_from_repo 'app/views/layouts/_navigation-subdomains_app.html.erb', :prefs => 'subdomains_app'
|
1426
|
+
|
1427
|
+
### GIT ###
|
1428
|
+
git :add => '-A' if prefer :git, true
|
1429
|
+
git :commit => '-qm "rails_apps_composer: navigation links"' if prefer :git, true
|
1430
|
+
end # after_everything
|
1431
|
+
# >--------------------------- recipes/frontend.rb ---------------------------end<
|
1432
|
+
# >-------------------------- templates/recipe.erb ---------------------------end<
|
1433
|
+
|
1434
|
+
# >-------------------------- templates/recipe.erb ---------------------------start<
|
1435
|
+
# >--------------------------------[ models ]---------------------------------<
|
1436
|
+
@current_recipe = "models"
|
1437
|
+
@before_configs["models"].call if @before_configs["models"]
|
1438
|
+
say_recipe 'models'
|
1439
|
+
@configs[@current_recipe] = config
|
1440
|
+
# >---------------------------- recipes/models.rb ----------------------------start<
|
1441
|
+
|
1442
|
+
# Application template recipe for the rails_apps_composer. Change the recipe here:
|
1443
|
+
# https://github.com/RailsApps/rails_apps_composer/blob/master/recipes/models.rb
|
1444
|
+
|
1445
|
+
after_bundler do
|
1446
|
+
say_wizard "recipe running after 'bundle install'"
|
1447
|
+
### DEVISE ###
|
1448
|
+
if prefer :authentication, 'devise'
|
1449
|
+
# prevent logging of password_confirmation
|
1450
|
+
gsub_file 'config/application.rb', /:password/, ':password, :password_confirmation'
|
1451
|
+
generate 'devise:install'
|
1452
|
+
generate 'devise_invitable:install' if prefer :devise_modules, 'invitable'
|
1453
|
+
generate 'devise user' # create the User model
|
1454
|
+
if prefer :orm, 'mongoid'
|
1455
|
+
## DEVISE AND MONGOID
|
1456
|
+
copy_from_repo 'app/models/user.rb', :repo => 'https://raw.github.com/RailsApps/rails3-mongoid-devise/master/' unless rails_4?
|
1457
|
+
if (prefer :devise_modules, 'confirmable') || (prefer :devise_modules, 'invitable')
|
1458
|
+
gsub_file 'app/models/user.rb', /:registerable,/, ":registerable, :confirmable,"
|
1459
|
+
gsub_file 'app/models/user.rb', /# field :confirmation_token/, "field :confirmation_token"
|
1460
|
+
gsub_file 'app/models/user.rb', /# field :confirmed_at/, "field :confirmed_at"
|
1461
|
+
gsub_file 'app/models/user.rb', /# field :confirmation_sent_at/, "field :confirmation_sent_at"
|
1462
|
+
gsub_file 'app/models/user.rb', /# field :unconfirmed_email/, "field :unconfirmed_email"
|
1463
|
+
end
|
1464
|
+
if (prefer :devise_modules, 'invitable')
|
1465
|
+
gsub_file 'app/models/user.rb', /\bend\s*\Z/ do
|
1466
|
+
<<-RUBY
|
1467
|
+
#invitable
|
1468
|
+
field :invitation_token, :type => String
|
1469
|
+
field :invitation_sent_at, :type => Time
|
1470
|
+
field :invitation_accepted_at, :type => Time
|
1471
|
+
field :invitation_limit, :type => Integer
|
1472
|
+
field :invited_by_id, :type => String
|
1473
|
+
field :invited_by_type, :type => String
|
1474
|
+
end
|
1475
|
+
RUBY
|
1476
|
+
end
|
1477
|
+
end
|
1478
|
+
else
|
1479
|
+
## DEVISE AND ACTIVE RECORD
|
1480
|
+
unless prefer :railsapps, 'rails-recurly-subscription-saas'
|
1481
|
+
generate 'migration AddNameToUsers name:string'
|
1482
|
+
end
|
1483
|
+
copy_from_repo 'app/models/user.rb', :repo => 'https://raw.github.com/RailsApps/rails3-devise-rspec-cucumber/master/' unless rails_4?
|
1484
|
+
if (prefer :devise_modules, 'confirmable') || (prefer :devise_modules, 'invitable')
|
1485
|
+
gsub_file 'app/models/user.rb', /:registerable,/, ":registerable, :confirmable,"
|
1486
|
+
generate 'migration AddConfirmableToUsers confirmation_token:string confirmed_at:datetime confirmation_sent_at:datetime unconfirmed_email:string'
|
1487
|
+
end
|
1488
|
+
end
|
1489
|
+
## DEVISE AND CUCUMBER
|
1490
|
+
if prefer :integration, 'cucumber'
|
1491
|
+
# Cucumber wants to test GET requests not DELETE requests for destroy_user_session_path
|
1492
|
+
# (see https://github.com/RailsApps/rails3-devise-rspec-cucumber/issues/3)
|
1493
|
+
gsub_file 'config/initializers/devise.rb', 'config.sign_out_via = :delete', 'config.sign_out_via = Rails.env.test? ? :get : :delete'
|
1494
|
+
end
|
1495
|
+
end
|
1496
|
+
### OMNIAUTH ###
|
1497
|
+
if prefer :authentication, 'omniauth'
|
1498
|
+
repo = 'https://raw.github.com/RailsApps/rails-omniauth/master/'
|
1499
|
+
copy_from_repo 'config/initializers/omniauth.rb', :repo => repo
|
1500
|
+
gsub_file 'config/initializers/omniauth.rb', /twitter/, prefs[:omniauth_provider] unless prefer :omniauth_provider, 'twitter'
|
1501
|
+
if prefer :orm, 'mongoid'
|
1502
|
+
repo = 'https://raw.github.com/RailsApps/rails3-mongoid-omniauth/master/'
|
1503
|
+
copy_from_repo 'app/models/user.rb', :repo => repo
|
1504
|
+
else
|
1505
|
+
generate 'model User name:string email:string provider:string uid:string'
|
1506
|
+
run 'bundle exec rake db:migrate'
|
1507
|
+
copy_from_repo 'app/models/user.rb', :repo => repo
|
1508
|
+
end
|
1509
|
+
end
|
1510
|
+
### SUBDOMAINS ###
|
1511
|
+
copy_from_repo 'app/models/user.rb', :repo => 'https://raw.github.com/RailsApps/rails3-subdomains/master/' if prefer :starter_app, 'subdomains_app'
|
1512
|
+
### AUTHORIZATION ###
|
1513
|
+
if prefer :authorization, 'cancan'
|
1514
|
+
generate 'cancan:ability'
|
1515
|
+
if prefer :starter_app, 'admin_app'
|
1516
|
+
# Limit access to the users#index page
|
1517
|
+
copy_from_repo 'app/models/ability.rb', :repo => 'https://raw.github.com/RailsApps/rails3-bootstrap-devise-cancan/master/'
|
1518
|
+
# allow an admin to update roles
|
1519
|
+
insert_into_file 'app/models/user.rb', " attr_accessible :role_ids, :as => :admin\n", :before => " attr_accessible"
|
1520
|
+
end
|
1521
|
+
unless prefer :orm, 'mongoid'
|
1522
|
+
generate 'rolify Role User'
|
1523
|
+
else
|
1524
|
+
generate 'rolify Role User --orm=mongoid'
|
1525
|
+
end
|
1526
|
+
end
|
1527
|
+
### GIT ###
|
1528
|
+
git :add => '-A' if prefer :git, true
|
1529
|
+
git :commit => '-qm "rails_apps_composer: models"' if prefer :git, true
|
1530
|
+
end # after_bundler
|
1531
|
+
# >---------------------------- recipes/models.rb ----------------------------end<
|
1532
|
+
# >-------------------------- templates/recipe.erb ---------------------------end<
|
1533
|
+
|
1534
|
+
# >-------------------------- templates/recipe.erb ---------------------------start<
|
1535
|
+
# >--------------------------------[ testing ]--------------------------------<
|
1536
|
+
@current_recipe = "testing"
|
1537
|
+
@before_configs["testing"].call if @before_configs["testing"]
|
1538
|
+
say_recipe 'testing'
|
1539
|
+
@configs[@current_recipe] = config
|
1540
|
+
# >--------------------------- recipes/testing.rb ----------------------------start<
|
1541
|
+
|
1542
|
+
# Application template recipe for the rails_apps_composer. Change the recipe here:
|
1543
|
+
# https://github.com/RailsApps/rails_apps_composer/blob/master/recipes/testing.rb
|
1544
|
+
|
1545
|
+
after_bundler do
|
1546
|
+
say_wizard "recipe running after 'bundle install'"
|
1547
|
+
### TEST/UNIT ###
|
1548
|
+
if prefer :unit_test, 'test_unit'
|
1549
|
+
inject_into_file 'config/application.rb', :after => "Rails::Application\n" do <<-RUBY
|
1550
|
+
|
1551
|
+
config.generators do |g|
|
1552
|
+
#{"g.test_framework :test_unit, fixture_replacement: :fabrication" if prefer :fixtures, 'fabrication'}
|
1553
|
+
#{"g.fixture_replacement :fabrication, dir: 'test/fabricators'" if prefer :fixtures, 'fabrication'}
|
1554
|
+
end
|
1555
|
+
|
1556
|
+
RUBY
|
1557
|
+
end
|
1558
|
+
end
|
1559
|
+
### RSPEC ###
|
1560
|
+
if prefer :unit_test, 'rspec'
|
1561
|
+
say_wizard "recipe installing RSpec"
|
1562
|
+
generate 'rspec:install'
|
1563
|
+
copy_from_repo 'spec/spec_helper.rb', :repo => 'https://raw.github.com/RailsApps/rails3-devise-rspec-cucumber/master/'
|
1564
|
+
generate 'email_spec:steps' if prefer :integration, 'cucumber'
|
1565
|
+
inject_into_file 'spec/spec_helper.rb', "require 'email_spec'\n", :after => "require 'rspec/rails'\n"
|
1566
|
+
inject_into_file 'spec/spec_helper.rb', :after => "RSpec.configure do |config|\n" do <<-RUBY
|
1567
|
+
config.include(EmailSpec::Helpers)
|
1568
|
+
config.include(EmailSpec::Matchers)
|
1569
|
+
RUBY
|
1570
|
+
end
|
1571
|
+
run 'rm -rf test/' # Removing test folder (not needed for RSpec)
|
1572
|
+
inject_into_file 'config/application.rb', :after => "Rails::Application\n" do <<-RUBY
|
1573
|
+
|
1574
|
+
# don't generate RSpec tests for views and helpers
|
1575
|
+
config.generators do |g|
|
1576
|
+
#{"g.test_framework :rspec" if prefer :fixtures, 'none'}
|
1577
|
+
#{"g.test_framework :rspec, fixture: true" unless prefer :fixtures, 'none'}
|
1578
|
+
#{"g.fixture_replacement :factory_girl, dir: 'spec/factories'" if prefer :fixtures, 'factory_girl'}
|
1579
|
+
#{"g.fixture_replacement :machinist" if prefer :fixtures, 'machinist'}
|
1580
|
+
#{"g.fixture_replacement :fabrication" if prefer :fixtures, 'fabrication'}
|
1581
|
+
g.view_specs false
|
1582
|
+
g.helper_specs false
|
1583
|
+
end
|
1584
|
+
|
1585
|
+
RUBY
|
1586
|
+
end
|
1587
|
+
## RSPEC AND MONGOID
|
1588
|
+
if prefer :orm, 'mongoid'
|
1589
|
+
# remove ActiveRecord artifacts
|
1590
|
+
gsub_file 'spec/spec_helper.rb', /config.fixture_path/, '# config.fixture_path'
|
1591
|
+
gsub_file 'spec/spec_helper.rb', /config.use_transactional_fixtures/, '# config.use_transactional_fixtures'
|
1592
|
+
# remove either possible occurrence of "require rails/test_unit/railtie"
|
1593
|
+
gsub_file 'config/application.rb', /require 'rails\/test_unit\/railtie'/, '# require "rails/test_unit/railtie"'
|
1594
|
+
gsub_file 'config/application.rb', /require "rails\/test_unit\/railtie"/, '# require "rails/test_unit/railtie"'
|
1595
|
+
# configure RSpec to use matchers from the mongoid-rspec gem
|
1596
|
+
create_file 'spec/support/mongoid.rb' do
|
1597
|
+
<<-RUBY
|
1598
|
+
RSpec.configure do |config|
|
1599
|
+
config.include Mongoid::Matchers
|
1600
|
+
end
|
1601
|
+
RUBY
|
1602
|
+
end
|
1603
|
+
end
|
1604
|
+
## RSPEC AND DEVISE
|
1605
|
+
if prefer :authentication, 'devise'
|
1606
|
+
# add Devise test helpers
|
1607
|
+
create_file 'spec/support/devise.rb' do
|
1608
|
+
<<-RUBY
|
1609
|
+
RSpec.configure do |config|
|
1610
|
+
config.include Devise::TestHelpers, :type => :controller
|
1611
|
+
end
|
1612
|
+
RUBY
|
1613
|
+
end
|
1614
|
+
end
|
1615
|
+
end
|
1616
|
+
### CUCUMBER ###
|
1617
|
+
if prefer :integration, 'cucumber'
|
1618
|
+
say_wizard "recipe installing Cucumber"
|
1619
|
+
generate "cucumber:install --capybara#{' --rspec' if prefer :unit_test, 'rspec'}#{' -D' if prefer :orm, 'mongoid'}"
|
1620
|
+
# make it easy to run Cucumber for single features without adding "--require features" to the command line
|
1621
|
+
gsub_file 'config/cucumber.yml', /std_opts = "/, 'std_opts = "-r features/support/ -r features/step_definitions '
|
1622
|
+
create_file 'features/support/email_spec.rb' do <<-RUBY
|
1623
|
+
require 'email_spec/cucumber'
|
1624
|
+
RUBY
|
1625
|
+
end
|
1626
|
+
## CUCUMBER AND MONGOID
|
1627
|
+
if prefer :orm, 'mongoid'
|
1628
|
+
gsub_file 'features/support/env.rb', /transaction/, "truncation"
|
1629
|
+
inject_into_file 'features/support/env.rb', :after => 'begin' do
|
1630
|
+
"\n DatabaseCleaner.orm = 'mongoid'"
|
1631
|
+
end
|
1632
|
+
end
|
1633
|
+
generate 'fabrication:cucumber_steps' if prefer :fixtures, 'fabrication'
|
1634
|
+
end
|
1635
|
+
## TURNIP
|
1636
|
+
if prefer :integration, 'turnip'
|
1637
|
+
append_file '.rspec', '-r turnip/rspec'
|
1638
|
+
inject_into_file 'spec/spec_helper.rb', "require 'turnip/capybara'\n", :after => "require 'rspec/rails'\n"
|
1639
|
+
create_file 'spec/acceptance/steps/.gitkeep'
|
1640
|
+
end
|
1641
|
+
## FIXTURE REPLACEMENTS
|
1642
|
+
if prefer :fixtures, 'machinist'
|
1643
|
+
say_wizard "generating blueprints file for 'machinist'"
|
1644
|
+
generate 'machinist:install'
|
1645
|
+
end
|
1646
|
+
### GUARD
|
1647
|
+
if prefer :continuous_testing, 'guard'
|
1648
|
+
say_wizard "recipe initializing Guard"
|
1649
|
+
run 'bundle exec guard init'
|
1650
|
+
end
|
1651
|
+
### GIT ###
|
1652
|
+
git :add => '-A' if prefer :git, true
|
1653
|
+
git :commit => '-qm "rails_apps_composer: testing framework"' if prefer :git, true
|
1654
|
+
end # after_bundler
|
1655
|
+
|
1656
|
+
after_everything do
|
1657
|
+
say_wizard "recipe running after everything"
|
1658
|
+
### RSPEC ###
|
1659
|
+
if prefer :unit_test, 'rspec'
|
1660
|
+
if (prefer :authentication, 'devise') && (prefer :starter_app, 'users_app')
|
1661
|
+
say_wizard "copying RSpec files from the rails3-devise-rspec-cucumber examples"
|
1662
|
+
repo = 'https://raw.github.com/RailsApps/rails3-devise-rspec-cucumber/master/'
|
1663
|
+
copy_from_repo 'spec/factories/users.rb', :repo => repo
|
1664
|
+
gsub_file 'spec/factories/users.rb', /# confirmed_at/, "confirmed_at" if (prefer :devise_modules, 'confirmable') || (prefer :devise_modules, 'invitable')
|
1665
|
+
copy_from_repo 'spec/controllers/home_controller_spec.rb', :repo => repo
|
1666
|
+
copy_from_repo 'spec/controllers/users_controller_spec.rb', :repo => repo
|
1667
|
+
copy_from_repo 'spec/models/user_spec.rb', :repo => repo
|
1668
|
+
remove_file 'spec/views/home/index.html.erb_spec.rb'
|
1669
|
+
remove_file 'spec/views/home/index.html.haml_spec.rb'
|
1670
|
+
remove_file 'spec/views/users/show.html.erb_spec.rb'
|
1671
|
+
remove_file 'spec/views/users/show.html.haml_spec.rb'
|
1672
|
+
remove_file 'spec/helpers/home_helper_spec.rb'
|
1673
|
+
remove_file 'spec/helpers/users_helper_spec.rb'
|
1674
|
+
end
|
1675
|
+
if (prefer :authentication, 'devise') && (prefer :starter_app, 'admin_app')
|
1676
|
+
say_wizard "copying RSpec files from the rails3-bootstrap-devise-cancan examples"
|
1677
|
+
repo = 'https://raw.github.com/RailsApps/rails3-bootstrap-devise-cancan/master/'
|
1678
|
+
copy_from_repo 'spec/factories/users.rb', :repo => repo
|
1679
|
+
gsub_file 'spec/factories/users.rb', /# confirmed_at/, "confirmed_at" if (prefer :devise_modules, 'confirmable') || (prefer :devise_modules, 'invitable')
|
1680
|
+
copy_from_repo 'spec/controllers/home_controller_spec.rb', :repo => repo
|
1681
|
+
copy_from_repo 'spec/controllers/users_controller_spec.rb', :repo => repo
|
1682
|
+
copy_from_repo 'spec/models/user_spec.rb', :repo => repo
|
1683
|
+
remove_file 'spec/views/home/index.html.erb_spec.rb'
|
1684
|
+
remove_file 'spec/views/home/index.html.haml_spec.rb'
|
1685
|
+
remove_file 'spec/views/users/show.html.erb_spec.rb'
|
1686
|
+
remove_file 'spec/views/users/show.html.haml_spec.rb'
|
1687
|
+
remove_file 'spec/helpers/home_helper_spec.rb'
|
1688
|
+
remove_file 'spec/helpers/users_helper_spec.rb'
|
1689
|
+
end
|
1690
|
+
## RSPEC AND OMNIAUTH
|
1691
|
+
if (prefer :authentication, 'omniauth') && (prefer :starter_app, 'users_app')
|
1692
|
+
say_wizard "copying RSpec files from the rails3-mongoid-omniauth examples"
|
1693
|
+
repo = 'https://raw.github.com/RailsApps/rails3-mongoid-omniauth/master/'
|
1694
|
+
copy_from_repo 'spec/factories/users.rb', :repo => repo
|
1695
|
+
copy_from_repo 'spec/controllers/sessions_controller_spec.rb', :repo => repo
|
1696
|
+
copy_from_repo 'spec/controllers/home_controller_spec.rb', :repo => repo
|
1697
|
+
copy_from_repo 'spec/controllers/users_controller_spec.rb', :repo => repo
|
1698
|
+
copy_from_repo 'spec/models/user_spec.rb', :repo => repo
|
1699
|
+
end
|
1700
|
+
## SUBDOMAINS
|
1701
|
+
if (prefer :authentication, 'devise') && (prefer :starter_app, 'subdomains_app')
|
1702
|
+
say_wizard "copying RSpec files from the rails3-subdomains examples"
|
1703
|
+
repo = 'https://raw.github.com/RailsApps/rails3-subdomains/master/'
|
1704
|
+
copy_from_repo 'spec/factories/users.rb', :repo => repo
|
1705
|
+
copy_from_repo 'spec/controllers/home_controller_spec.rb', :repo => repo
|
1706
|
+
copy_from_repo 'spec/controllers/users_controller_spec.rb', :repo => repo
|
1707
|
+
copy_from_repo 'spec/models/user_spec.rb', :repo => repo
|
1708
|
+
end
|
1709
|
+
## GIT
|
1710
|
+
git :add => '-A' if prefer :git, true
|
1711
|
+
git :commit => '-qm "rails_apps_composer: rspec files"' if prefer :git, true
|
1712
|
+
end
|
1713
|
+
### CUCUMBER ###
|
1714
|
+
if prefer :integration, 'cucumber'
|
1715
|
+
## CUCUMBER AND DEVISE (USERS APP)
|
1716
|
+
if (prefer :authentication, 'devise') && (prefer :starter_app, 'users_app')
|
1717
|
+
say_wizard "copying Cucumber scenarios from the rails3-devise-rspec-cucumber examples"
|
1718
|
+
repo = 'https://raw.github.com/RailsApps/rails3-devise-rspec-cucumber/master/'
|
1719
|
+
copy_from_repo 'spec/controllers/home_controller_spec.rb', :repo => repo
|
1720
|
+
copy_from_repo 'features/users/sign_in.feature', :repo => repo
|
1721
|
+
copy_from_repo 'features/users/sign_out.feature', :repo => repo
|
1722
|
+
copy_from_repo 'features/users/sign_up.feature', :repo => repo
|
1723
|
+
copy_from_repo 'features/users/user_edit.feature', :repo => repo
|
1724
|
+
copy_from_repo 'features/users/user_show.feature', :repo => repo
|
1725
|
+
copy_from_repo 'features/step_definitions/user_steps.rb', :repo => repo
|
1726
|
+
copy_from_repo 'features/support/paths.rb', :repo => repo
|
1727
|
+
if (prefer :devise_modules, 'confirmable') || (prefer :devise_modules, 'invitable')
|
1728
|
+
gsub_file 'features/step_definitions/user_steps.rb', /Welcome! You have signed up successfully./, "A message with a confirmation link has been sent to your email address."
|
1729
|
+
inject_into_file 'features/users/sign_in.feature', :before => ' Scenario: User signs in successfully' do
|
1730
|
+
<<-RUBY
|
1731
|
+
Scenario: User has not confirmed account
|
1732
|
+
Given I exist as an unconfirmed user
|
1733
|
+
And I am not logged in
|
1734
|
+
When I sign in with valid credentials
|
1735
|
+
Then I see an unconfirmed account message
|
1736
|
+
And I should be signed out
|
1737
|
+
RUBY
|
1738
|
+
end
|
1739
|
+
end
|
1740
|
+
end
|
1741
|
+
## CUCUMBER AND DEVISE (ADMIN APP)
|
1742
|
+
if (prefer :authentication, 'devise') && (prefer :starter_app, 'admin_app')
|
1743
|
+
say_wizard "copying Cucumber scenarios from the rails3-bootstrap-devise-cancan examples"
|
1744
|
+
repo = 'https://raw.github.com/RailsApps/rails3-bootstrap-devise-cancan/master/'
|
1745
|
+
copy_from_repo 'spec/controllers/home_controller_spec.rb', :repo => repo
|
1746
|
+
copy_from_repo 'features/users/sign_in.feature', :repo => repo
|
1747
|
+
copy_from_repo 'features/users/sign_out.feature', :repo => repo
|
1748
|
+
copy_from_repo 'features/users/sign_up.feature', :repo => repo
|
1749
|
+
copy_from_repo 'features/users/user_edit.feature', :repo => repo
|
1750
|
+
copy_from_repo 'features/users/user_show.feature', :repo => repo
|
1751
|
+
copy_from_repo 'features/step_definitions/user_steps.rb', :repo => repo
|
1752
|
+
copy_from_repo 'features/support/paths.rb', :repo => repo
|
1753
|
+
if (prefer :devise_modules, 'confirmable') || (prefer :devise_modules, 'invitable')
|
1754
|
+
gsub_file 'features/step_definitions/user_steps.rb', /Welcome! You have signed up successfully./, "A message with a confirmation link has been sent to your email address."
|
1755
|
+
inject_into_file 'features/users/sign_in.feature', :before => ' Scenario: User signs in successfully' do
|
1756
|
+
<<-RUBY
|
1757
|
+
Scenario: User has not confirmed account
|
1758
|
+
Given I exist as an unconfirmed user
|
1759
|
+
And I am not logged in
|
1760
|
+
When I sign in with valid credentials
|
1761
|
+
Then I see an unconfirmed account message
|
1762
|
+
And I should be signed out
|
1763
|
+
RUBY
|
1764
|
+
end
|
1765
|
+
end
|
1766
|
+
end
|
1767
|
+
## CUCUMBER AND DEVISE (SUBDOMAINS APP)
|
1768
|
+
if (prefer :authentication, 'devise') && (prefer :starter_app, 'subdomains_app')
|
1769
|
+
say_wizard "copying RSpec files from the rails3-subdomains examples"
|
1770
|
+
repo = 'https://raw.github.com/RailsApps/rails3-subdomains/master/'
|
1771
|
+
copy_from_repo 'features/users/sign_in.feature', :repo => repo
|
1772
|
+
copy_from_repo 'features/users/sign_out.feature', :repo => repo
|
1773
|
+
copy_from_repo 'features/users/sign_up.feature', :repo => repo
|
1774
|
+
copy_from_repo 'features/users/user_edit.feature', :repo => repo
|
1775
|
+
copy_from_repo 'features/users/user_show.feature', :repo => repo
|
1776
|
+
copy_from_repo 'features/step_definitions/user_steps.rb', :repo => repo
|
1777
|
+
copy_from_repo 'features/support/paths.rb', :repo => repo
|
1778
|
+
end
|
1779
|
+
## GIT
|
1780
|
+
git :add => '-A' if prefer :git, true
|
1781
|
+
git :commit => '-qm "rails_apps_composer: cucumber files"' if prefer :git, true
|
1782
|
+
end
|
1783
|
+
### FABRICATION ###
|
1784
|
+
if prefer :fixtures, 'fabrication'
|
1785
|
+
say_wizard "replacing FactoryGirl fixtures with Fabrication"
|
1786
|
+
remove_file 'spec/factories/users.rb'
|
1787
|
+
remove_file 'spec/fabricators/user_fabricator.rb'
|
1788
|
+
create_file 'spec/fabricators/user_fabricator.rb' do
|
1789
|
+
<<-RUBY
|
1790
|
+
Fabricator(:user) do
|
1791
|
+
name 'Test User'
|
1792
|
+
email 'example@example.com'
|
1793
|
+
password 'changeme'
|
1794
|
+
password_confirmation 'changeme'
|
1795
|
+
# required if the Devise Confirmable module is used
|
1796
|
+
# confirmed_at Time.now
|
1797
|
+
end
|
1798
|
+
RUBY
|
1799
|
+
end
|
1800
|
+
if prefer :integration, 'cucumber'
|
1801
|
+
gsub_file 'features/step_definitions/user_steps.rb', /@user = FactoryGirl.create\(:user, email: @visitor\[:email\]\)/, '@user = Fabricate(:user, email: @visitor[:email])'
|
1802
|
+
end
|
1803
|
+
if File.exist?('spec/controllers/users_controller_spec.rb')
|
1804
|
+
gsub_file 'spec/controllers/users_controller_spec.rb', /@user = FactoryGirl.create\(:user\)/, '@user = Fabricate(:user)'
|
1805
|
+
end
|
1806
|
+
end
|
1807
|
+
end # after_everything
|
1808
|
+
# >--------------------------- recipes/testing.rb ----------------------------end<
|
1809
|
+
# >-------------------------- templates/recipe.erb ---------------------------end<
|
1810
|
+
|
1811
|
+
# >-------------------------- templates/recipe.erb ---------------------------start<
|
1812
|
+
# >---------------------------------[ init ]----------------------------------<
|
1813
|
+
@current_recipe = "init"
|
1814
|
+
@before_configs["init"].call if @before_configs["init"]
|
1815
|
+
say_recipe 'init'
|
1816
|
+
@configs[@current_recipe] = config
|
1817
|
+
# >----------------------------- recipes/init.rb -----------------------------start<
|
1818
|
+
|
1819
|
+
# Application template recipe for the rails_apps_composer. Change the recipe here:
|
1820
|
+
# https://github.com/RailsApps/rails_apps_composer/blob/master/recipes/init.rb
|
1821
|
+
|
1822
|
+
after_everything do
|
1823
|
+
say_wizard "recipe running after everything"
|
1824
|
+
### CONFIGURATION FILE ###
|
1825
|
+
## EMAIL
|
1826
|
+
case prefs[:email]
|
1827
|
+
when 'none'
|
1828
|
+
credentials = ''
|
1829
|
+
when 'smtp'
|
1830
|
+
credentials = ''
|
1831
|
+
when 'gmail'
|
1832
|
+
credentials = "GMAIL_USERNAME: Your_Username\nGMAIL_PASSWORD: Your_Password\n"
|
1833
|
+
when 'sendgrid'
|
1834
|
+
credentials = "SENDGRID_USERNAME: Your_Username\nSENDGRID_PASSWORD: Your_Password\n"
|
1835
|
+
when 'mandrill'
|
1836
|
+
credentials = "MANDRILL_USERNAME: Your_Username\nMANDRILL_APIKEY: Your_API_Key\n"
|
1837
|
+
end
|
1838
|
+
append_file 'config/application.yml', credentials if prefer :local_env_file, 'figaro' and not rails_4_1?
|
1839
|
+
append_file '.env', credentials.gsub(': ', '=') if prefer :local_env_file, 'foreman'
|
1840
|
+
if prefer :local_env_file, 'figaro' and not rails_4_1?
|
1841
|
+
## DEFAULT USER
|
1842
|
+
unless prefer :starter_app, false
|
1843
|
+
append_file 'config/application.yml' do <<-FILE
|
1844
|
+
ADMIN_NAME: First User
|
1845
|
+
ADMIN_EMAIL: user@example.com
|
1846
|
+
ADMIN_PASSWORD: changeme
|
1847
|
+
FILE
|
1848
|
+
end
|
1849
|
+
end
|
1850
|
+
## AUTHENTICATION
|
1851
|
+
if prefer :authentication, 'omniauth'
|
1852
|
+
append_file 'config/application.yml' do <<-FILE
|
1853
|
+
OMNIAUTH_PROVIDER_KEY: Your_OmniAuth_Provider_Key
|
1854
|
+
OMNIAUTH_PROVIDER_SECRET: Your_OmniAuth_Provider_Secret
|
1855
|
+
FILE
|
1856
|
+
end
|
1857
|
+
end
|
1858
|
+
## AUTHORIZATION
|
1859
|
+
if (prefer :authorization, 'cancan')
|
1860
|
+
append_file 'config/application.yml', "ROLES: [admin, user, VIP]\n"
|
1861
|
+
end
|
1862
|
+
elsif prefer :local_env_file, 'foreman'
|
1863
|
+
## DEFAULT USER
|
1864
|
+
unless prefer :starter_app, false
|
1865
|
+
append_file '.env' do <<-FILE
|
1866
|
+
ADMIN_NAME=First User
|
1867
|
+
ADMIN_EMAIL=user@example.com
|
1868
|
+
ADMIN_PASSWORD=changeme
|
1869
|
+
FILE
|
1870
|
+
end
|
1871
|
+
end
|
1872
|
+
## AUTHENTICATION
|
1873
|
+
if prefer :authentication, 'omniauth'
|
1874
|
+
append_file '.env' do <<-FILE
|
1875
|
+
OMNIAUTH_PROVIDER_KEY=Your_OmniAuth_Provider_Key
|
1876
|
+
OMNIAUTH_PROVIDER_SECRET=Your_OmniAuth_Provider_Secret
|
1877
|
+
FILE
|
1878
|
+
end
|
1879
|
+
end
|
1880
|
+
## AUTHORIZATION
|
1881
|
+
if (prefer :authorization, 'cancan')
|
1882
|
+
append_file '.env', "ROLES=[admin, user, VIP]\n"
|
1883
|
+
end
|
1884
|
+
end
|
1885
|
+
### SUBDOMAINS ###
|
1886
|
+
copy_from_repo 'config/application.yml', :repo => 'https://raw.github.com/RailsApps/rails3-subdomains/master/' if prefer :starter_app, 'subdomains_app'
|
1887
|
+
### APPLICATION.EXAMPLE.YML ###
|
1888
|
+
if prefer :local_env_file, 'figaro' and not rails_4_1?
|
1889
|
+
copy_file destination_root + '/config/application.yml', destination_root + '/config/application.example.yml'
|
1890
|
+
elsif prefer :local_env_file, 'foreman'
|
1891
|
+
copy_file destination_root + '/.env', destination_root + '/.env.example'
|
1892
|
+
end
|
1893
|
+
### DATABASE SEED ###
|
1894
|
+
if prefer :local_env_file, 'figaro' and not rails_4_1?
|
1895
|
+
append_file 'db/seeds.rb' do <<-FILE
|
1896
|
+
# Environment variables (ENV['...']) can be set in the file config/application.yml.
|
1897
|
+
# See http://railsapps.github.io/rails-environment-variables.html
|
1898
|
+
FILE
|
1899
|
+
end
|
1900
|
+
elsif prefer :local_env_file, 'foreman'
|
1901
|
+
append_file 'db/seeds.rb' do <<-FILE
|
1902
|
+
# Environment variables (ENV['...']) can be set in the file .env file.
|
1903
|
+
FILE
|
1904
|
+
end
|
1905
|
+
end
|
1906
|
+
if (prefer :authorization, 'cancan')
|
1907
|
+
unless prefer :orm, 'mongoid'
|
1908
|
+
append_file 'db/seeds.rb' do <<-FILE
|
1909
|
+
puts 'ROLES'
|
1910
|
+
YAML.load(ENV['ROLES']).each do |role|
|
1911
|
+
Role.find_or_create_by_name({ :name => role }, :without_protection => true)
|
1912
|
+
puts 'role: ' << role
|
1913
|
+
end
|
1914
|
+
FILE
|
1915
|
+
end
|
1916
|
+
## Fix db seed for Rails 4.0
|
1917
|
+
gsub_file 'db/seeds.rb', /{ :name => role }, :without_protection => true/, 'role' if rails_4?
|
1918
|
+
else
|
1919
|
+
append_file 'db/seeds.rb' do <<-FILE
|
1920
|
+
puts 'ROLES'
|
1921
|
+
YAML.load(ENV['ROLES']).each do |role|
|
1922
|
+
Role.mongo_session['roles'].insert({ :name => role })
|
1923
|
+
puts 'role: ' << role
|
1924
|
+
end
|
1925
|
+
FILE
|
1926
|
+
end
|
1927
|
+
end
|
1928
|
+
end
|
1929
|
+
## DEVISE-DEFAULT
|
1930
|
+
if (prefer :authentication, 'devise') and (not prefer :apps4, 'rails-devise')
|
1931
|
+
append_file 'db/seeds.rb' do <<-FILE
|
1932
|
+
puts 'DEFAULT USERS'
|
1933
|
+
user = User.find_or_create_by_email :name => ENV['ADMIN_NAME'].dup, :email => ENV['ADMIN_EMAIL'].dup, :password => ENV['ADMIN_PASSWORD'].dup, :password_confirmation => ENV['ADMIN_PASSWORD'].dup
|
1934
|
+
puts 'user: ' << user.name
|
1935
|
+
FILE
|
1936
|
+
end
|
1937
|
+
# Mongoid doesn't have a 'find_or_create_by' method
|
1938
|
+
gsub_file 'db/seeds.rb', /find_or_create_by_email/, 'create!' if prefer :orm, 'mongoid'
|
1939
|
+
end
|
1940
|
+
if prefer :apps4, 'rails-devise'
|
1941
|
+
append_file 'db/seeds.rb' do <<-FILE
|
1942
|
+
puts 'DEFAULT USERS'
|
1943
|
+
user = User.find_or_create_by_email :email => ENV['ADMIN_EMAIL'].dup, :password => ENV['ADMIN_PASSWORD'].dup, :password_confirmation => ENV['ADMIN_PASSWORD'].dup
|
1944
|
+
puts 'user: ' << user.email
|
1945
|
+
FILE
|
1946
|
+
end
|
1947
|
+
# Mongoid doesn't have a 'find_or_create_by' method
|
1948
|
+
gsub_file 'db/seeds.rb', /find_or_create_by_email/, 'create!' if prefer :orm, 'mongoid'
|
1949
|
+
end
|
1950
|
+
## DEVISE-CONFIRMABLE
|
1951
|
+
if (prefer :devise_modules, 'confirmable') || (prefer :devise_modules, 'invitable')
|
1952
|
+
append_file 'db/seeds.rb', "user.confirm!\n"
|
1953
|
+
end
|
1954
|
+
if (prefer :authorization, 'cancan') && !(prefer :authentication, 'omniauth')
|
1955
|
+
append_file 'db/seeds.rb', 'user.add_role :admin'
|
1956
|
+
end
|
1957
|
+
## DEVISE-INVITABLE
|
1958
|
+
if prefer :devise_modules, 'invitable'
|
1959
|
+
if prefer :local_env_file, 'foreman'
|
1960
|
+
run 'foreman run bundle exec rake db:migrate'
|
1961
|
+
else
|
1962
|
+
run 'bundle exec rake db:migrate'
|
1963
|
+
end
|
1964
|
+
generate 'devise_invitable user'
|
1965
|
+
end
|
1966
|
+
### APPLY DATABASE SEED ###
|
1967
|
+
unless prefer :orm, 'mongoid'
|
1968
|
+
unless prefer :database, 'default'
|
1969
|
+
## ACTIVE_RECORD
|
1970
|
+
say_wizard "applying migrations and seeding the database"
|
1971
|
+
if prefer :local_env_file, 'foreman'
|
1972
|
+
run 'foreman run bundle exec rake db:migrate'
|
1973
|
+
run 'foreman run bundle exec rake db:test:prepare'
|
1974
|
+
else
|
1975
|
+
run 'bundle exec rake db:migrate'
|
1976
|
+
run 'bundle exec rake db:test:prepare'
|
1977
|
+
end
|
1978
|
+
end
|
1979
|
+
else
|
1980
|
+
## MONGOID
|
1981
|
+
say_wizard "dropping database, creating indexes and seeding the database"
|
1982
|
+
if prefer :local_env_file, 'foreman'
|
1983
|
+
run 'foreman run bundle exec rake db:drop'
|
1984
|
+
run 'foreman run bundle exec rake db:mongoid:create_indexes'
|
1985
|
+
else
|
1986
|
+
run 'bundle exec rake db:drop'
|
1987
|
+
run 'bundle exec rake db:mongoid:create_indexes'
|
1988
|
+
end
|
1989
|
+
end
|
1990
|
+
unless prefs[:skip_seeds]
|
1991
|
+
unless prefer :railsapps, 'rails-recurly-subscription-saas'
|
1992
|
+
if prefer :local_env_file, 'foreman'
|
1993
|
+
run 'foreman run bundle exec rake db:seed'
|
1994
|
+
else
|
1995
|
+
run 'bundle exec rake db:seed'
|
1996
|
+
end
|
1997
|
+
end
|
1998
|
+
end
|
1999
|
+
### GIT ###
|
2000
|
+
git :add => '-A' if prefer :git, true
|
2001
|
+
git :commit => '-qm "rails_apps_composer: set up database"' if prefer :git, true
|
2002
|
+
end # after_everything
|
2003
|
+
# >----------------------------- recipes/init.rb -----------------------------end<
|
2004
|
+
# >-------------------------- templates/recipe.erb ---------------------------end<
|
2005
|
+
|
2006
|
+
# >-------------------------- templates/recipe.erb ---------------------------start<
|
2007
|
+
# >---------------------------------[ apps4 ]---------------------------------<
|
2008
|
+
@current_recipe = "apps4"
|
2009
|
+
@before_configs["apps4"].call if @before_configs["apps4"]
|
2010
|
+
say_recipe 'apps4'
|
2011
|
+
@configs[@current_recipe] = config
|
2012
|
+
# >---------------------------- recipes/apps4.rb -----------------------------start<
|
2013
|
+
|
2014
|
+
# Application template recipe for the rails_apps_composer. Change the recipe here:
|
2015
|
+
# https://github.com/RailsApps/rails_apps_composer/blob/master/recipes/apps4.rb
|
2016
|
+
|
2017
|
+
### LEARN-RAILS ####
|
2018
|
+
|
2019
|
+
if prefer :apps4, 'learn-rails'
|
2020
|
+
|
2021
|
+
# >-------------------------------[ Gems ]--------------------------------<
|
2022
|
+
|
2023
|
+
add_gem 'activerecord-tableless'
|
2024
|
+
add_gem 'high_voltage'
|
2025
|
+
add_gem 'gibbon'
|
2026
|
+
add_gem 'google_drive'
|
2027
|
+
gsub_file 'Gemfile', /gem 'sqlite3'\n/, ''
|
2028
|
+
add_gem 'sqlite3', :group => :development
|
2029
|
+
add_gem 'pg', :group => :production
|
2030
|
+
add_gem 'thin', :group => :production
|
2031
|
+
add_gem 'rails_12factor', :group => :production
|
2032
|
+
|
2033
|
+
# >-------------------------------[ after_everything ]--------------------------------<
|
2034
|
+
|
2035
|
+
after_everything do
|
2036
|
+
say_wizard "recipe running after 'bundle install'"
|
2037
|
+
repo = 'https://raw.github.com/RailsApps/learn-rails/master/'
|
2038
|
+
|
2039
|
+
# >-------------------------------[ Clean up starter app ]--------------------------------<
|
2040
|
+
|
2041
|
+
# remove commented lines and multiple blank lines from Gemfile
|
2042
|
+
# thanks to https://github.com/perfectline/template-bucket/blob/master/cleanup.rb
|
2043
|
+
gsub_file 'Gemfile', /#.*\n/, "\n"
|
2044
|
+
gsub_file 'Gemfile', /\n^\s*\n/, "\n"
|
2045
|
+
# remove commented lines and multiple blank lines from config/routes.rb
|
2046
|
+
gsub_file 'config/routes.rb', / #.*\n/, "\n"
|
2047
|
+
gsub_file 'config/routes.rb', /\n^\s*\n/, "\n"
|
2048
|
+
# GIT
|
2049
|
+
git :add => '-A' if prefer :git, true
|
2050
|
+
git :commit => '-qm "rails_apps_composer: clean up starter app"' if prefer :git, true
|
2051
|
+
|
2052
|
+
# >-------------------------------[ Models ]--------------------------------<
|
2053
|
+
|
2054
|
+
copy_from_repo 'app/models/contact.rb', :repo => repo
|
2055
|
+
copy_from_repo 'app/models/visitor.rb', :repo => repo
|
2056
|
+
|
2057
|
+
# >-------------------------------[ Init ]--------------------------------<
|
2058
|
+
copy_from_repo 'config/application.yml', :repo => repo
|
2059
|
+
remove_file 'config/application.example.yml'
|
2060
|
+
copy_file destination_root + '/config/application.yml', destination_root + '/config/application.example.yml'
|
2061
|
+
|
2062
|
+
# >-------------------------------[ Controllers ]--------------------------------<
|
2063
|
+
|
2064
|
+
copy_from_repo 'app/controllers/contacts_controller.rb', :repo => repo
|
2065
|
+
copy_from_repo 'app/controllers/visitors_controller.rb', :repo => repo
|
2066
|
+
|
2067
|
+
# >-------------------------------[ Mailers ]--------------------------------<
|
2068
|
+
|
2069
|
+
generate 'mailer UserMailer'
|
2070
|
+
copy_from_repo 'app/mailers/user_mailer.rb', :repo => repo
|
2071
|
+
|
2072
|
+
# >-------------------------------[ Views ]--------------------------------<
|
2073
|
+
|
2074
|
+
copy_from_repo 'app/views/contacts/new.html.erb', :repo => repo
|
2075
|
+
copy_from_repo 'app/views/pages/about.html.erb', :repo => repo
|
2076
|
+
copy_from_repo 'app/views/user_mailer/contact_email.html.erb', :repo => repo
|
2077
|
+
copy_from_repo 'app/views/user_mailer/contact_email.text.erb', :repo => repo
|
2078
|
+
copy_from_repo 'app/views/visitors/new.html.erb', :repo => repo
|
2079
|
+
# create navigation links using the rails_layout gem
|
2080
|
+
generate 'layout:navigation -f'
|
2081
|
+
|
2082
|
+
# >-------------------------------[ Routes ]--------------------------------<
|
2083
|
+
|
2084
|
+
copy_from_repo 'config/routes.rb', :repo => repo
|
2085
|
+
### CORRECT APPLICATION NAME ###
|
2086
|
+
gsub_file 'config/routes.rb', /^.*.routes.draw do/, "#{app_const}.routes.draw do"
|
2087
|
+
|
2088
|
+
# >-------------------------------[ Assets ]--------------------------------<
|
2089
|
+
|
2090
|
+
copy_from_repo 'app/assets/javascripts/segmentio.js', :repo => repo
|
2091
|
+
|
2092
|
+
### GIT ###
|
2093
|
+
git :add => '-A' if prefer :git, true
|
2094
|
+
git :commit => '-qm "rails_apps_composer: learn-rails app"' if prefer :git, true
|
2095
|
+
end # after_bundler
|
2096
|
+
end # learn-rails
|
2097
|
+
|
2098
|
+
### RAILS-BOOTSTRAP or RAILS-FOUNDATION ####
|
2099
|
+
|
2100
|
+
if (prefer :apps4, 'rails-bootstrap') || (prefer :apps4, 'rails-foundation')
|
2101
|
+
|
2102
|
+
# >-------------------------------[ Gems ]--------------------------------<
|
2103
|
+
|
2104
|
+
add_gem 'high_voltage'
|
2105
|
+
|
2106
|
+
# >-------------------------------[ after_everything ]--------------------------------<
|
2107
|
+
|
2108
|
+
after_everything do
|
2109
|
+
say_wizard "recipe running after 'bundle install'"
|
2110
|
+
repo = 'https://raw.github.com/RailsApps/rails-bootstrap/master/' if prefer :apps4, 'rails-bootstrap'
|
2111
|
+
repo = 'https://raw.github.com/RailsApps/rails-foundation/master/' if prefer :apps4, 'rails-foundation'
|
2112
|
+
|
2113
|
+
# >-------------------------------[ Clean up starter app ]--------------------------------<
|
2114
|
+
|
2115
|
+
# remove commented lines and multiple blank lines from Gemfile
|
2116
|
+
# thanks to https://github.com/perfectline/template-bucket/blob/master/cleanup.rb
|
2117
|
+
gsub_file 'Gemfile', /#.*\n/, "\n"
|
2118
|
+
gsub_file 'Gemfile', /\n^\s*\n/, "\n"
|
2119
|
+
# remove commented lines and multiple blank lines from config/routes.rb
|
2120
|
+
gsub_file 'config/routes.rb', / #.*\n/, "\n"
|
2121
|
+
gsub_file 'config/routes.rb', /\n^\s*\n/, "\n"
|
2122
|
+
# GIT
|
2123
|
+
git :add => '-A' if prefer :git, true
|
2124
|
+
git :commit => '-qm "rails_apps_composer: clean up starter app"' if prefer :git, true
|
2125
|
+
|
2126
|
+
# >-------------------------------[ Models ]--------------------------------<
|
2127
|
+
|
2128
|
+
# no models
|
2129
|
+
|
2130
|
+
# >-------------------------------[ Init ]--------------------------------<
|
2131
|
+
copy_from_repo 'config/application.yml', :repo => repo
|
2132
|
+
remove_file 'config/application.example.yml'
|
2133
|
+
copy_file destination_root + '/config/application.yml', destination_root + '/config/application.example.yml'
|
2134
|
+
|
2135
|
+
# >-------------------------------[ Controllers ]--------------------------------<
|
2136
|
+
|
2137
|
+
copy_from_repo 'app/controllers/visitors_controller.rb', :repo => repo
|
2138
|
+
|
2139
|
+
# >-------------------------------[ Views ]--------------------------------<
|
2140
|
+
|
2141
|
+
copy_from_repo 'app/views/pages/about.html.erb', :repo => repo
|
2142
|
+
copy_from_repo 'app/views/visitors/new.html.erb', :repo => repo
|
2143
|
+
# create navigation links using the rails_layout gem
|
2144
|
+
generate 'layout:navigation -f'
|
2145
|
+
|
2146
|
+
# >-------------------------------[ Routes ]--------------------------------<
|
2147
|
+
|
2148
|
+
copy_from_repo 'config/routes.rb', :repo => repo
|
2149
|
+
### CORRECT APPLICATION NAME ###
|
2150
|
+
gsub_file 'config/routes.rb', /^.*.routes.draw do/, "#{app_const}.routes.draw do"
|
2151
|
+
|
2152
|
+
# >-------------------------------[ Assets ]--------------------------------<
|
2153
|
+
|
2154
|
+
# no assets
|
2155
|
+
|
2156
|
+
### GIT ###
|
2157
|
+
if prefer :git, true
|
2158
|
+
git :add => '-A'
|
2159
|
+
git :commit => '-qm "rails_apps_composer: rails-bootstrap app"' if prefer :apps4, 'rails-bootstrap'
|
2160
|
+
git :commit => '-qm "rails_apps_composer: rails-foundation app"' if prefer :apps4, 'rails-foundation'
|
2161
|
+
end
|
2162
|
+
end # after_bundler
|
2163
|
+
end # rails-bootstrap
|
2164
|
+
|
2165
|
+
### RAILS-DEVISE ####
|
2166
|
+
|
2167
|
+
if prefer :apps4, 'rails-devise'
|
2168
|
+
|
2169
|
+
# >-------------------------------[ after_bundler ]--------------------------------<
|
2170
|
+
|
2171
|
+
after_bundler do
|
2172
|
+
say_wizard "recipe running after 'bundle install'"
|
2173
|
+
repo = 'https://raw.github.com/RailsApps/rails-devise/master/'
|
2174
|
+
|
2175
|
+
# >-------------------------------[ Init ]--------------------------------<
|
2176
|
+
|
2177
|
+
copy_from_repo 'config/application.yml', :repo => repo
|
2178
|
+
remove_file 'config/application.example.yml'
|
2179
|
+
copy_file destination_root + '/config/application.yml', destination_root + '/config/application.example.yml'
|
2180
|
+
|
2181
|
+
# >-------------------------------[ Controllers ]--------------------------------<
|
2182
|
+
|
2183
|
+
copy_from_repo 'app/controllers/home_controller.rb', :repo => repo
|
2184
|
+
copy_from_repo 'app/controllers/users_controller.rb', :repo => repo
|
2185
|
+
copy_from_repo 'app/controllers/registrations_controller.rb', :repo => repo
|
2186
|
+
|
2187
|
+
# >-------------------------------[ Views ]--------------------------------<
|
2188
|
+
|
2189
|
+
copy_from_repo 'app/views/home/index.html.erb', :repo => repo
|
2190
|
+
copy_from_repo 'app/views/users/index.html.erb', :repo => repo
|
2191
|
+
copy_from_repo 'app/views/users/show.html.erb', :repo => repo
|
2192
|
+
|
2193
|
+
# >-------------------------------[ Routes ]--------------------------------<
|
2194
|
+
|
2195
|
+
copy_from_repo 'config/routes.rb', :repo => repo
|
2196
|
+
### CORRECT APPLICATION NAME ###
|
2197
|
+
gsub_file 'config/routes.rb', /^.*.routes.draw do/, "#{app_const}.routes.draw do"
|
2198
|
+
|
2199
|
+
end
|
2200
|
+
|
2201
|
+
# >-------------------------------[ after_everything ]--------------------------------<
|
2202
|
+
|
2203
|
+
after_everything do
|
2204
|
+
say_wizard "recipe running after 'bundle install'"
|
2205
|
+
|
2206
|
+
# >-------------------------------[ Clean up starter app ]--------------------------------<
|
2207
|
+
|
2208
|
+
# remove commented lines and multiple blank lines from Gemfile
|
2209
|
+
# thanks to https://github.com/perfectline/template-bucket/blob/master/cleanup.rb
|
2210
|
+
gsub_file 'Gemfile', /#.*\n/, "\n"
|
2211
|
+
gsub_file 'Gemfile', /\n^\s*\n/, "\n"
|
2212
|
+
# remove commented lines and multiple blank lines from config/routes.rb
|
2213
|
+
gsub_file 'config/routes.rb', / #.*\n/, "\n"
|
2214
|
+
gsub_file 'config/routes.rb', /\n^\s*\n/, "\n"
|
2215
|
+
# GIT
|
2216
|
+
git :add => '-A' if prefer :git, true
|
2217
|
+
git :commit => '-qm "rails_apps_composer: clean up starter app"' if prefer :git, true
|
2218
|
+
|
2219
|
+
### GIT ###
|
2220
|
+
git :add => '-A' if prefer :git, true
|
2221
|
+
git :commit => '-qm "rails_apps_composer: learn-rails app"' if prefer :git, true
|
2222
|
+
|
2223
|
+
end # after_bundler
|
2224
|
+
end # rails-devise
|
2225
|
+
|
2226
|
+
### RAILS-OMNIAUTH ####
|
2227
|
+
|
2228
|
+
if prefer :apps4, 'rails-omniauth'
|
2229
|
+
|
2230
|
+
# >-------------------------------[ after_bundler ]--------------------------------<
|
2231
|
+
|
2232
|
+
after_bundler do
|
2233
|
+
say_wizard "recipe running after 'bundle install'"
|
2234
|
+
repo = 'https://raw.github.com/RailsApps/rails-omniauth/master/'
|
2235
|
+
|
2236
|
+
# >-------------------------------[ Init ]--------------------------------<
|
2237
|
+
|
2238
|
+
copy_from_repo 'config/application.yml', :repo => repo
|
2239
|
+
remove_file 'config/application.example.yml'
|
2240
|
+
copy_file destination_root + '/config/application.yml', destination_root + '/config/application.example.yml'
|
2241
|
+
|
2242
|
+
# >-------------------------------[ Models ]--------------------------------<
|
2243
|
+
|
2244
|
+
copy_from_repo 'app/models/user.rb', :repo => repo
|
2245
|
+
|
2246
|
+
# >-------------------------------[ Controllers ]--------------------------------<
|
2247
|
+
|
2248
|
+
copy_from_repo 'app/controllers/home_controller.rb', :repo => repo
|
2249
|
+
copy_from_repo 'app/controllers/sessions_controller.rb', :repo => repo
|
2250
|
+
gsub_file 'app/controllers/sessions_controller.rb', /twitter/, prefs[:omniauth_provider]
|
2251
|
+
copy_from_repo 'app/controllers/users_controller.rb', :repo => repo
|
2252
|
+
|
2253
|
+
# >-------------------------------[ Views ]--------------------------------<
|
2254
|
+
|
2255
|
+
copy_from_repo 'app/views/home/index.html.erb', :repo => repo
|
2256
|
+
copy_from_repo 'app/views/users/edit.html.erb', :repo => repo
|
2257
|
+
copy_from_repo 'app/views/users/index.html.erb', :repo => repo
|
2258
|
+
copy_from_repo 'app/views/users/show.html.erb', :repo => repo
|
2259
|
+
|
2260
|
+
# >-------------------------------[ Routes ]--------------------------------<
|
2261
|
+
|
2262
|
+
copy_from_repo 'config/routes.rb', :repo => repo
|
2263
|
+
### CORRECT APPLICATION NAME ###
|
2264
|
+
gsub_file 'config/routes.rb', /^.*.routes.draw do/, "#{app_const}.routes.draw do"
|
2265
|
+
|
2266
|
+
end
|
2267
|
+
|
2268
|
+
# >-------------------------------[ after_everything ]--------------------------------<
|
2269
|
+
|
2270
|
+
after_everything do
|
2271
|
+
say_wizard "recipe running after 'bundle install'"
|
2272
|
+
|
2273
|
+
# >-------------------------------[ Clean up starter app ]--------------------------------<
|
2274
|
+
|
2275
|
+
# remove commented lines and multiple blank lines from Gemfile
|
2276
|
+
# thanks to https://github.com/perfectline/template-bucket/blob/master/cleanup.rb
|
2277
|
+
gsub_file 'Gemfile', /#.*\n/, "\n"
|
2278
|
+
gsub_file 'Gemfile', /\n^\s*\n/, "\n"
|
2279
|
+
# remove commented lines and multiple blank lines from config/routes.rb
|
2280
|
+
gsub_file 'config/routes.rb', / #.*\n/, "\n"
|
2281
|
+
gsub_file 'config/routes.rb', /\n^\s*\n/, "\n"
|
2282
|
+
# GIT
|
2283
|
+
git :add => '-A' if prefer :git, true
|
2284
|
+
git :commit => '-qm "rails_apps_composer: clean up starter app"' if prefer :git, true
|
2285
|
+
|
2286
|
+
### GIT ###
|
2287
|
+
git :add => '-A' if prefer :git, true
|
2288
|
+
git :commit => '-qm "rails_apps_composer: learn-rails app"' if prefer :git, true
|
2289
|
+
|
2290
|
+
end # after_bundler
|
2291
|
+
end # rails-omniauth
|
2292
|
+
# >---------------------------- recipes/apps4.rb -----------------------------end<
|
2293
|
+
# >-------------------------- templates/recipe.erb ---------------------------end<
|
2294
|
+
|
2295
|
+
# >-------------------------- templates/recipe.erb ---------------------------start<
|
2296
|
+
# >------------------------------[ controllers ]------------------------------<
|
2297
|
+
@current_recipe = "controllers"
|
2298
|
+
@before_configs["controllers"].call if @before_configs["controllers"]
|
2299
|
+
say_recipe 'controllers'
|
2300
|
+
@configs[@current_recipe] = config
|
2301
|
+
# >------------------------- recipes/controllers.rb --------------------------start<
|
2302
|
+
|
2303
|
+
# Application template recipe for the rails_apps_composer. Change the recipe here:
|
2304
|
+
# https://github.com/RailsApps/rails_apps_composer/blob/master/recipes/controllers.rb
|
2305
|
+
|
2306
|
+
after_bundler do
|
2307
|
+
say_wizard "recipe running after 'bundle install'"
|
2308
|
+
### APPLICATION_CONTROLLER ###
|
2309
|
+
if prefer :authentication, 'omniauth'
|
2310
|
+
copy_from_repo 'app/controllers/application_controller.rb', :repo => 'https://raw.github.com/RailsApps/rails-omniauth/master/'
|
2311
|
+
end
|
2312
|
+
if prefer :authorization, 'cancan'
|
2313
|
+
inject_into_file 'app/controllers/application_controller.rb', :before => "\nend" do <<-RUBY
|
2314
|
+
\n
|
2315
|
+
rescue_from CanCan::AccessDenied do |exception|
|
2316
|
+
redirect_to root_path, :alert => exception.message
|
2317
|
+
end
|
2318
|
+
RUBY
|
2319
|
+
end
|
2320
|
+
end
|
2321
|
+
### HOME_CONTROLLER ###
|
2322
|
+
if ['home_app','users_app','admin_app','subdomains_app'].include? prefs[:starter_app]
|
2323
|
+
generate(:controller, "home")
|
2324
|
+
end
|
2325
|
+
### USERS_CONTROLLER ###
|
2326
|
+
case prefs[:starter_app]
|
2327
|
+
when 'users_app'
|
2328
|
+
if (prefer :authentication, 'devise') and (not prefer :apps4, 'rails-devise')
|
2329
|
+
copy_from_repo 'app/controllers/users_controller.rb', :repo => 'https://raw.github.com/RailsApps/rails3-devise-rspec-cucumber/master/'
|
2330
|
+
elsif prefer :authentication, 'omniauth'
|
2331
|
+
if rails_4?
|
2332
|
+
copy_from_repo 'app/controllers/users_controller.rb', :repo => 'https://raw.github.com/RailsApps/rails-omniauth/master/'
|
2333
|
+
else
|
2334
|
+
copy_from_repo 'app/controllers/users_controller.rb', :repo => 'https://raw.github.com/RailsApps/rails3-mongoid-omniauth/master/'
|
2335
|
+
end
|
2336
|
+
end
|
2337
|
+
when 'admin_app'
|
2338
|
+
if (prefer :authentication, 'devise') and (not prefer :apps4, 'rails-devise')
|
2339
|
+
copy_from_repo 'app/controllers/users_controller.rb', :repo => 'https://raw.github.com/RailsApps/rails3-bootstrap-devise-cancan/master/'
|
2340
|
+
elsif prefer :authentication, 'omniauth'
|
2341
|
+
if rails_4?
|
2342
|
+
copy_from_repo 'app/controllers/users_controller.rb', :repo => 'https://raw.github.com/RailsApps/rails-omniauth/master/'
|
2343
|
+
else
|
2344
|
+
copy_from_repo 'app/controllers/users_controller.rb', :repo => 'https://raw.github.com/RailsApps/rails3-mongoid-omniauth/master/'
|
2345
|
+
end
|
2346
|
+
end
|
2347
|
+
when 'subdomains_app'
|
2348
|
+
copy_from_repo 'app/controllers/users_controller.rb', :repo => 'https://raw.github.com/RailsApps/rails3-subdomains/master/'
|
2349
|
+
end
|
2350
|
+
### REGISTRATIONS_CONTROLLER ###
|
2351
|
+
if rails_4?
|
2352
|
+
if ['users_app','admin_app','subdomains_app'].include? prefs[:starter_app]
|
2353
|
+
## accommodate strong parameters in Rails 4
|
2354
|
+
copy_from_repo 'app/controllers/registrations_controller-devise.rb', :prefs => 'devise'
|
2355
|
+
end
|
2356
|
+
end
|
2357
|
+
### SESSIONS_CONTROLLER ###
|
2358
|
+
if prefer :authentication, 'omniauth'
|
2359
|
+
filename = 'app/controllers/sessions_controller.rb'
|
2360
|
+
copy_from_repo filename, :repo => 'https://raw.github.com/RailsApps/rails-omniauth/master/'
|
2361
|
+
gsub_file filename, /twitter/, prefs[:omniauth_provider] unless prefer :omniauth_provider, 'twitter'
|
2362
|
+
if prefer :authorization, 'cancan'
|
2363
|
+
inject_into_file filename, " user.add_role :admin if User.count == 1 # make the first user an admin\n", :after => "session[:user_id] = user.id\n"
|
2364
|
+
end
|
2365
|
+
end
|
2366
|
+
### PROFILES_CONTROLLER ###
|
2367
|
+
copy_from_repo 'app/controllers/profiles_controller.rb', :repo => 'https://raw.github.com/RailsApps/rails3-subdomains/master/' if prefer :starter_app, 'subdomains_app'
|
2368
|
+
### GIT ###
|
2369
|
+
git :add => '-A' if prefer :git, true
|
2370
|
+
git :commit => '-qm "rails_apps_composer: controllers"' if prefer :git, true
|
2371
|
+
end # after_bundler
|
2372
|
+
# >------------------------- recipes/controllers.rb --------------------------end<
|
2373
|
+
# >-------------------------- templates/recipe.erb ---------------------------end<
|
2374
|
+
|
2375
|
+
# >-------------------------- templates/recipe.erb ---------------------------start<
|
2376
|
+
# >---------------------------------[ views ]---------------------------------<
|
2377
|
+
@current_recipe = "views"
|
2378
|
+
@before_configs["views"].call if @before_configs["views"]
|
2379
|
+
say_recipe 'views'
|
2380
|
+
@configs[@current_recipe] = config
|
2381
|
+
# >---------------------------- recipes/views.rb -----------------------------start<
|
2382
|
+
|
2383
|
+
# Application template recipe for the rails_apps_composer. Change the recipe here:
|
2384
|
+
# https://github.com/RailsApps/rails_apps_composer/blob/master/recipes/views.rb
|
2385
|
+
|
2386
|
+
after_bundler do
|
2387
|
+
say_wizard "recipe running after 'bundle install'"
|
2388
|
+
### DEVISE ###
|
2389
|
+
if (prefer :authentication, 'devise') and (not prefer :apps4, 'rails-devise')
|
2390
|
+
copy_from_repo 'app/views/devise/shared/_links.html.erb'
|
2391
|
+
unless prefer :form_builder, 'simple_form'
|
2392
|
+
copy_from_repo 'app/views/devise/registrations/edit.html.erb'
|
2393
|
+
copy_from_repo 'app/views/devise/registrations/new.html.erb'
|
2394
|
+
else
|
2395
|
+
copy_from_repo 'app/views/devise/registrations/edit-simple_form.html.erb', :prefs => 'simple_form'
|
2396
|
+
copy_from_repo 'app/views/devise/registrations/new-simple_form.html.erb', :prefs => 'simple_form'
|
2397
|
+
copy_from_repo 'app/views/devise/sessions/new-simple_form.html.erb', :prefs => 'simple_form'
|
2398
|
+
copy_from_repo 'app/helpers/application_helper-simple_form.rb', :prefs => 'simple_form'
|
2399
|
+
end
|
2400
|
+
end
|
2401
|
+
### HOME ###
|
2402
|
+
copy_from_repo 'app/views/home/index.html.erb' if prefer :starter_app, 'users_app'
|
2403
|
+
copy_from_repo 'app/views/home/index.html.erb' if prefer :starter_app, 'admin_app'
|
2404
|
+
copy_from_repo 'app/views/home/index-subdomains_app.html.erb', :prefs => 'subdomains_app'
|
2405
|
+
### USERS ###
|
2406
|
+
if ['users_app','admin_app','subdomains_app'].include? prefs[:starter_app]
|
2407
|
+
## INDEX
|
2408
|
+
if prefer :starter_app, 'admin_app'
|
2409
|
+
copy_from_repo 'app/views/users/index-admin_app.html.erb', :prefs => 'admin_app'
|
2410
|
+
unless prefer :form_builder, 'simple_form'
|
2411
|
+
copy_from_repo 'app/views/users/_user.html.erb'
|
2412
|
+
else
|
2413
|
+
copy_from_repo 'app/views/users/_user-simple_form.html.erb', :prefs => 'simple_form'
|
2414
|
+
end
|
2415
|
+
else
|
2416
|
+
copy_from_repo 'app/views/users/index.html.erb'
|
2417
|
+
end
|
2418
|
+
## SHOW
|
2419
|
+
copy_from_repo 'app/views/users/show.html.erb'
|
2420
|
+
copy_from_repo 'app/views/users/show-subdomains_app.html.erb', :prefs => 'subdomains_app'
|
2421
|
+
## EDIT
|
2422
|
+
copy_from_repo 'app/views/users/edit.html.erb', :repo => 'https://raw.github.com/RailsApps/rails-omniauth/master/'
|
2423
|
+
end
|
2424
|
+
### PROFILES ###
|
2425
|
+
copy_from_repo 'app/views/profiles/show-subdomains_app.html.erb', :prefs => 'subdomains_app'
|
2426
|
+
### GIT ###
|
2427
|
+
git :add => '-A' if prefer :git, true
|
2428
|
+
git :commit => '-qm "rails_apps_composer: views"' if prefer :git, true
|
2429
|
+
end # after_bundler
|
2430
|
+
# >---------------------------- recipes/views.rb -----------------------------end<
|
2431
|
+
# >-------------------------- templates/recipe.erb ---------------------------end<
|
2432
|
+
|
2433
|
+
# >-------------------------- templates/recipe.erb ---------------------------start<
|
2434
|
+
# >-------------------------------[ prelaunch ]-------------------------------<
|
2435
|
+
@current_recipe = "prelaunch"
|
2436
|
+
@before_configs["prelaunch"].call if @before_configs["prelaunch"]
|
2437
|
+
say_recipe 'prelaunch'
|
2438
|
+
@configs[@current_recipe] = config
|
2439
|
+
# >-------------------------- recipes/prelaunch.rb ---------------------------start<
|
2440
|
+
|
2441
|
+
# Application template recipe for the rails_apps_composer. Change the recipe here:
|
2442
|
+
# https://github.com/RailsApps/rails_apps_composer/blob/master/recipes/prelaunch.rb
|
2443
|
+
|
2444
|
+
if prefer :railsapps, 'rails-prelaunch-signup'
|
2445
|
+
|
2446
|
+
after_everything do
|
2447
|
+
say_wizard "recipe running after 'bundle install'"
|
2448
|
+
repo = 'https://raw.github.com/RailsApps/rails-prelaunch-signup/master/'
|
2449
|
+
|
2450
|
+
# >-------------------------------[ Clean up starter app ]--------------------------------<
|
2451
|
+
|
2452
|
+
%w{
|
2453
|
+
public/index.html
|
2454
|
+
app/assets/images/rails.png
|
2455
|
+
}.each { |file| remove_file file }
|
2456
|
+
# remove commented lines and multiple blank lines from Gemfile
|
2457
|
+
# thanks to https://github.com/perfectline/template-bucket/blob/master/cleanup.rb
|
2458
|
+
gsub_file 'Gemfile', /#.*\n/, "\n"
|
2459
|
+
gsub_file 'Gemfile', /\n^\s*\n/, "\n"
|
2460
|
+
# remove commented lines and multiple blank lines from config/routes.rb
|
2461
|
+
gsub_file 'config/routes.rb', / #.*\n/, "\n"
|
2462
|
+
gsub_file 'config/routes.rb', /\n^\s*\n/, "\n"
|
2463
|
+
# GIT
|
2464
|
+
git :add => '-A' if prefer :git, true
|
2465
|
+
git :commit => '-qm "rails_apps_composer: clean up starter app"' if prefer :git, true
|
2466
|
+
|
2467
|
+
# >-------------------------------[ Create a git branch ]--------------------------------<
|
2468
|
+
if prefer :git, true
|
2469
|
+
if prefer :prelaunch_branch, 'master'
|
2470
|
+
unless prefer :main_branch, 'none'
|
2471
|
+
say_wizard "renaming git branch 'master' to '#{prefs[:main_branch]}' for starter app"
|
2472
|
+
git :branch => "-m master #{prefs[:main_branch]}"
|
2473
|
+
git :checkout => "-b master"
|
2474
|
+
else
|
2475
|
+
say_wizard "creating prelaunch app on git branch 'master'"
|
2476
|
+
end
|
2477
|
+
else
|
2478
|
+
say_wizard "creating new git branch '#{prefs[:prelaunch_branch]}' for prelaunch app"
|
2479
|
+
git :checkout => "-b #{prefs[:prelaunch_branch]}"
|
2480
|
+
end
|
2481
|
+
end
|
2482
|
+
|
2483
|
+
# >-------------------------------[ Models ]--------------------------------<
|
2484
|
+
|
2485
|
+
copy_from_repo 'app/models/user.rb', :repo => repo
|
2486
|
+
|
2487
|
+
# >-------------------------------[ Init ]--------------------------------<
|
2488
|
+
copy_from_repo 'config/application.yml', :repo => repo
|
2489
|
+
remove_file 'config/application.example.yml'
|
2490
|
+
copy_file destination_root + '/config/application.yml', destination_root + '/config/application.example.yml'
|
2491
|
+
copy_from_repo 'db/seeds.rb', :repo => repo
|
2492
|
+
run 'bundle exec rake db:seed'
|
2493
|
+
run 'bundle exec rake db:test:prepare'
|
2494
|
+
|
2495
|
+
# >-------------------------------[ Controllers ]--------------------------------<
|
2496
|
+
|
2497
|
+
copy_from_repo 'app/controllers/confirmations_controller.rb', :repo => repo
|
2498
|
+
copy_from_repo 'app/controllers/home_controller.rb', :repo => repo
|
2499
|
+
copy_from_repo 'app/controllers/registrations_controller.rb', :repo => repo
|
2500
|
+
copy_from_repo 'app/controllers/users_controller.rb', :repo => repo
|
2501
|
+
|
2502
|
+
# >-------------------------------[ Mailers ]--------------------------------<
|
2503
|
+
|
2504
|
+
generate 'mailer UserMailer'
|
2505
|
+
copy_from_repo 'spec/mailers/user_mailer_spec.rb', :repo => repo
|
2506
|
+
copy_from_repo 'app/mailers/user_mailer.rb', :repo => repo
|
2507
|
+
|
2508
|
+
# >-------------------------------[ Views ]--------------------------------<
|
2509
|
+
|
2510
|
+
copy_from_repo 'app/views/devise/confirmations/show.html.erb', :repo => repo
|
2511
|
+
copy_from_repo 'app/views/devise/mailer/confirmation_instructions.html.erb', :repo => repo
|
2512
|
+
copy_from_repo 'app/views/devise/registrations/_thankyou.html.erb', :repo => repo
|
2513
|
+
copy_from_repo 'app/views/devise/registrations/new.html.erb', :repo => repo
|
2514
|
+
copy_from_repo 'app/views/devise/shared/_links.html.erb', :repo => repo
|
2515
|
+
copy_from_repo 'app/views/home/index.html.erb', :repo => repo
|
2516
|
+
copy_from_repo 'app/views/user_mailer/welcome_email.html.erb', :repo => repo
|
2517
|
+
copy_from_repo 'app/views/user_mailer/welcome_email.text.erb', :repo => repo
|
2518
|
+
copy_from_repo 'app/views/users/index.html.erb', :repo => repo
|
2519
|
+
copy_from_repo 'public/thankyou.html', :repo => repo
|
2520
|
+
|
2521
|
+
# >-------------------------------[ Routes ]--------------------------------<
|
2522
|
+
|
2523
|
+
copy_from_repo 'config/routes.rb', :repo => repo
|
2524
|
+
### CORRECT APPLICATION NAME ###
|
2525
|
+
gsub_file 'config/routes.rb', /^.*.routes.draw do/, "#{app_const}.routes.draw do"
|
2526
|
+
|
2527
|
+
# >-------------------------------[ Assets ]--------------------------------<
|
2528
|
+
|
2529
|
+
copy_from_repo 'app/assets/javascripts/application.js', :repo => repo
|
2530
|
+
copy_from_repo 'app/assets/stylesheets/application.css.scss', :repo => repo
|
2531
|
+
|
2532
|
+
# >-------------------------------[ Cucumber ]--------------------------------<
|
2533
|
+
say_wizard "copying Cucumber scenarios from the rails-prelaunch-signup examples"
|
2534
|
+
copy_from_repo 'features/admin/send_invitations.feature', :repo => repo
|
2535
|
+
copy_from_repo 'features/admin/view_progress.feature', :repo => repo
|
2536
|
+
copy_from_repo 'features/visitors/request_invitation.feature', :repo => repo
|
2537
|
+
copy_from_repo 'features/users/sign_in.feature', :repo => repo
|
2538
|
+
copy_from_repo 'features/users/sign_up.feature', :repo => repo
|
2539
|
+
copy_from_repo 'features/users/user_show.feature', :repo => repo
|
2540
|
+
copy_from_repo 'features/step_definitions/admin_steps.rb', :repo => repo
|
2541
|
+
copy_from_repo 'features/step_definitions/user_steps.rb', :repo => repo
|
2542
|
+
copy_from_repo 'features/step_definitions/visitor_steps.rb', :repo => repo
|
2543
|
+
copy_from_repo 'config/locales/devise.en.yml', :repo => repo
|
2544
|
+
|
2545
|
+
### GIT ###
|
2546
|
+
git :add => '-A' if prefer :git, true
|
2547
|
+
git :commit => '-qm "rails_apps_composer: prelaunch app"' if prefer :git, true
|
2548
|
+
end # after_bundler
|
2549
|
+
end # rails-prelaunch-signup
|
2550
|
+
# >-------------------------- recipes/prelaunch.rb ---------------------------end<
|
2551
|
+
# >-------------------------- templates/recipe.erb ---------------------------end<
|
2552
|
+
|
2553
|
+
# >-------------------------- templates/recipe.erb ---------------------------start<
|
2554
|
+
# >-------------------------------[ prelaunch ]-------------------------------<
|
2555
|
+
@current_recipe = "saas"
|
2556
|
+
@before_configs["saas"].call if @before_configs["saas"]
|
2557
|
+
say_recipe 'prelaunch'
|
2558
|
+
@configs[@current_recipe] = config
|
2559
|
+
# >-------------------------- recipes/prelaunch.rb ---------------------------start<
|
2560
|
+
|
2561
|
+
# Application template recipe for the rails_apps_composer. Change the recipe here:
|
2562
|
+
# https://github.com/RailsApps/rails_apps_composer/blob/master/recipes/saas.rb
|
2563
|
+
|
2564
|
+
if prefer :railsapps, 'rails-stripe-membership-saas'
|
2565
|
+
|
2566
|
+
after_everything do
|
2567
|
+
say_wizard "recipe running after 'bundle install'"
|
2568
|
+
repo = 'https://raw.github.com/RailsApps/rails-stripe-membership-saas/master/'
|
2569
|
+
|
2570
|
+
# >-------------------------------[ Clean up starter app ]--------------------------------<
|
2571
|
+
|
2572
|
+
%w{
|
2573
|
+
public/index.html
|
2574
|
+
app/assets/images/rails.png
|
2575
|
+
}.each { |file| remove_file file }
|
2576
|
+
# remove commented lines and multiple blank lines from Gemfile
|
2577
|
+
# thanks to https://github.com/perfectline/template-bucket/blob/master/cleanup.rb
|
2578
|
+
gsub_file 'Gemfile', /#.*\n/, "\n"
|
2579
|
+
gsub_file 'Gemfile', /\n^\s*\n/, "\n"
|
2580
|
+
# remove commented lines and multiple blank lines from config/routes.rb
|
2581
|
+
gsub_file 'config/routes.rb', / #.*\n/, "\n"
|
2582
|
+
gsub_file 'config/routes.rb', /\n^\s*\n/, "\n"
|
2583
|
+
# GIT
|
2584
|
+
git :add => '-A' if prefer :git, true
|
2585
|
+
git :commit => '-qm "rails_apps_composer: clean up starter app"' if prefer :git, true
|
2586
|
+
|
2587
|
+
# >-------------------------------[ Migrations ]--------------------------------<
|
2588
|
+
generate 'migration AddStripeToUsers customer_id:string last_4_digits:string'
|
2589
|
+
run 'bundle exec rake db:drop'
|
2590
|
+
run 'bundle exec rake db:migrate'
|
2591
|
+
|
2592
|
+
# >-------------------------------[ Models ]--------------------------------<
|
2593
|
+
copy_from_repo 'app/models/ability.rb', :repo => repo
|
2594
|
+
copy_from_repo 'app/models/user.rb', :repo => repo
|
2595
|
+
|
2596
|
+
# >-------------------------------[ Init ]--------------------------------<
|
2597
|
+
copy_from_repo 'config/application.yml', :repo => repo
|
2598
|
+
remove_file 'config/application.example.yml'
|
2599
|
+
copy_file destination_root + '/config/application.yml', destination_root + '/config/application.example.yml'
|
2600
|
+
copy_from_repo 'db/seeds.rb', :repo => repo
|
2601
|
+
copy_from_repo 'config/initializers/stripe.rb', :repo => repo
|
2602
|
+
run 'bundle exec rake db:seed'
|
2603
|
+
run 'bundle exec rake db:test:prepare'
|
2604
|
+
|
2605
|
+
# >-------------------------------[ Controllers ]--------------------------------<
|
2606
|
+
copy_from_repo 'app/controllers/home_controller.rb', :repo => repo
|
2607
|
+
generate 'controller content silver gold platinum --skip-stylesheets --skip-javascripts'
|
2608
|
+
copy_from_repo 'app/controllers/content_controller.rb', :repo => repo
|
2609
|
+
copy_from_repo 'app/controllers/registrations_controller.rb', :repo => repo
|
2610
|
+
copy_from_repo 'app/controllers/application_controller.rb', :repo => repo
|
2611
|
+
copy_from_repo 'app/controllers/users_controller.rb', :repo => repo
|
2612
|
+
|
2613
|
+
# >-------------------------------[ Mailers ]--------------------------------<
|
2614
|
+
generate 'mailer UserMailer'
|
2615
|
+
copy_from_repo 'app/mailers/user_mailer.rb', :repo => repo
|
2616
|
+
|
2617
|
+
# >-------------------------------[ Views ]--------------------------------<
|
2618
|
+
copy_from_repo 'app/views/home/index.html.erb', :repo => repo
|
2619
|
+
copy_from_repo 'app/views/layouts/_navigation.html.erb', :repo => repo
|
2620
|
+
copy_from_repo 'app/views/devise/registrations/new.html.erb', :repo => repo
|
2621
|
+
copy_from_repo 'app/views/devise/registrations/edit.html.erb', :repo => repo
|
2622
|
+
copy_from_repo 'app/views/user_mailer/expire_email.html.erb', :repo => repo
|
2623
|
+
copy_from_repo 'app/views/user_mailer/expire_email.text.erb', :repo => repo
|
2624
|
+
|
2625
|
+
# >-------------------------------[ Routes ]--------------------------------<
|
2626
|
+
copy_from_repo 'config/routes.rb', :repo => repo
|
2627
|
+
### CORRECT APPLICATION NAME ###
|
2628
|
+
gsub_file 'config/routes.rb', /^.*.routes.draw do/, "#{app_const}.routes.draw do"
|
2629
|
+
|
2630
|
+
# >-------------------------------[ Assets ]--------------------------------<
|
2631
|
+
copy_from_repo 'app/assets/javascripts/application.js', :repo => repo
|
2632
|
+
copy_from_repo 'app/assets/javascripts/jquery.readyselector.js', :repo => repo
|
2633
|
+
copy_from_repo 'app/assets/javascripts/jquery.externalscript.js', :repo => repo
|
2634
|
+
copy_from_repo 'app/assets/javascripts/registrations.js', :repo => repo
|
2635
|
+
copy_from_repo 'app/assets/stylesheets/application.css.scss', :repo => repo
|
2636
|
+
copy_from_repo 'app/assets/stylesheets/pricing.css.scss', :repo => repo
|
2637
|
+
|
2638
|
+
# >-------------------------------[ RSpec ]--------------------------------<
|
2639
|
+
say_wizard "copying RSpec tests from the rails-stripe-membership-saas examples"
|
2640
|
+
copy_from_repo 'spec/factories/roles.rb', :repo => repo
|
2641
|
+
copy_from_repo 'spec/models/user_spec.rb', :repo => repo
|
2642
|
+
copy_from_repo 'spec/controllers/content_controller_spec.rb', :repo => repo
|
2643
|
+
copy_from_repo 'spec/mailers/user_mailer_spec.rb', :repo => repo
|
2644
|
+
copy_from_repo 'spec/stripe/stripe_config_spec.rb', :repo => repo
|
2645
|
+
copy_from_repo 'spec/support/stripe_helper.rb', :repo => repo
|
2646
|
+
copy_from_repo 'spec/support/fixtures/success.json', :repo => repo
|
2647
|
+
|
2648
|
+
# >-------------------------------[ Cucumber ]--------------------------------<
|
2649
|
+
say_wizard "copying Cucumber scenarios from the rails-stripe-membership-saas examples"
|
2650
|
+
remove_file 'features/users/user_show.feature'
|
2651
|
+
copy_from_repo 'features/support/paths.rb', :repo => repo
|
2652
|
+
copy_from_repo 'features/users/sign_in.feature', :repo => repo
|
2653
|
+
copy_from_repo 'features/users/sign_up.feature', :repo => repo
|
2654
|
+
copy_from_repo 'features/users/sign_up_with_stripe.feature', :repo => repo
|
2655
|
+
copy_from_repo 'features/users/user_edit.feature', :repo => repo
|
2656
|
+
copy_from_repo 'features/users/user_delete.feature', :repo => repo
|
2657
|
+
copy_from_repo 'features/step_definitions/user_steps.rb', :repo => repo
|
2658
|
+
copy_from_repo 'features/step_definitions/form_helper_steps.rb', :repo => repo
|
2659
|
+
copy_from_repo 'config/locales/devise.en.yml', :repo => repo
|
2660
|
+
|
2661
|
+
### GIT ###
|
2662
|
+
git :add => '-A' if prefer :git, true
|
2663
|
+
git :commit => '-qm "rails_apps_composer: membership app"' if prefer :git, true
|
2664
|
+
end # after_bundler
|
2665
|
+
end # rails-stripe-membership-saas
|
2666
|
+
|
2667
|
+
if prefer :railsapps, 'rails-recurly-subscription-saas'
|
2668
|
+
|
2669
|
+
after_everything do
|
2670
|
+
say_wizard "recipe running after 'bundle install'"
|
2671
|
+
repo = 'https://raw.github.com/RailsApps/rails-recurly-subscription-saas/master/'
|
2672
|
+
|
2673
|
+
# >-------------------------------[ Clean up starter app ]--------------------------------<
|
2674
|
+
|
2675
|
+
%w{
|
2676
|
+
public/index.html
|
2677
|
+
app/assets/images/rails.png
|
2678
|
+
}.each { |file| remove_file file }
|
2679
|
+
# remove commented lines and multiple blank lines from Gemfile
|
2680
|
+
# thanks to https://github.com/perfectline/template-bucket/blob/master/cleanup.rb
|
2681
|
+
gsub_file 'Gemfile', /#.*\n/, "\n"
|
2682
|
+
gsub_file 'Gemfile', /\n^\s*\n/, "\n"
|
2683
|
+
# remove commented lines and multiple blank lines from config/routes.rb
|
2684
|
+
gsub_file 'config/routes.rb', / #.*\n/, "\n"
|
2685
|
+
gsub_file 'config/routes.rb', /\n^\s*\n/, "\n"
|
2686
|
+
# GIT
|
2687
|
+
git :add => '-A' if prefer :git, true
|
2688
|
+
git :commit => '-qm "rails_apps_composer: clean up starter app"' if prefer :git, true
|
2689
|
+
|
2690
|
+
# >-------------------------------[ Migrations ]--------------------------------<
|
2691
|
+
generate 'migration AddRecurlyToUsers first_name:string last_name:string customer_id:string'
|
2692
|
+
run 'bundle exec rake db:drop'
|
2693
|
+
run 'bundle exec rake db:migrate'
|
2694
|
+
|
2695
|
+
# >-------------------------------[ Models ]--------------------------------<
|
2696
|
+
copy_from_repo 'app/models/ability.rb', :repo => repo
|
2697
|
+
copy_from_repo 'app/models/user.rb', :repo => repo
|
2698
|
+
|
2699
|
+
# >-------------------------------[ Init ]--------------------------------<
|
2700
|
+
copy_from_repo 'config/application.yml', :repo => repo
|
2701
|
+
remove_file 'config/application.example.yml'
|
2702
|
+
copy_file destination_root + '/config/application.yml', destination_root + '/config/application.example.yml'
|
2703
|
+
copy_from_repo 'db/seeds.rb', :repo => repo
|
2704
|
+
copy_from_repo 'config/initializers/recurly.rb', :repo => repo
|
2705
|
+
run 'bundle exec rake db:seed'
|
2706
|
+
run 'bundle exec rake db:test:prepare'
|
2707
|
+
|
2708
|
+
# >-------------------------------[ Controllers ]--------------------------------<
|
2709
|
+
copy_from_repo 'app/controllers/home_controller.rb', :repo => repo
|
2710
|
+
generate 'controller content silver gold platinum --skip-stylesheets --skip-javascripts'
|
2711
|
+
copy_from_repo 'app/controllers/content_controller.rb', :repo => repo
|
2712
|
+
copy_from_repo 'app/controllers/registrations_controller.rb', :repo => repo
|
2713
|
+
copy_from_repo 'app/controllers/application_controller.rb', :repo => repo
|
2714
|
+
copy_from_repo 'app/controllers/users_controller.rb', :repo => repo
|
2715
|
+
copy_from_repo 'app/controllers/recurly_controller.rb', :repo => repo
|
2716
|
+
|
2717
|
+
# >-------------------------------[ Mailers ]--------------------------------<
|
2718
|
+
generate 'mailer UserMailer'
|
2719
|
+
copy_from_repo 'app/mailers/user_mailer.rb', :repo => repo
|
2720
|
+
|
2721
|
+
# >-------------------------------[ Views ]--------------------------------<
|
2722
|
+
copy_from_repo 'app/views/home/index.html.erb', :repo => repo
|
2723
|
+
copy_from_repo 'app/views/layouts/_navigation.html.erb', :repo => repo
|
2724
|
+
copy_from_repo 'app/views/devise/registrations/new.html.erb', :repo => repo
|
2725
|
+
copy_from_repo 'app/views/devise/registrations/edit.html.erb', :repo => repo
|
2726
|
+
copy_from_repo 'app/views/user_mailer/expire_email.html.erb', :repo => repo
|
2727
|
+
copy_from_repo 'app/views/user_mailer/expire_email.text.erb', :repo => repo
|
2728
|
+
|
2729
|
+
# >-------------------------------[ Routes ]--------------------------------<
|
2730
|
+
copy_from_repo 'config/routes.rb', :repo => repo
|
2731
|
+
### CORRECT APPLICATION NAME ###
|
2732
|
+
gsub_file 'config/routes.rb', /^.*.routes.draw do/, "#{app_const}.routes.draw do"
|
2733
|
+
|
2734
|
+
# >-------------------------------[ Assets ]--------------------------------<
|
2735
|
+
copy_from_repo 'app/assets/javascripts/application.js', :repo => repo
|
2736
|
+
copy_from_repo 'app/assets/javascripts/jquery.readyselector.js', :repo => repo
|
2737
|
+
copy_from_repo 'app/assets/javascripts/recurly.js', :repo => repo
|
2738
|
+
copy_from_repo 'app/assets/javascripts/registrations.js', :repo => repo
|
2739
|
+
copy_from_repo 'app/assets/stylesheets/application.css.scss', :repo => repo
|
2740
|
+
copy_from_repo 'app/assets/stylesheets/pricing.css.scss', :repo => repo
|
2741
|
+
|
2742
|
+
# >-------------------------------[ RSpec ]--------------------------------<
|
2743
|
+
say_wizard "copying RSpec tests from the rails-recurly-subscription-saas examples"
|
2744
|
+
copy_from_repo 'spec/factories/roles.rb', :repo => repo
|
2745
|
+
copy_from_repo 'spec/factories/users.rb', :repo => repo
|
2746
|
+
copy_from_repo 'spec/models/user_spec.rb', :repo => repo
|
2747
|
+
copy_from_repo 'spec/controllers/content_controller_spec.rb', :repo => repo
|
2748
|
+
copy_from_repo 'spec/mailers/user_mailer_spec.rb', :repo => repo
|
2749
|
+
copy_from_repo 'spec/recurly/recurly_config_spec.rb', :repo => repo
|
2750
|
+
|
2751
|
+
# >-------------------------------[ Cucumber ]--------------------------------<
|
2752
|
+
say_wizard "copying Cucumber scenarios from the rails-recurly-subscription-saas examples"
|
2753
|
+
remove_file 'features/users/user_show.feature'
|
2754
|
+
copy_from_repo 'features/support/paths.rb', :repo => repo
|
2755
|
+
copy_from_repo 'features/users/sign_in.feature', :repo => repo
|
2756
|
+
copy_from_repo 'features/users/sign_up.feature', :repo => repo
|
2757
|
+
copy_from_repo 'features/users/sign_up_with_recurly.feature', :repo => repo
|
2758
|
+
copy_from_repo 'features/users/user_edit.feature', :repo => repo
|
2759
|
+
copy_from_repo 'features/users/user_delete.feature', :repo => repo
|
2760
|
+
copy_from_repo 'features/step_definitions/user_steps.rb', :repo => repo
|
2761
|
+
copy_from_repo 'features/step_definitions/form_helper_steps.rb', :repo => repo
|
2762
|
+
copy_from_repo 'config/locales/devise.en.yml', :repo => repo
|
2763
|
+
|
2764
|
+
### GIT ###
|
2765
|
+
git :add => '-A' if prefer :git, true
|
2766
|
+
git :commit => '-qm "rails_apps_composer: membership app"' if prefer :git, true
|
2767
|
+
end # after_bundler
|
2768
|
+
end # rails-recurly-subscription-saas
|
2769
|
+
# >-------------------------- recipes/prelaunch.rb ---------------------------end<
|
2770
|
+
# >-------------------------- templates/recipe.erb ---------------------------end<
|
2771
|
+
|
2772
|
+
# >-------------------------- templates/recipe.erb ---------------------------start<
|
2773
|
+
# >--------------------------------[ routes ]---------------------------------<
|
2774
|
+
@current_recipe = "routes"
|
2775
|
+
@before_configs["routes"].call if @before_configs["routes"]
|
2776
|
+
say_recipe 'routes'
|
2777
|
+
@configs[@current_recipe] = config
|
2778
|
+
# >---------------------------- recipes/routes.rb ----------------------------start<
|
2779
|
+
|
2780
|
+
# Application template recipe for the rails_apps_composer. Change the recipe here:
|
2781
|
+
# https://github.com/RailsApps/rails_apps_composer/blob/master/recipes/routes.rb
|
2782
|
+
|
2783
|
+
after_bundler do
|
2784
|
+
say_wizard "recipe running after 'bundle install'"
|
2785
|
+
### HOME ###
|
2786
|
+
if prefer :starter_app, 'home_app'
|
2787
|
+
remove_file 'public/index.html'
|
2788
|
+
gsub_file 'config/routes.rb', /get \"home\/index\"/, 'root :to => "home#index"'
|
2789
|
+
end
|
2790
|
+
### USER_ACCOUNTS ###
|
2791
|
+
if ['users_app','admin_app'].include? prefs[:starter_app]
|
2792
|
+
## DEVISE
|
2793
|
+
if (prefer :authentication, 'devise') and (not prefer :apps4, 'rails-devise')
|
2794
|
+
copy_from_repo 'config/routes.rb', :repo => 'https://raw.github.com/RailsApps/rails3-devise-rspec-cucumber/master/'
|
2795
|
+
## Rails 4.0 doesn't allow two 'root' routes
|
2796
|
+
gsub_file 'config/routes.rb', /authenticated :user do\n.*\n.*\n /, '' if rails_4?
|
2797
|
+
## accommodate strong parameters in Rails 4
|
2798
|
+
gsub_file 'config/routes.rb', /devise_for :users/, 'devise_for :users, :controllers => {:registrations => "registrations"}' if rails_4?
|
2799
|
+
end
|
2800
|
+
## OMNIAUTH
|
2801
|
+
if prefer :authentication, 'omniauth'
|
2802
|
+
if rails_4?
|
2803
|
+
copy_from_repo 'config/routes.rb', :repo => 'https://raw.github.com/RailsApps/rails-omniauth/master/'
|
2804
|
+
else
|
2805
|
+
copy_from_repo 'config/routes.rb', :repo => 'https://raw.github.com/RailsApps/rails3-mongoid-omniauth/master/'
|
2806
|
+
end
|
2807
|
+
end
|
2808
|
+
end
|
2809
|
+
### SUBDOMAINS ###
|
2810
|
+
copy_from_repo 'lib/subdomain.rb', :repo => 'https://raw.github.com/RailsApps/rails3-subdomains/master/' if prefer :starter_app, 'subdomains_app'
|
2811
|
+
copy_from_repo 'config/routes.rb', :repo => 'https://raw.github.com/RailsApps/rails3-subdomains/master/' if prefer :starter_app, 'subdomains_app'
|
2812
|
+
### CORRECT APPLICATION NAME ###
|
2813
|
+
gsub_file 'config/routes.rb', /^.*.routes.draw do/, "#{app_const}.routes.draw do"
|
2814
|
+
### GIT ###
|
2815
|
+
git :add => '-A' if prefer :git, true
|
2816
|
+
git :commit => '-qm "rails_apps_composer: routes"' if prefer :git, true
|
2817
|
+
end # after_bundler
|
2818
|
+
# >---------------------------- recipes/routes.rb ----------------------------end<
|
2819
|
+
# >-------------------------- templates/recipe.erb ---------------------------end<
|
2820
|
+
|
2821
|
+
# >-------------------------- templates/recipe.erb ---------------------------start<
|
2822
|
+
# >--------------------------------[ extras ]---------------------------------<
|
2823
|
+
@current_recipe = "extras"
|
2824
|
+
@before_configs["extras"].call if @before_configs["extras"]
|
2825
|
+
say_recipe 'extras'
|
2826
|
+
config = {}
|
2827
|
+
config['ban_spiders'] = yes_wizard?("Set a robots.txt file to ban spiders?") if true && true unless config.key?('ban_spiders') || prefs.has_key?(:ban_spiders)
|
2828
|
+
config['github'] = yes_wizard?("Create a GitHub repository?") if true && true unless config.key?('github') || prefs.has_key?(:github)
|
2829
|
+
config['local_env_file'] = multiple_choice("Use file for environment variables?", [["None", "none"], ["Use application.yml with Figaro", "figaro"], ["Use .env with Foreman", "foreman"]]) if true && true unless config.key?('local_env_file') || prefs.has_key?(:local_env_file)
|
2830
|
+
config['quiet_assets'] = yes_wizard?("Reduce assets logger noise during development?") if true && true unless config.key?('quiet_assets') || prefs.has_key?(:quiet_assets)
|
2831
|
+
config['better_errors'] = yes_wizard?("Improve error reporting with 'better_errors' during development?") if true && true unless config.key?('better_errors') || prefs.has_key?(:better_errors)
|
2832
|
+
@configs[@current_recipe] = config
|
2833
|
+
# >---------------------------- recipes/extras.rb ----------------------------start<
|
2834
|
+
|
2835
|
+
# Application template recipe for the rails_apps_composer. Change the recipe here:
|
2836
|
+
# https://github.com/RailsApps/rails_apps_composer/blob/master/recipes/extras.rb
|
2837
|
+
|
2838
|
+
## RVMRC
|
2839
|
+
rvmrc_detected = false
|
2840
|
+
if File.exist?('.rvmrc')
|
2841
|
+
rvmrc_file = File.read('.rvmrc')
|
2842
|
+
rvmrc_detected = rvmrc_file.include? app_name
|
2843
|
+
end
|
2844
|
+
if File.exist?('.ruby-gemset')
|
2845
|
+
rvmrc_file = File.read('.ruby-gemset')
|
2846
|
+
rvmrc_detected = rvmrc_file.include? app_name
|
2847
|
+
end
|
2848
|
+
unless rvmrc_detected || (prefs.has_key? :rvmrc)
|
2849
|
+
prefs[:rvmrc] = yes_wizard? "Use or create a project-specific rvm gemset?"
|
2850
|
+
end
|
2851
|
+
if prefs[:rvmrc]
|
2852
|
+
if which("rvm")
|
2853
|
+
say_wizard "recipe creating project-specific rvm gemset and .rvmrc"
|
2854
|
+
# using the rvm Ruby API, see:
|
2855
|
+
# http://blog.thefrontiergroup.com.au/2010/12/a-brief-introduction-to-the-rvm-ruby-api/
|
2856
|
+
# https://rvm.io/integration/passenger
|
2857
|
+
if ENV['MY_RUBY_HOME'] && ENV['MY_RUBY_HOME'].include?('rvm')
|
2858
|
+
begin
|
2859
|
+
gems_path = ENV['MY_RUBY_HOME'].split(/@/)[0].sub(/rubies/,'gems')
|
2860
|
+
ENV['GEM_PATH'] = "#{gems_path}:#{gems_path}@global"
|
2861
|
+
require 'rvm'
|
2862
|
+
RVM.use_from_path! File.dirname(File.dirname(__FILE__))
|
2863
|
+
rescue LoadError
|
2864
|
+
raise "RVM gem is currently unavailable."
|
2865
|
+
end
|
2866
|
+
end
|
2867
|
+
say_wizard "creating RVM gemset '#{app_name}'"
|
2868
|
+
RVM.gemset_create app_name
|
2869
|
+
say_wizard "switching to gemset '#{app_name}'"
|
2870
|
+
# RVM.gemset_use! requires rvm version 1.11.3.5 or newer
|
2871
|
+
rvm_spec =
|
2872
|
+
if Gem::Specification.respond_to?(:find_by_name)
|
2873
|
+
Gem::Specification.find_by_name("rvm")
|
2874
|
+
else
|
2875
|
+
Gem.source_index.find_name("rvm").last
|
2876
|
+
end
|
2877
|
+
unless rvm_spec.version > Gem::Version.create('1.11.3.4')
|
2878
|
+
say_wizard "rvm gem version: #{rvm_spec.version}"
|
2879
|
+
raise "Please update rvm gem to 1.11.3.5 or newer"
|
2880
|
+
end
|
2881
|
+
begin
|
2882
|
+
RVM.gemset_use! app_name
|
2883
|
+
rescue => e
|
2884
|
+
say_wizard "rvm failure: unable to use gemset #{app_name}, reason: #{e}"
|
2885
|
+
raise
|
2886
|
+
end
|
2887
|
+
run "rvm gemset list"
|
2888
|
+
if File.exist?('.ruby-version')
|
2889
|
+
say_wizard ".ruby-version file already exists"
|
2890
|
+
else
|
2891
|
+
create_file '.ruby-version', "#{RUBY_VERSION}\n"
|
2892
|
+
end
|
2893
|
+
if File.exist?('.ruby-gemset')
|
2894
|
+
say_wizard ".ruby-gemset file already exists"
|
2895
|
+
else
|
2896
|
+
create_file '.ruby-gemset', "#{app_name}\n"
|
2897
|
+
end
|
2898
|
+
else
|
2899
|
+
say_wizard "WARNING! RVM does not appear to be available."
|
2900
|
+
end
|
2901
|
+
end
|
2902
|
+
|
2903
|
+
## QUIET ASSETS
|
2904
|
+
if config['quiet_assets']
|
2905
|
+
prefs[:quiet_assets] = true
|
2906
|
+
end
|
2907
|
+
if prefs[:quiet_assets]
|
2908
|
+
say_wizard "recipe setting quiet_assets for reduced asset pipeline logging"
|
2909
|
+
add_gem 'quiet_assets', :group => :development
|
2910
|
+
end
|
2911
|
+
|
2912
|
+
## LOCAL_ENV.YML FILE
|
2913
|
+
if config['local_env_file']
|
2914
|
+
case config['local_env_file']
|
2915
|
+
when 'figaro'
|
2916
|
+
prefs[:local_env_file] = 'figaro'
|
2917
|
+
when 'foreman'
|
2918
|
+
prefs[:local_env_file] = 'foreman'
|
2919
|
+
end
|
2920
|
+
end
|
2921
|
+
if prefer :local_env_file, 'figaro' and not rails_4_1?
|
2922
|
+
say_wizard "recipe creating application.yml file for environment variables with figaro"
|
2923
|
+
add_gem 'figaro'
|
2924
|
+
elsif prefer :local_env_file, 'foreman'
|
2925
|
+
say_wizard "recipe creating .env file for development environment variables with foreman"
|
2926
|
+
add_gem 'foreman', :group => :development
|
2927
|
+
end
|
2928
|
+
|
2929
|
+
## BETTER ERRORS
|
2930
|
+
if config['better_errors']
|
2931
|
+
prefs[:better_errors] = true
|
2932
|
+
end
|
2933
|
+
if prefs[:better_errors]
|
2934
|
+
say_wizard "recipe adding better_errors gem"
|
2935
|
+
add_gem 'better_errors', :group => :development
|
2936
|
+
add_gem 'binding_of_caller', :group => :development, :platforms => [:mri_19, :mri_20, :rbx]
|
2937
|
+
end
|
2938
|
+
|
2939
|
+
## BAN SPIDERS
|
2940
|
+
if config['ban_spiders']
|
2941
|
+
prefs[:ban_spiders] = true
|
2942
|
+
end
|
2943
|
+
if prefs[:ban_spiders]
|
2944
|
+
say_wizard "recipe banning spiders by modifying 'public/robots.txt'"
|
2945
|
+
after_bundler do
|
2946
|
+
gsub_file 'public/robots.txt', /# User-Agent/, 'User-Agent'
|
2947
|
+
gsub_file 'public/robots.txt', /# Disallow/, 'Disallow'
|
2948
|
+
end
|
2949
|
+
end
|
2950
|
+
|
2951
|
+
## JSRUNTIME
|
2952
|
+
case RbConfig::CONFIG['host_os']
|
2953
|
+
when /linux/i
|
2954
|
+
prefs[:jsruntime] = yes_wizard? "Add 'therubyracer' JavaScript runtime (for Linux users without node.js)?" unless prefs.has_key? :jsruntime
|
2955
|
+
if prefs[:jsruntime]
|
2956
|
+
say_wizard "recipe adding 'therubyracer' JavaScript runtime gem"
|
2957
|
+
add_gem 'therubyracer', :platform => :ruby
|
2958
|
+
end
|
2959
|
+
end
|
2960
|
+
|
2961
|
+
## AFTER_EVERYTHING
|
2962
|
+
after_everything do
|
2963
|
+
say_wizard "recipe removing unnecessary files and whitespace"
|
2964
|
+
%w{
|
2965
|
+
public/index.html
|
2966
|
+
app/assets/images/rails.png
|
2967
|
+
}.each { |file| remove_file file }
|
2968
|
+
# remove temporary Haml gems from Gemfile when Slim is selected
|
2969
|
+
if prefer :templates, 'slim'
|
2970
|
+
gsub_file 'Gemfile', / gem 'haml2slim'\n/, "\n"
|
2971
|
+
gsub_file 'Gemfile', / gem 'html2haml'\n/, "\n"
|
2972
|
+
end
|
2973
|
+
# remove commented lines and multiple blank lines from Gemfile
|
2974
|
+
# thanks to https://github.com/perfectline/template-bucket/blob/master/cleanup.rb
|
2975
|
+
gsub_file 'Gemfile', /#.*\n/, "\n"
|
2976
|
+
gsub_file 'Gemfile', /\n^\s*\n/, "\n"
|
2977
|
+
# remove commented lines and multiple blank lines from config/routes.rb
|
2978
|
+
gsub_file 'config/routes.rb', / #.*\n/, "\n"
|
2979
|
+
gsub_file 'config/routes.rb', /\n^\s*\n/, "\n"
|
2980
|
+
# GIT
|
2981
|
+
git :add => '-A' if prefer :git, true
|
2982
|
+
git :commit => '-qm "rails_apps_composer: extras"' if prefer :git, true
|
2983
|
+
end
|
2984
|
+
|
2985
|
+
## GITHUB
|
2986
|
+
if config['github']
|
2987
|
+
prefs[:github] = true
|
2988
|
+
end
|
2989
|
+
if prefs[:github]
|
2990
|
+
add_gem 'hub', :require => nil, :group => [:development]
|
2991
|
+
after_everything do
|
2992
|
+
say_wizard "recipe creating GitHub repository"
|
2993
|
+
git_uri = `git config remote.origin.url`.strip
|
2994
|
+
unless git_uri.size == 0
|
2995
|
+
say_wizard "Repository already exists:"
|
2996
|
+
say_wizard "#{git_uri}"
|
2997
|
+
else
|
2998
|
+
run "hub create #{app_name}"
|
2999
|
+
unless prefer :railsapps, 'rails-prelaunch-signup'
|
3000
|
+
run "hub push -u origin master"
|
3001
|
+
else
|
3002
|
+
run "hub push -u origin #{prefs[:prelaunch_branch]}"
|
3003
|
+
run "hub push -u origin #{prefs[:main_branch]}" unless prefer :main_branch, 'none'
|
3004
|
+
end
|
3005
|
+
end
|
3006
|
+
end
|
3007
|
+
end
|
3008
|
+
# >---------------------------- recipes/extras.rb ----------------------------end<
|
3009
|
+
# >-------------------------- templates/recipe.erb ---------------------------end<
|
3010
|
+
|
3011
|
+
# >-------------------------- templates/recipe.erb ---------------------------start<
|
3012
|
+
# >-------------------------------[ email_dev ]-------------------------------<
|
3013
|
+
@current_recipe = "email_dev"
|
3014
|
+
@before_configs["email_dev"].call if @before_configs["email_dev"]
|
3015
|
+
say_recipe 'email_dev'
|
3016
|
+
config = {}
|
3017
|
+
config['mailcatcher'] = yes_wizard?("Use Mailcatcher to catch sent emails in development and display in web interface?") if true && true unless config.key?('mailcatcher') || prefs.has_key?(:mailcatcher)
|
3018
|
+
config['mail_view'] = yes_wizard?("Add MailView routes to preview email layouts in development?") if true && true unless config.key?('mail_view') || prefs.has_key?(:mail_view)
|
3019
|
+
@configs[@current_recipe] = config
|
3020
|
+
# >-------------------------- recipes/email_dev.rb ---------------------------start<
|
3021
|
+
|
3022
|
+
# Application template recipe for the rails_apps_composer. Change the recipe here:
|
3023
|
+
# https://github.com/RailsApps/rails_apps_composer/blob/master/recipes/email_dev.rb
|
3024
|
+
|
3025
|
+
prefs[:mailcatcher] = true if config['mailcatcher']
|
3026
|
+
prefs[:mail_view] = true if config['mail_view']
|
3027
|
+
|
3028
|
+
if prefs[:mailcatcher]
|
3029
|
+
if rails_4?
|
3030
|
+
add_gem 'mailcatcher', github: 'sj26/mailcatcher', group: :development
|
3031
|
+
else
|
3032
|
+
add_gem 'mailcatcher', group: :development
|
3033
|
+
end
|
3034
|
+
end
|
3035
|
+
add_gem 'mail_view', group: :development if prefs[:mail_view]
|
3036
|
+
|
3037
|
+
after_bundler do
|
3038
|
+
if prefs[:mailcatcher]
|
3039
|
+
say_wizard "recipe installing mailcatcher"
|
3040
|
+
create_file 'config/initializers/mailcatcher.rb' do <<-RUBY
|
3041
|
+
# Detect if mailcatcher is running and use that if available
|
3042
|
+
if Rails.env.development?
|
3043
|
+
begin
|
3044
|
+
sock = TCPSocket.new("localhost", 1025)
|
3045
|
+
sock.close
|
3046
|
+
catcher = true
|
3047
|
+
rescue
|
3048
|
+
catcher = false
|
3049
|
+
end
|
3050
|
+
|
3051
|
+
if catcher
|
3052
|
+
ActionMailer::Base.smtp_settings = { :host => "localhost", :port => '1025', }
|
3053
|
+
ActionMailer::Base.perform_deliveries = true
|
3054
|
+
end
|
3055
|
+
end
|
3056
|
+
RUBY
|
3057
|
+
end
|
3058
|
+
if prefer(:local_env_file, 'foreman') && File.exists?('Procfile.dev')
|
3059
|
+
append_file 'Procfile.dev', 'mail: mailcatcher --foreground'
|
3060
|
+
end
|
3061
|
+
### GIT
|
3062
|
+
git :add => '-A' if prefer :git, true
|
3063
|
+
git :commit => '-qm "rails_apps_composer: set up mailcatcher for development"' if prefer :git, true
|
3064
|
+
end
|
3065
|
+
if prefs[:mail_view]
|
3066
|
+
say_wizard "recipe installing mail_view"
|
3067
|
+
create_file 'app/mailers/mail_preview.rb' do <<-RUBY
|
3068
|
+
class MailPreview < MailView
|
3069
|
+
# Pull data from existing fixtures
|
3070
|
+
#def invitation
|
3071
|
+
# account = Account.first
|
3072
|
+
# inviter, invitee = account.users[0, 2]
|
3073
|
+
# Notifier.invitation(inviter, invitee)
|
3074
|
+
#end
|
3075
|
+
|
3076
|
+
# Factory-like pattern
|
3077
|
+
#def welcome
|
3078
|
+
# user = User.create!
|
3079
|
+
# mail = Notifier.welcome(user)
|
3080
|
+
# user.destroy
|
3081
|
+
# mail
|
3082
|
+
#end
|
3083
|
+
|
3084
|
+
# Stub-like
|
3085
|
+
#def forgot_password
|
3086
|
+
# user = Struct.new(:email, :name).new('name@example.com', 'Jill Smith')
|
3087
|
+
# mail = UserMailer.forgot_password(user)
|
3088
|
+
#end
|
3089
|
+
end
|
3090
|
+
RUBY
|
3091
|
+
end
|
3092
|
+
inject_into_file 'config/routes.rb', "mount MailPreview => 'mail_view' if Rails.env.development?", :before => "end"
|
3093
|
+
### GIT
|
3094
|
+
git :add => '-A' if prefer :git, true
|
3095
|
+
git :commit => '-qm "rails_apps_composer: set up mail_view for development"' if prefer :git, true
|
3096
|
+
end
|
3097
|
+
end
|
3098
|
+
# >-------------------------- recipes/email_dev.rb ---------------------------end<
|
3099
|
+
# >-------------------------- templates/recipe.erb ---------------------------end<
|
3100
|
+
|
3101
|
+
|
3102
|
+
# >-----------------------------[ Final Gemfile Write ]------------------------------<
|
3103
|
+
Gemfile.write
|
3104
|
+
|
3105
|
+
# >---------------------------------[ Diagnostics ]----------------------------------<
|
3106
|
+
|
3107
|
+
# remove prefs which are diagnostically irrelevant
|
3108
|
+
redacted_prefs = prefs.clone
|
3109
|
+
redacted_prefs.delete(:ban_spiders)
|
3110
|
+
redacted_prefs.delete(:better_errors)
|
3111
|
+
redacted_prefs.delete(:dev_webserver)
|
3112
|
+
redacted_prefs.delete(:git)
|
3113
|
+
redacted_prefs.delete(:github)
|
3114
|
+
redacted_prefs.delete(:jsruntime)
|
3115
|
+
redacted_prefs.delete(:local_env_file)
|
3116
|
+
redacted_prefs.delete(:main_branch)
|
3117
|
+
redacted_prefs.delete(:prelaunch_branch)
|
3118
|
+
redacted_prefs.delete(:prod_webserver)
|
3119
|
+
redacted_prefs.delete(:quiet_assets)
|
3120
|
+
redacted_prefs.delete(:rvmrc)
|
3121
|
+
redacted_prefs.delete(:templates)
|
3122
|
+
|
3123
|
+
if diagnostics_prefs.include? redacted_prefs
|
3124
|
+
diagnostics[:prefs] = 'success'
|
3125
|
+
else
|
3126
|
+
diagnostics[:prefs] = 'fail'
|
3127
|
+
end
|
3128
|
+
|
3129
|
+
@current_recipe = nil
|
3130
|
+
|
3131
|
+
# >-----------------------------[ Run 'Bundle Install' ]-------------------------------<
|
3132
|
+
|
3133
|
+
say_wizard "Installing gems. This will take a while."
|
3134
|
+
run 'bundle install --without production'
|
3135
|
+
say_wizard "Updating gem paths."
|
3136
|
+
Gem.clear_paths
|
3137
|
+
# >-----------------------------[ Run 'After Bundler' Callbacks ]-------------------------------<
|
3138
|
+
|
3139
|
+
say_wizard "Running 'after bundler' callbacks."
|
3140
|
+
if prefer :templates, 'haml'
|
3141
|
+
say_wizard "importing html2haml conversion tool"
|
3142
|
+
require 'html2haml'
|
3143
|
+
end
|
3144
|
+
if prefer :templates, 'slim'
|
3145
|
+
say_wizard "importing html2haml and haml2slim conversion tools"
|
3146
|
+
require 'html2haml'
|
3147
|
+
require 'haml2slim'
|
3148
|
+
end
|
3149
|
+
@after_blocks.each{|b| config = @configs[b[0]] || {}; @current_recipe = b[0]; puts @current_recipe; b[1].call}
|
3150
|
+
|
3151
|
+
# >-----------------------------[ Run 'After Everything' Callbacks ]-------------------------------<
|
3152
|
+
|
3153
|
+
@current_recipe = nil
|
3154
|
+
say_wizard "Running 'after everything' callbacks."
|
3155
|
+
@after_everything_blocks.each{|b| config = @configs[b[0]] || {}; @current_recipe = b[0]; puts @current_recipe; b[1].call}
|
3156
|
+
|
3157
|
+
@current_recipe = nil
|
3158
|
+
say_wizard("Creating God Scripts")
|
3159
|
+
exec "touch lib/scripts/server.god"
|
3160
|
+
exec "cat <<EOF>> lib/scripts/server.god
|
3161
|
+
God.watch do |w|
|
3162
|
+
w.name = \"server\"
|
3163
|
+
w.start = \"foreman start\"
|
3164
|
+
w.keepalive
|
3165
|
+
end
|
3166
|
+
EOF"
|
3167
|
+
say_wizard("Your new application will contain diagnostics in its README file.")
|
3168
|
+
say_wizard("When reporting an issue on GitHub, include the README diagnostics.")
|
3169
|
+
say_wizard "Finished running the rails_apps_composer app template."
|
3170
|
+
say_wizard "Your new Rails app is ready. Time to run 'bundle install'."
|
3171
|
+
end
|