-
Notifications
You must be signed in to change notification settings - Fork 486
/
composer.rb
2887 lines (2522 loc) · 120 KB
/
composer.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# >---------------------------------------------------------------------------<
#
# _____ _ _
# | __ \ (_) | /\
# | |__) |__ _ _| |___ / \ _ __ _ __ ___
# | _ // _` | | / __| / /\ \ | '_ \| '_ \/ __|
# | | \ \ (_| | | \__ \/ ____ \| |_) | |_) \__ \
# |_| \_\__,_|_|_|___/_/ \_\ .__/| .__/|___/
# | | | |
# |_| |_|
#
# Application template generated by the rails_apps_composer gem.
# Restrain your impulse to make changes to this file; instead,
# make changes to the recipes in the rails_apps_composer gem.
#
# For more information, see:
# https://github.com/RailsApps/rails_apps_composer/
#
# Thank you to Michael Bleigh for leading the way with the RailsWizard gem.
#
# >---------------------------------------------------------------------------<
# >----------------------------[ Initial Setup ]------------------------------<
module Gemfile
class GemInfo
def initialize(name) @name=name; @group=[]; @opts={}; end
attr_accessor :name, :version
attr_reader :group, :opts
def opts=(new_opts={})
new_group = new_opts.delete(:group)
if (new_group && self.group != new_group)
@group = ([self.group].flatten + [new_group].flatten).compact.uniq.sort
end
@opts = (self.opts || {}).merge(new_opts)
end
def group_key() @group end
def gem_args_string
args = ["'#{@name}'"]
args << "'#{@version}'" if @version
@opts.each do |name,value|
args << ":#{name}=>#{value.inspect}"
end
args.join(', ')
end
end
@geminfo = {}
class << self
# add(name, version, opts={})
def add(name, *args)
name = name.to_s
version = args.first && !args.first.is_a?(Hash) ? args.shift : nil
opts = args.first && args.first.is_a?(Hash) ? args.shift : {}
@geminfo[name] = (@geminfo[name] || GemInfo.new(name)).tap do |info|
info.version = version if version
info.opts = opts
end
end
def write
File.open('Gemfile', 'a') do |file|
file.puts
grouped_gem_names.sort.each do |group, gem_names|
indent = ""
unless group.empty?
file.puts "group :#{group.join(', :')} do" unless group.empty?
indent=" "
end
gem_names.sort.each do |gem_name|
file.puts "#{indent}gem #{@geminfo[gem_name].gem_args_string}"
end
file.puts "end" unless group.empty?
file.puts
end
end
end
private
#returns {group=>[...gem names...]}, ie {[:development, :test]=>['rspec-rails', 'mocha'], :assets=>[], ...}
def grouped_gem_names
{}.tap do |_groups|
@geminfo.each do |gem_name, geminfo|
(_groups[geminfo.group_key] ||= []).push(gem_name)
end
end
end
end
end
def add_gem(*all) Gemfile.add(*all); end
@recipes = ["core", "git", "railsapps", "learn_rails", "rails_bootstrap", "rails_foundation", "rails_omniauth", "rails_devise", "rails_devise_roles", "rails_devise_pundit", "rails_shortcut_app", "rails_signup_download", "rails_signup_thankyou", "rails_mailinglist_activejob", "rails_stripe_checkout", "rails_stripe_coupons", "rails_stripe_membership_saas", "setup", "locale", "readme", "gems", "tests", "email", "devise", "omniauth", "roles", "frontend", "pages", "init", "analytics", "deployment", "extras"]
@prefs = {}
@gems = []
@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"], ["email", "extras", "frontend", "gems", "git", "init", "railsapps", "readme", "setup", "testing"], ["core", "email", "extras", "frontend", "gems", "git", "init", "railsapps", "readme", "setup", "testing"], ["core", "email", "extras", "frontend", "gems", "git", "init", "railsapps", "readme", "setup", "testing"], ["core", "email", "extras", "frontend", "gems", "git", "init", "railsapps", "readme", "setup", "testing"], ["email", "example", "extras", "frontend", "gems", "git", "init", "railsapps", "readme", "setup", "testing"], ["email", "example", "extras", "frontend", "gems", "git", "init", "railsapps", "readme", "setup", "testing"], ["email", "example", "extras", "frontend", "gems", "git", "init", "railsapps", "readme", "setup", "testing"], ["apps4", "core", "email", "extras", "frontend", "gems", "git", "init", "railsapps", "readme", "setup", "testing"], ["apps4", "core", "email", "extras", "frontend", "gems", "git", "init", "railsapps", "readme", "setup", "tests"], ["apps4", "core", "deployment", "email", "extras", "frontend", "gems", "git", "init", "railsapps", "readme", "setup", "testing"], ["apps4", "core", "deployment", "email", "extras", "frontend", "gems", "git", "init", "railsapps", "readme", "setup", "tests"], ["apps4", "core", "deployment", "devise", "email", "extras", "frontend", "gems", "git", "init", "omniauth", "pundit", "railsapps", "readme", "setup", "tests"]]
@diagnostics_prefs = []
diagnostics = {}
# >-------------------------- templates/helpers.erb --------------------------start<
def recipes; @recipes end
def recipe?(name); @recipes.include?(name) end
def prefs; @prefs end
def prefer(key, value); @prefs[key].eql? value end
def gems; @gems end
def diagnostics_recipes; @diagnostics_recipes end
def diagnostics_prefs; @diagnostics_prefs end
def say_custom(tag, text); say "\033[1m\033[36m" + tag.to_s.rjust(10) + "\033[0m" + " #{text}" end
def say_loud(tag, text); say "\033[1m\033[36m" + tag.to_s.rjust(10) + " #{text}" + "\033[0m" end
def say_recipe(name); say "\033[1m\033[36m" + "recipe".rjust(10) + "\033[0m" + " Running #{name} recipe..." end
def say_wizard(text); say_custom(@current_recipe || 'composer', text) end
def ask_wizard(question)
ask "\033[1m\033[36m" + ("option").rjust(10) + "\033[1m\033[36m" + " #{question}\033[0m"
end
def whisper_ask_wizard(question)
ask "\033[1m\033[36m" + ("choose").rjust(10) + "\033[0m" + " #{question}"
end
def yes_wizard?(question)
answer = ask_wizard(question + " \033[33m(y/n)\033[0m")
case answer.downcase
when "yes", "y"
true
when "no", "n"
false
else
yes_wizard?(question)
end
end
def no_wizard?(question); !yes_wizard?(question) end
def multiple_choice(question, choices)
say_custom('option', "\033[1m\033[36m" + "#{question}\033[0m")
values = {}
choices.each_with_index do |choice,i|
values[(i + 1).to_s] = choice[1]
say_custom( (i + 1).to_s + ')', choice[0] )
end
answer = whisper_ask_wizard("Enter your selection:") while !values.keys.include?(answer)
values[answer]
end
@current_recipe = nil
@configs = {}
@after_blocks = []
def stage_two(&block); @after_blocks << [@current_recipe, block]; end
@stage_three_blocks = []
def stage_three(&block); @stage_three_blocks << [@current_recipe, block]; end
@stage_four_blocks = []
def stage_four(&block); @stage_four_blocks << [@current_recipe, block]; end
@before_configs = {}
def before_config(&block); @before_configs[@current_recipe] = block; end
def copy_from(source, destination)
begin
remove_file destination
get source, destination
rescue OpenURI::HTTPError
say_wizard "Unable to obtain #{source}"
end
end
def copy_from_repo(filename, opts = {})
repo = 'https://raw.github.com/RailsApps/rails-composer/master/files/'
repo = opts[:repo] unless opts[:repo].nil?
if (!opts[:prefs].nil?) && (!prefs.has_value? opts[:prefs])
return
end
source_filename = filename
destination_filename = filename
unless opts[:prefs].nil?
if filename.include? opts[:prefs]
destination_filename = filename.gsub(/\-#{opts[:prefs]}/, '')
end
end
if (prefer :templates, 'haml') && (filename.include? 'views')
remove_file destination_filename
destination_filename = destination_filename.gsub(/.erb/, '.haml')
end
if (prefer :templates, 'slim') && (filename.include? 'views')
remove_file destination_filename
destination_filename = destination_filename.gsub(/.erb/, '.slim')
end
begin
remove_file destination_filename
if (prefer :templates, 'haml') && (filename.include? 'views')
create_file destination_filename, html_to_haml(repo + source_filename)
elsif (prefer :templates, 'slim') && (filename.include? 'views')
create_file destination_filename, html_to_slim(repo + source_filename)
else
get repo + source_filename, destination_filename
end
rescue OpenURI::HTTPError
say_wizard "Unable to obtain #{source_filename} from the repo #{repo}"
end
end
def html_to_haml(source)
begin
html = open(source) {|input| input.binmode.read }
Html2haml::HTML.new(html, :erb => true, :xhtml => true).render
rescue RubyParser::SyntaxError
say_wizard "Ignoring RubyParser::SyntaxError"
# special case to accommodate https://github.com/RailsApps/rails-composer/issues/55
html = open(source) {|input| input.binmode.read }
say_wizard "applying patch" if html.include? 'card_month'
say_wizard "applying patch" if html.include? 'card_year'
html = html.gsub(/, {add_month_numbers: true}, {name: nil, id: "card_month"}/, '')
html = html.gsub(/, {start_year: Date\.today\.year, end_year: Date\.today\.year\+10}, {name: nil, id: "card_year"}/, '')
result = Html2haml::HTML.new(html, :erb => true, :xhtml => true).render
result = result.gsub(/select_month nil/, "select_month nil, {add_month_numbers: true}, {name: nil, id: \"card_month\"}")
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\"}")
end
end
def html_to_slim(source)
html = open(source) {|input| input.binmode.read }
haml = Html2haml::HTML.new(html, :erb => true, :xhtml => true).render
Haml2Slim.convert!(haml)
end
# full credit to @mislav in this StackOverflow answer for the #which() method:
# - http://stackoverflow.com/a/5471032
def which(cmd)
exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : ['']
ENV['PATH'].split(File::PATH_SEPARATOR).each do |path|
exts.each do |ext|
exe = "#{path}#{File::SEPARATOR}#{cmd}#{ext}"
return exe if File.executable? exe
end
end
return nil
end
# >-------------------------- templates/helpers.erb --------------------------end<
say_wizard("\033[1m\033[36m" + "" + "\033[0m")
say_wizard("\033[1m\033[36m" + ' _____ _ _' + "\033[0m")
say_wizard("\033[1m\033[36m" + "| __ \\ \(_\) | /\\" + "\033[0m")
say_wizard("\033[1m\033[36m" + "| |__) |__ _ _| |___ / \\ _ __ _ __ ___" + "\033[0m")
say_wizard("\033[1m\033[36m" + "| _ /\/ _` | | / __| / /\\ \\ | \'_ \| \'_ \\/ __|" + "\033[0m")
say_wizard("\033[1m\033[36m" + "| | \\ \\ (_| | | \\__ \\/ ____ \\| |_) | |_) \\__ \\" + "\033[0m")
say_wizard("\033[1m\033[36m" + "|_| \\_\\__,_|_|_|___/_/ \\_\\ .__/| .__/|___/" + "\033[0m")
say_wizard("\033[1m\033[36m" + " \| \| \| \|" + "\033[0m")
say_wizard("\033[1m\033[36m" + " \| \| \| \|" + "\033[0m")
say_wizard("\033[1m\033[36m" + '' + "\033[0m")
say_wizard("Need help? Ask on Stack Overflow with the tag \'railsapps.\'")
say_wizard("Your new application will contain diagnostics in its README file.")
if diagnostics_recipes.sort.include? recipes.sort
diagnostics[:recipes] = 'success'
else
diagnostics[:recipes] = 'fail'
end
# this application template only supports Rails version 4.1 and newer
case Rails::VERSION::MAJOR.to_s
when "5"
say_wizard "You are using Rails version #{Rails::VERSION::STRING}. Please report any issues."
when "3"
say_wizard "You are using Rails version #{Rails::VERSION::STRING} which is not supported. Use Rails 4.1 or newer."
raise StandardError.new "Rails #{Rails::VERSION::STRING} is not supported. Use Rails 4.1 or newer."
when "4"
case Rails::VERSION::MINOR.to_s
when "0"
say_wizard "You are using Rails version #{Rails::VERSION::STRING} which is not supported. Use Rails 4.1 or newer."
raise StandardError.new "Rails #{Rails::VERSION::STRING} is not supported. Use Rails 4.1 or newer."
end
else
say_wizard "You are using Rails version #{Rails::VERSION::STRING} which is not supported. Use Rails 4.1 or newer."
raise StandardError.new "Rails #{Rails::VERSION::STRING} is not supported. Use Rails 4.1 or newer."
end
# >---------------------------[ Autoload Modules/Classes ]-----------------------------<
inject_into_file 'config/application.rb', :after => 'config.autoload_paths += %W(#{config.root}/extras)' do <<-'RUBY'
config.autoload_paths += %W(#{config.root}/lib)
RUBY
end
# >---------------------------------[ Recipes ]----------------------------------<
# >-------------------------- templates/recipe.erb ---------------------------start<
# >---------------------------------[ core ]----------------------------------<
@current_recipe = "core"
@before_configs["core"].call if @before_configs["core"]
say_recipe 'core'
@configs[@current_recipe] = config
# >----------------------------- recipes/core.rb -----------------------------start<
# Application template recipe for the rails_apps_composer. Change the recipe here:
# https://github.com/RailsApps/rails_apps_composer/blob/master/recipes/core.rb
## Git
say_wizard "selected all core recipes"
# >----------------------------- recipes/core.rb -----------------------------end<
# >-------------------------- templates/recipe.erb ---------------------------end<
# >-------------------------- templates/recipe.erb ---------------------------start<
# >----------------------------------[ git ]----------------------------------<
@current_recipe = "git"
@before_configs["git"].call if @before_configs["git"]
say_recipe 'git'
@configs[@current_recipe] = config
# >----------------------------- recipes/git.rb ------------------------------start<
# Application template recipe for the rails_apps_composer. Change the recipe here:
# https://github.com/RailsApps/rails_apps_composer/blob/master/recipes/git.rb
## Git
say_wizard "initialize git"
prefs[:git] = true unless prefs.has_key? :git
if prefer :git, true
copy_from 'https://raw.github.com/RailsApps/rails-composer/master/files/gitignore.txt', '.gitignore'
git :init
git :add => '-A'
git :commit => '-qm "rails_apps_composer: initial commit"'
else
stage_three do
say_wizard "recipe stage three"
say_wizard "removing .gitignore and .gitkeep files"
git_files = Dir[File.join('**','.gitkeep')] + Dir[File.join('**','.gitignore')]
File.unlink git_files
end
end
# >----------------------------- recipes/git.rb ------------------------------end<
# >-------------------------- templates/recipe.erb ---------------------------end<
# >-------------------------- templates/recipe.erb ---------------------------start<
# >-------------------------------[ railsapps ]-------------------------------<
@current_recipe = "railsapps"
@before_configs["railsapps"].call if @before_configs["railsapps"]
say_recipe 'railsapps'
@configs[@current_recipe] = config
# >-------------------------- recipes/railsapps.rb ---------------------------start<
# Application template recipe for the rails_apps_composer. Change the recipe here:
# https://github.com/RailsApps/rails_apps_composer/blob/master/recipes/railsapps.rb
raise if (defined? defaults) || (defined? preferences) # Shouldn't happen.
if options[:verbose]
print "\nrecipes: ";p recipes
print "\ngems: " ;p gems
print "\nprefs: " ;p prefs
print "\nconfig: " ;p config
end
case Rails::VERSION::MAJOR.to_s
when "5"
prefs[:apps4] = multiple_choice "Build a starter application?",
[["Build a RailsApps example application", "railsapps"],
["Contributed applications", "contributed_app"],
["Custom application (experimental)", "none"]] unless prefs.has_key? :apps4
case prefs[:apps4]
when 'railsapps'
prefs[:apps4] = multiple_choice "Choose a starter application.",
[["learn-rails", "learn-rails"],
["rails-bootstrap", "rails-bootstrap"],
["rails-foundation", "rails-foundation"],
["rails-mailinglist-activejob", "rails-mailinglist-activejob"],
["rails-omniauth", "rails-omniauth"],
["rails-devise", "rails-devise"],
["rails-devise-roles", "rails-devise-roles"],
["rails-devise-pundit", "rails-devise-pundit"],
["rails-signup-download", "rails-signup-download"],
["rails-stripe-checkout", "rails-stripe-checkout"],
["rails-stripe-coupons", "rails-stripe-coupons"]]
when 'contributed_app'
prefs[:apps4] = multiple_choice "Choose a starter application.",
[["rails-shortcut-app", "rails-shortcut-app"],
["rails-signup-thankyou", "rails-signup-thankyou"]]
end
when "3"
say_wizard "Please upgrade to Rails 4.1 or newer."
when "4"
case Rails::VERSION::MINOR.to_s
when "0"
say_wizard "Please upgrade to Rails 4.1 or newer."
else
prefs[:apps4] = multiple_choice "Build a starter application?",
[["Build a RailsApps example application", "railsapps"],
["Contributed applications (none available)", "contributed_app"],
["Custom application (experimental)", "none"]] unless prefs.has_key? :apps4
case prefs[:apps4]
when 'railsapps'
case Rails::VERSION::MINOR.to_s
when "2"
prefs[:apps4] = multiple_choice "Choose a starter application.",
[["learn-rails", "learn-rails"],
["rails-bootstrap", "rails-bootstrap"],
["rails-foundation", "rails-foundation"],
["rails-mailinglist-activejob", "rails-mailinglist-activejob"],
["rails-omniauth", "rails-omniauth"],
["rails-devise", "rails-devise"],
["rails-devise-roles", "rails-devise-roles"],
["rails-devise-pundit", "rails-devise-pundit"],
["rails-signup-download", "rails-signup-download"],
["rails-stripe-checkout", "rails-stripe-checkout"],
["rails-stripe-coupons", "rails-stripe-coupons"],
["rails-stripe-membership-saas", "rails-stripe-membership-saas"]]
else
prefs[:apps4] = multiple_choice "Upgrade to Rails 4.2 for more choices.",
[["learn-rails", "learn-rails"],
["rails-bootstrap", "rails-bootstrap"],
["rails-foundation", "rails-foundation"],
["rails-omniauth", "rails-omniauth"],
["rails-devise", "rails-devise"],
["rails-devise-roles", "rails-devise-roles"],
["rails-devise-pundit", "rails-devise-pundit"]]
end
when 'contributed_app'
prefs[:apps4] = multiple_choice "No contributed applications are available.",
[["create custom application", "railsapps"]]
end
end
end
unless prefs[:announcements]
say_loud '', 'Get on the mailing list for Rails Composer news?'
prefs[:announcements] = ask_wizard('Enter your email address:')
if prefs[:announcements].present?
system "curl --silent http://mailinglist.railscomposer.com/api -d'visitor[email]=#{prefs[:announcements]}' > /dev/null"
prefs[:announcements] = 'mailinglist'
else
prefs[:announcements] = 'none'
end
end
# >-------------------------- recipes/railsapps.rb ---------------------------end<
# >-------------------------- templates/recipe.erb ---------------------------end<
# >-------------------------- templates/recipe.erb ---------------------------start<
# >------------------------------[ learn_rails ]------------------------------<
@current_recipe = "learn_rails"
@before_configs["learn_rails"].call if @before_configs["learn_rails"]
say_recipe 'learn_rails'
@configs[@current_recipe] = config
# >------------------------- recipes/learn_rails.rb --------------------------start<
# Application template recipe for the rails_apps_composer. Change the recipe here:
# https://github.com/RailsApps/rails_apps_composer/blob/master/recipes/learn_rails.rb
if prefer :apps4, 'learn-rails'
# preferences
prefs[:authentication] = false
prefs[:authorization] = false
prefs[:dashboard] = 'none'
prefs[:ban_spiders] = false
prefs[:better_errors] = true
prefs[:database] = 'sqlite'
prefs[:deployment] = 'heroku'
prefs[:devise_modules] = false
prefs[:dev_webserver] = 'puma'
prefs[:email] = 'sendgrid'
prefs[:frontend] = 'bootstrap3'
prefs[:layouts] = 'none'
prefs[:pages] = 'none'
prefs[:github] = false
prefs[:git] = true
prefs[:local_env_file] = 'none'
prefs[:prod_webserver] = 'same'
prefs[:pry] = false
prefs[:secrets] = ['owner_email', 'mailchimp_list_id', 'mailchimp_api_key']
prefs[:templates] = 'erb'
prefs[:tests] = false
prefs[:locale] = 'none'
prefs[:analytics] = 'none'
prefs[:rubocop] = false
prefs[:disable_turbolinks] = false
prefs[:rvmrc] = true
if Rails::VERSION::MAJOR == 5 && Rails::VERSION::MINOR >= 1
prefs[:form_builder] = false
prefs[:jquery] = 'gem'
else
# Rails 5.0 version uses SimpleForm
prefs[:form_builder] = 'simple_form'
add_gem 'minitest-rails-capybara', :group => :test
end
# gems
add_gem 'high_voltage'
add_gem 'gibbon'
add_gem 'minitest-spec-rails', :group => :test
gsub_file 'Gemfile', /gem 'sqlite3'\n/, ''
add_gem 'sqlite3', :group => :development
stage_three do
say_wizard "recipe stage three"
repo = 'https://raw.github.com/RailsApps/learn-rails/master/'
# >-------------------------------[ Models ]--------------------------------<
copy_from_repo 'app/models/contact.rb', :repo => repo
copy_from_repo 'app/models/visitor.rb', :repo => repo
# >-------------------------------[ Controllers ]--------------------------------<
copy_from_repo 'app/controllers/contacts_controller.rb', :repo => repo
copy_from_repo 'app/controllers/visitors_controller.rb', :repo => repo
# >-------------------------------[ Mailers ]--------------------------------<
generate 'mailer UserMailer'
copy_from_repo 'app/mailers/user_mailer.rb', :repo => repo
# >-------------------------------[ Views ]--------------------------------<
if Rails::VERSION::MAJOR == 5 && Rails::VERSION::MINOR >= 1
copy_from_repo 'app/views/visitors/new.html.erb', :repo => repo
copy_from_repo 'app/views/contacts/new.html.erb', :repo => repo
else
# Rails 5.0 version uses SimpleForm
copy_from_repo 'app/views/visitors/new.html.erb', :repo => 'https://raw.githubusercontent.com/RailsApps/learn-rails/rails50/'
copy_from_repo 'app/views/contacts/new.html.erb', :repo => 'https://raw.githubusercontent.com/RailsApps/learn-rails/rails50/'
end
copy_from_repo 'app/views/pages/about.html.erb', :repo => repo
copy_from_repo 'app/views/user_mailer/contact_email.html.erb', :repo => repo
copy_from_repo 'app/views/user_mailer/contact_email.text.erb', :repo => repo
# create navigation links using the rails_layout gem
generate 'layout:navigation -f'
# >-------------------------------[ Routes ]--------------------------------<
copy_from_repo 'config/routes.rb', :repo => repo
# >-------------------------------[ Assets ]--------------------------------<
copy_from_repo 'app/assets/javascripts/segment.js', :repo => repo
# >-------------------------------[ Tests ]--------------------------------<
copy_from_repo 'test/test_helper.rb', :repo => repo
copy_from_repo 'test/integration/home_page_test.rb', :repo => repo
copy_from_repo 'test/models/visitor_test.rb', :repo => repo
run 'bundle exec rake db:migrate'
end
end
# >------------------------- recipes/learn_rails.rb --------------------------end<
# >-------------------------- templates/recipe.erb ---------------------------end<
# >-------------------------- templates/recipe.erb ---------------------------start<
# >----------------------------[ rails_bootstrap ]----------------------------<
@current_recipe = "rails_bootstrap"
@before_configs["rails_bootstrap"].call if @before_configs["rails_bootstrap"]
say_recipe 'rails_bootstrap'
@configs[@current_recipe] = config
# >----------------------- recipes/rails_bootstrap.rb ------------------------start<
# Application template recipe for the rails_apps_composer. Change the recipe here:
# https://github.com/RailsApps/rails_apps_composer/blob/master/recipes/rails_bootstrap.rb
if prefer :apps4, 'rails-bootstrap'
prefs[:authentication] = false
prefs[:authorization] = false
prefs[:dashboard] = 'none'
prefs[:better_errors] = true
prefs[:devise_modules] = false
prefs[:email] = 'none'
prefs[:git] = true
prefs[:local_env_file] = false
prefs[:pry] = false
prefs[:pages] = 'about'
prefs[:locale] = 'none'
prefs[:rubocop] = false
prefs[:frontend] = multiple_choice "Front-end framework?",
[["Bootstrap 4.0", "bootstrap4"], ["Bootstrap 3.3", "bootstrap3"]] unless prefs.has_key? :frontend
prefs[:rvmrc] = true
end
# >----------------------- recipes/rails_bootstrap.rb ------------------------end<
# >-------------------------- templates/recipe.erb ---------------------------end<
# >-------------------------- templates/recipe.erb ---------------------------start<
# >---------------------------[ rails_foundation ]----------------------------<
@current_recipe = "rails_foundation"
@before_configs["rails_foundation"].call if @before_configs["rails_foundation"]
say_recipe 'rails_foundation'
@configs[@current_recipe] = config
# >----------------------- recipes/rails_foundation.rb -----------------------start<
# Application template recipe for the rails_apps_composer. Change the recipe here:
# https://github.com/RailsApps/rails_apps_composer/blob/master/recipes/rails_foundation.rb
if prefer :apps4, 'rails-foundation'
prefs[:authentication] = false
prefs[:authorization] = false
prefs[:dashboard] = 'none'
prefs[:better_errors] = true
prefs[:devise_modules] = false
prefs[:email] = 'none'
prefs[:frontend] = 'foundation5'
prefs[:git] = true
prefs[:local_env_file] = false
prefs[:pry] = false
prefs[:pages] = 'about'
prefs[:locale] = 'none'
prefs[:rubocop] = false
prefs[:rvmrc] = true
end
# >----------------------- recipes/rails_foundation.rb -----------------------end<
# >-------------------------- templates/recipe.erb ---------------------------end<
# >-------------------------- templates/recipe.erb ---------------------------start<
# >----------------------------[ rails_omniauth ]-----------------------------<
@current_recipe = "rails_omniauth"
@before_configs["rails_omniauth"].call if @before_configs["rails_omniauth"]
say_recipe 'rails_omniauth'
@configs[@current_recipe] = config
# >------------------------ recipes/rails_omniauth.rb ------------------------start<
# Application template recipe for the rails_apps_composer. Change the recipe here:
# https://github.com/RailsApps/rails_apps_composer/blob/master/recipes/rails_omniauth.rb
if prefer :apps4, 'rails-omniauth'
prefs[:authentication] = 'omniauth'
prefs[:authorization] = 'none'
prefs[:dashboard] = 'none'
prefs[:better_errors] = true
prefs[:email] = 'none'
prefs[:git] = true
prefs[:local_env_file] = false
prefs[:pry] = false
prefs[:pages] = 'about+users'
prefs[:locale] = 'none'
prefs[:rubocop] = false
prefs[:rvmrc] = true
end
# >------------------------ recipes/rails_omniauth.rb ------------------------end<
# >-------------------------- templates/recipe.erb ---------------------------end<
# >-------------------------- templates/recipe.erb ---------------------------start<
# >-----------------------------[ rails_devise ]------------------------------<
@current_recipe = "rails_devise"
@before_configs["rails_devise"].call if @before_configs["rails_devise"]
say_recipe 'rails_devise'
@configs[@current_recipe] = config
# >------------------------- recipes/rails_devise.rb -------------------------start<
# Application template recipe for the rails_apps_composer. Change the recipe here:
# https://github.com/RailsApps/rails_apps_composer/blob/master/recipes/rails_devise.rb
if prefer :apps4, 'rails-devise'
prefs[:authentication] = 'devise'
prefs[:authorization] = false
prefs[:dashboard] = 'none'
prefs[:better_errors] = true
prefs[:git] = true
prefs[:local_env_file] = false
prefs[:pry] = false
prefs[:pages] = 'about+users'
prefs[:locale] = 'none'
prefs[:rubocop] = false
prefs[:rvmrc] = true
end
# >------------------------- recipes/rails_devise.rb -------------------------end<
# >-------------------------- templates/recipe.erb ---------------------------end<
# >-------------------------- templates/recipe.erb ---------------------------start<
# >--------------------------[ rails_devise_roles ]---------------------------<
@current_recipe = "rails_devise_roles"
@before_configs["rails_devise_roles"].call if @before_configs["rails_devise_roles"]
say_recipe 'rails_devise_roles'
@configs[@current_recipe] = config
# >---------------------- recipes/rails_devise_roles.rb ----------------------start<
# Application template recipe for the rails_apps_composer. Change the recipe here:
# https://github.com/RailsApps/rails_apps_composer/blob/master/recipes/rails_devise_roles.rb
if prefer :apps4, 'rails-devise-roles'
prefs[:authentication] = 'devise'
prefs[:authorization] = 'roles'
prefs[:better_errors] = true
prefs[:git] = true
prefs[:local_env_file] = false
prefs[:pry] = false
prefs[:pages] = 'about+users'
prefs[:locale] = 'none'
prefs[:rubocop] = false
prefs[:rvmrc] = true
end
# >---------------------- recipes/rails_devise_roles.rb ----------------------end<
# >-------------------------- templates/recipe.erb ---------------------------end<
# >-------------------------- templates/recipe.erb ---------------------------start<
# >--------------------------[ rails_devise_pundit ]--------------------------<
@current_recipe = "rails_devise_pundit"
@before_configs["rails_devise_pundit"].call if @before_configs["rails_devise_pundit"]
say_recipe 'rails_devise_pundit'
@configs[@current_recipe] = config
# >--------------------- recipes/rails_devise_pundit.rb ----------------------start<
# Application template recipe for the rails_apps_composer. Change the recipe here:
# https://github.com/RailsApps/rails_apps_composer/blob/master/recipes/rails_devise_pundit.rb
if prefer :apps4, 'rails-devise-pundit'
prefs[:authentication] = 'devise'
prefs[:authorization] = 'pundit'
prefs[:better_errors] = true
prefs[:git] = true
prefs[:local_env_file] = false
prefs[:pry] = false
prefs[:pages] = 'about+users'
prefs[:locale] = 'none'
prefs[:rubocop] = false
prefs[:rvmrc] = true
end
# >--------------------- recipes/rails_devise_pundit.rb ----------------------end<
# >-------------------------- templates/recipe.erb ---------------------------end<
# >-------------------------- templates/recipe.erb ---------------------------start<
# >--------------------------[ rails_shortcut_app ]---------------------------<
@current_recipe = "rails_shortcut_app"
@before_configs["rails_shortcut_app"].call if @before_configs["rails_shortcut_app"]
say_recipe 'rails_shortcut_app'
@configs[@current_recipe] = config
# >---------------------- recipes/rails_shortcut_app.rb ----------------------start<
# Application template recipe for the rails_apps_composer. Change the recipe here:
# https://github.com/RailsApps/rails_apps_composer/blob/master/recipes/rails_shortcut_app.rb
if prefer :apps4, 'rails-shortcut-app'
prefs[:authentication] = 'devise'
prefs[:authorization] = 'roles'
prefs[:dashboard] = 'none'
prefs[:ban_spiders] = false
prefs[:better_errors] = true
prefs[:database] = 'sqlite'
prefs[:deployment] = 'none'
prefs[:devise_modules] = false
prefs[:dev_webserver] = 'puma'
prefs[:email] = 'none'
prefs[:frontend] = 'bootstrap3'
prefs[:layouts] = 'none'
prefs[:pages] = 'none'
prefs[:github] = false
prefs[:git] = true
prefs[:local_env_file] = false
prefs[:prod_webserver] = 'same'
prefs[:pry] = false
prefs[:pages] = 'about+users'
prefs[:templates] = 'erb'
prefs[:tests] = 'none'
prefs[:locale] = 'none'
prefs[:analytics] = 'none'
prefs[:rubocop] = false
prefs[:disable_turbolinks] = true
prefs[:rvmrc] = true
prefs[:form_builder] = false
prefs[:jquery] = 'gem'
end
# >---------------------- recipes/rails_shortcut_app.rb ----------------------end<
# >-------------------------- templates/recipe.erb ---------------------------end<
# >-------------------------- templates/recipe.erb ---------------------------start<
# >-------------------------[ rails_signup_download ]-------------------------<
@current_recipe = "rails_signup_download"
@before_configs["rails_signup_download"].call if @before_configs["rails_signup_download"]
say_recipe 'rails_signup_download'
@configs[@current_recipe] = config
# >-------------------- recipes/rails_signup_download.rb ---------------------start<
# Application template recipe for the rails_apps_composer. Change the recipe here:
# https://github.com/RailsApps/rails_apps_composer/blob/master/recipes/rails_signup_download.rb
if prefer :apps4, 'rails-signup-download'
prefs[:authentication] = 'devise'
prefs[:authorization] = 'roles'
prefs[:better_errors] = true
prefs[:devise_modules] = false
prefs[:form_builder] = false
prefs[:git] = true
prefs[:local_env_file] = false
prefs[:pry] = false
prefs[:secrets] = ['mailchimp_list_id', 'mailchimp_api_key']
prefs[:pages] = 'about+users'
prefs[:locale] = 'none'
prefs[:rubocop] = false
prefs[:rvmrc] = true
# gems
add_gem 'gibbon'
add_gem 'sucker_punch'
stage_three do
say_wizard "recipe stage three"
repo = 'https://raw.github.com/RailsApps/rails-signup-download/master/'
# >-------------------------------[ Config ]---------------------------------<
copy_from_repo 'config/initializers/active_job.rb', :repo => repo
# >-------------------------------[ Models ]--------------------------------<
copy_from_repo 'app/models/user.rb', :repo => repo
# >-------------------------------[ Controllers ]--------------------------------<
copy_from_repo 'app/controllers/visitors_controller.rb', :repo => repo
copy_from_repo 'app/controllers/products_controller.rb', :repo => repo
# >-------------------------------[ Jobs ]---------------------------------<
copy_from_repo 'app/jobs/mailing_list_signup_job.rb', :repo => repo
# >-------------------------------[ Views ]--------------------------------<
copy_from_repo 'app/views/visitors/index.html.erb', :repo => repo
copy_from_repo 'app/views/products/product.pdf', :repo => repo
# >-------------------------------[ Routes ]--------------------------------<
copy_from_repo 'config/routes.rb', :repo => repo
# >-------------------------------[ Tests ]--------------------------------<
copy_from_repo 'spec/features/users/product_acquisition_spec.rb', :repo => repo
copy_from_repo 'spec/controllers/products_controller_spec.rb', :repo => repo
end
end
# >-------------------- recipes/rails_signup_download.rb ---------------------end<
# >-------------------------- templates/recipe.erb ---------------------------end<
# >-------------------------- templates/recipe.erb ---------------------------start<
# >-------------------------[ rails_signup_thankyou ]-------------------------<
@current_recipe = "rails_signup_thankyou"
@before_configs["rails_signup_thankyou"].call if @before_configs["rails_signup_thankyou"]
say_recipe 'rails_signup_thankyou'
@configs[@current_recipe] = config
# >-------------------- recipes/rails_signup_thankyou.rb ---------------------start<
# Application template recipe for the rails_apps_composer. Change the recipe here:
# https://github.com/RailsApps/rails_apps_composer/blob/master/recipes/rails_signup_thankyou.rb
if prefer :apps4, 'rails-signup-thankyou'
prefs[:authentication] = 'devise'
prefs[:authorization] = 'roles'
prefs[:dashboard] = 'none'
prefs[:ban_spiders] = false
prefs[:better_errors] = true
prefs[:database] = 'sqlite'
prefs[:deployment] = 'none'
prefs[:devise_modules] = false
prefs[:dev_webserver] = 'puma'
prefs[:email] = 'none'
prefs[:frontend] = 'bootstrap3'
prefs[:layouts] = 'none'
prefs[:pages] = 'none'
prefs[:github] = false
prefs[:git] = true
prefs[:local_env_file] = false
prefs[:prod_webserver] = 'same'
prefs[:pry] = false
prefs[:pages] = 'about+users'
prefs[:templates] = 'erb'
prefs[:tests] = 'none'
prefs[:locale] = 'none'
prefs[:analytics] = 'none'
prefs[:rubocop] = false
prefs[:disable_turbolinks] = true
prefs[:rvmrc] = true
prefs[:form_builder] = false
prefs[:jquery] = 'gem'
stage_three do
say_wizard "recipe stage three"
repo = 'https://raw.github.com/RailsApps/rails-signup-thankyou/master/'
# >-------------------------------[ Models ]--------------------------------<
copy_from_repo 'app/models/user.rb', :repo => repo
# >-------------------------------[ Controllers ]--------------------------------<
copy_from_repo 'app/controllers/application_controller.rb', :repo => repo
copy_from_repo 'app/controllers/visitors_controller.rb', :repo => repo
copy_from_repo 'app/controllers/products_controller.rb', :repo => repo
copy_from_repo 'app/controllers/thank_you_controller.rb', :repo => repo
# >-------------------------------[ Views ]--------------------------------<
copy_from_repo 'app/views/visitors/index.html.erb', :repo => repo
copy_from_repo 'app/views/products/product.pdf', :repo => repo
copy_from_repo 'app/views/thank_you/index.html.erb', :repo => repo
# >-------------------------------[ Routes ]--------------------------------<
copy_from_repo 'config/routes.rb', :repo => repo
# >-------------------------------[ Tests ]--------------------------------<
copy_from_repo 'spec/features/users/product_acquisition_spec.rb', :repo => repo
copy_from_repo 'spec/controllers/products_controller_spec.rb', :repo => repo
end
end
# >-------------------- recipes/rails_signup_thankyou.rb ---------------------end<
# >-------------------------- templates/recipe.erb ---------------------------end<
# >-------------------------- templates/recipe.erb ---------------------------start<
# >----------------------[ rails_mailinglist_activejob ]----------------------<
@current_recipe = "rails_mailinglist_activejob"
@before_configs["rails_mailinglist_activejob"].call if @before_configs["rails_mailinglist_activejob"]
say_recipe 'rails_mailinglist_activejob'
@configs[@current_recipe] = config
# >----------------- recipes/rails_mailinglist_activejob.rb ------------------start<
# Application template recipe for the rails_apps_composer. Change the recipe here:
# https://github.com/RailsApps/rails_apps_composer/blob/master/recipes/rails_mailinglist_activejob.rb
if prefer :apps4, 'rails-mailinglist-activejob'
prefs[:authentication] = false
prefs[:authorization] = false
prefs[:dashboard] = 'none'
prefs[:better_errors] = true
prefs[:form_builder] = 'simple_form'
prefs[:git] = true
prefs[:local_env_file] = false
prefs[:pry] = false
prefs[:secrets] = ['mailchimp_list_id', 'mailchimp_api_key']
prefs[:pages] = 'about'
prefs[:locale] = 'none'
prefs[:rubocop] = false
prefs[:rvmrc] = true
# gems
add_gem 'gibbon'
add_gem 'high_voltage'
add_gem 'sucker_punch'
stage_two do
say_wizard "recipe stage two"
generate 'model Visitor email:string'
end
stage_three do
say_wizard "recipe stage three"
repo = 'https://raw.github.com/RailsApps/rails-mailinglist-activejob/master/'
# >-------------------------------[ Config ]---------------------------------<
copy_from_repo 'config/initializers/active_job.rb', :repo => repo
# >-------------------------------[ Models ]--------------------------------<
copy_from_repo 'app/models/visitor.rb', :repo => repo
# >-------------------------------[ Controllers ]--------------------------<
copy_from_repo 'app/controllers/visitors_controller.rb', :repo => repo
# >-------------------------------[ Jobs ]---------------------------------<
copy_from_repo 'app/jobs/mailing_list_signup_job.rb', :repo => repo
# >-------------------------------[ Views ]--------------------------------<
remove_file 'app/views/visitors/index.html.erb'
copy_from_repo 'app/views/visitors/new.html.erb', :repo => repo
# >-------------------------------[ Routes ]-------------------------------<
gsub_file 'config/routes.rb', / root to: 'visitors#index'\n/, ''
inject_into_file 'config/routes.rb', " root to: 'visitors#new'\n", :after => "routes.draw do\n"
route = ' resources :visitors, only: [:new, :create]'
inject_into_file 'config/routes.rb', route + "\n", :after => "routes.draw do\n"
# >-------------------------------[ Tests ]--------------------------------<
### tests not implemented
end
end
# >----------------- recipes/rails_mailinglist_activejob.rb ------------------end<
# >-------------------------- templates/recipe.erb ---------------------------end<
# >-------------------------- templates/recipe.erb ---------------------------start<
# >-------------------------[ rails_stripe_checkout ]-------------------------<
@current_recipe = "rails_stripe_checkout"
@before_configs["rails_stripe_checkout"].call if @before_configs["rails_stripe_checkout"]
say_recipe 'rails_stripe_checkout'
@configs[@current_recipe] = config
# >-------------------- recipes/rails_stripe_checkout.rb ---------------------start<
# Application template recipe for the rails_apps_composer. Change the recipe here:
# https://github.com/RailsApps/rails_apps_composer/blob/master/recipes/rails_stripe_checkout.rb
if prefer :apps4, 'rails-stripe-checkout'