intersect_rails_composer 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. checksums.yaml +7 -0
  2. data/README.textile +433 -0
  3. data/bin/intersect_rails_composer +7 -0
  4. data/lib/rails_wizard/command.rb +204 -0
  5. data/lib/rails_wizard/config.rb +88 -0
  6. data/lib/rails_wizard/diagnostics.rb +68 -0
  7. data/lib/rails_wizard/recipe.rb +114 -0
  8. data/lib/rails_wizard/recipes.rb +56 -0
  9. data/lib/rails_wizard/template.rb +111 -0
  10. data/lib/rails_wizard.rb +7 -0
  11. data/recipes/apps4.rb +150 -0
  12. data/recipes/controllers.rb +75 -0
  13. data/recipes/core.rb +14 -0
  14. data/recipes/email.rb +110 -0
  15. data/recipes/example.rb +70 -0
  16. data/recipes/extras.rb +187 -0
  17. data/recipes/frontend.rb +45 -0
  18. data/recipes/gems.rb +277 -0
  19. data/recipes/git.rb +20 -0
  20. data/recipes/init.rb +136 -0
  21. data/recipes/models.rb +109 -0
  22. data/recipes/prelaunch.rb +119 -0
  23. data/recipes/railsapps.rb +277 -0
  24. data/recipes/readme.rb +85 -0
  25. data/recipes/routes.rb +45 -0
  26. data/recipes/saas.rb +218 -0
  27. data/recipes/setup.rb +134 -0
  28. data/recipes/testing.rb +276 -0
  29. data/recipes/views.rb +57 -0
  30. data/spec/rails_wizard/config_spec.rb +108 -0
  31. data/spec/rails_wizard/recipe_spec.rb +115 -0
  32. data/spec/rails_wizard/recipes/sanity_spec.rb +30 -0
  33. data/spec/rails_wizard/recipes_spec.rb +41 -0
  34. data/spec/rails_wizard/template_spec.rb +92 -0
  35. data/spec/spec_helper.rb +11 -0
  36. data/spec/support/rails_directory.rb +17 -0
  37. data/spec/support/template_runner.rb +28 -0
  38. data/spec/test_recipes/test_recipe_in_file.rb +9 -0
  39. data/templates/helpers.erb +135 -0
  40. data/templates/layout.erb +232 -0
  41. data/templates/recipe.erb +13 -0
  42. data/version.rb +3 -0
  43. metadata +210 -0
@@ -0,0 +1,88 @@
1
+ require 'active_support/ordered_hash'
2
+
3
+ module RailsWizard
4
+ class Config
5
+ attr_reader :questions, :defaults
6
+
7
+ def initialize(schema, defaults=nil)
8
+ @questions = ActiveSupport::OrderedHash.new
9
+ @defaults = defaults
10
+ schema.each do |hash|
11
+ key = hash.keys.first
12
+ details = hash.values.first
13
+
14
+ kind = details['type']
15
+ raise ArgumentError, "Unrecognized question type, must be one of #{QUESTION_TYPES.keys.join(', ')}" unless QUESTION_TYPES.keys.include?(kind)
16
+ @questions[key] = QUESTION_TYPES[kind].new(details)
17
+ end
18
+ end
19
+
20
+ def compile(values = {})
21
+ result = []
22
+ values.merge!(defaults) if defaults
23
+ result << "config = #{values.inspect}"
24
+ @questions.each_pair do |key, question|
25
+ result << "config['#{key}'] = #{question.compile} unless config.key?('#{key}') || prefs.has_key?(:#{key})"
26
+ end
27
+ result.join("\n")
28
+ end
29
+
30
+ class Prompt
31
+ attr_reader :prompt, :details
32
+ def initialize(details)
33
+ @details = details
34
+ @prompt = details['prompt']
35
+ end
36
+
37
+ def compile
38
+ "#{question} if #{conditions}"
39
+ end
40
+
41
+ def question
42
+ "ask_wizard(#{prompt.inspect})"
43
+ end
44
+
45
+ def conditions
46
+ [config_conditions, recipe_conditions].join(' && ')
47
+ end
48
+
49
+ def config_conditions
50
+ if details['if']
51
+ "config['#{details['if']}']"
52
+ elsif details['unless']
53
+ "!config['#{details['unless']}']"
54
+ else
55
+ 'true'
56
+ end
57
+ end
58
+
59
+ def recipe_conditions
60
+ if details['if_recipe']
61
+ "recipe?('#{details['if_recipe']}')"
62
+ elsif details['unless_recipe']
63
+ "!recipe?('#{details['unless_recipe']}')"
64
+ else
65
+ 'true'
66
+ end
67
+ end
68
+ end
69
+
70
+ class TrueFalse < Prompt
71
+ def question
72
+ "yes_wizard?(#{prompt.inspect})"
73
+ end
74
+ end
75
+
76
+ class MultipleChoice < Prompt
77
+ def question
78
+ "multiple_choice(#{prompt.inspect}, #{@details['choices'].inspect})"
79
+ end
80
+ end
81
+
82
+ QUESTION_TYPES = {
83
+ 'boolean' => TrueFalse,
84
+ 'string' => Prompt,
85
+ 'multiple_choice' => MultipleChoice
86
+ }
87
+ end
88
+ end
@@ -0,0 +1,68 @@
1
+ module RailsWizard
2
+ module Diagnostics
3
+
4
+ ### collections of recipes that are known to work together
5
+ @@recipes = []
6
+ @@recipes << %w(example)
7
+ @@recipes << %w(setup)
8
+ @@recipes << %w(railsapps)
9
+ @@recipes << %w(gems setup)
10
+ @@recipes << %w(gems readme setup)
11
+ @@recipes << %w(extras gems readme setup)
12
+ @@recipes << %w(example git)
13
+ @@recipes << %w(git setup)
14
+ @@recipes << %w(git railsapps)
15
+ @@recipes << %w(gems git setup)
16
+ @@recipes << %w(gems git readme setup)
17
+ @@recipes << %w(extras gems git readme setup)
18
+ @@recipes << %w(controllers email extras frontend gems git init models railsapps readme routes setup testing views)
19
+ @@recipes << %w(controllers core email extras frontend gems git init models railsapps readme routes setup testing views)
20
+ @@recipes << %w(controllers core email extras frontend gems git init models prelaunch railsapps readme routes setup testing views)
21
+ @@recipes << %w(controllers core email extras frontend gems git init models prelaunch railsapps readme routes saas setup testing views)
22
+ @@recipes << %w(controllers email example extras frontend gems git init models railsapps readme routes setup testing views)
23
+ @@recipes << %w(controllers email example extras frontend gems git init models prelaunch railsapps readme routes setup testing views)
24
+ @@recipes << %w(controllers email example extras frontend gems git init models prelaunch railsapps readme routes saas setup testing views)
25
+ @@recipes << %w(apps4 controllers core email extras frontend gems git init models prelaunch railsapps readme routes saas setup testing views)
26
+
27
+ ### collections of preferences that are known to work together
28
+
29
+ # ignore these preferences (because they don't cause conflicts)
30
+ # :ban_spiders
31
+ # :better_errors
32
+ # :dev_webserver
33
+ # :git
34
+ # :github
35
+ # :jsruntime
36
+ # :local_env_file
37
+ # :main_branch
38
+ # :prelaunch_branch
39
+ # :prod_webserver
40
+ # :quiet_assets
41
+ # :rvmrc
42
+ # :templates
43
+
44
+ @@prefs = []
45
+ @@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"}
46
+ @@prefs << {: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"}
47
+ @@prefs << {: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"}
48
+ @@prefs << {: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"}
49
+ @@prefs << {: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"}
50
+ @@prefs << {: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=>true, :continuous_testing=>"none"}
51
+ @@prefs << {: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"}
52
+ @@prefs << {: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'}
53
+ @@prefs << {: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'}
54
+ @@prefs << {: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'}
55
+ @@prefs << {: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"}
56
+ @@prefs << {: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"}
57
+ @@prefs << {: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"}
58
+ @@prefs << {: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"}
59
+
60
+ def self.recipes
61
+ @@recipes
62
+ end
63
+
64
+ def self.prefs
65
+ @@prefs
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,114 @@
1
+ require 'rails_wizard/config'
2
+
3
+ require 'active_support/inflector'
4
+ require 'yaml'
5
+ require 'erb'
6
+
7
+ module RailsWizard
8
+ class Recipe
9
+ extend Comparable
10
+
11
+ def self.<=>(another)
12
+ return -1 if another.run_after.include?(self.key) || self.run_before.include?(another.key)
13
+ return 1 if another.run_before.include?(self.key) || self.run_after.include?(another.key)
14
+ self.key <=> another.key
15
+ end
16
+
17
+ ATTRIBUTES = %w(key args category name description template config exclusive tags run_before run_after requires defaults)
18
+ DEFAULT_ATTRIBUTES = {
19
+ :category => 'other',
20
+ :args => [],
21
+ :tags => [],
22
+ :run_after => [],
23
+ :run_before => [],
24
+ :requires => []
25
+ }
26
+
27
+ def self.generate(key, template_or_file, attributes = {})
28
+ if template_or_file.respond_to?(:read)
29
+ file = template_or_file.read
30
+ parts = file.split(/^__END__$/)
31
+ raise ArgumentError, "The recipe file must have YAML matter after an __END__" unless parts.size == 2
32
+ template = parts.first.strip
33
+ attributes = YAML.load(parts.last).inject({}) do |h,(k,v)|
34
+ h[k.to_sym] = v
35
+ h
36
+ end.merge!(attributes)
37
+ else
38
+ template = template_or_file
39
+ end
40
+
41
+ recipe_class = Class.new(RailsWizard::Recipe)
42
+ recipe_class.attributes = attributes
43
+ recipe_class.template = template
44
+ recipe_class.key = key
45
+
46
+ recipe_class
47
+ end
48
+
49
+ ATTRIBUTES.each do |setter|
50
+ class_eval <<-RUBY
51
+ def self.#{setter}
52
+ attributes[:#{setter}]
53
+ end
54
+
55
+ def self.#{setter}=(val)
56
+ attributes[:#{setter}] = val
57
+ end
58
+
59
+ def #{setter}
60
+ self.class.#{setter}
61
+ end
62
+ RUBY
63
+ end
64
+
65
+ # The attributes hash containing any set values for
66
+ def self.attributes
67
+ @attributes ||= DEFAULT_ATTRIBUTES.dup
68
+ end
69
+
70
+ def self.attributes=(hash)
71
+ attributes.merge! hash
72
+ end
73
+
74
+ def self.config
75
+ return nil unless attributes[:config]
76
+ RailsWizard::Config.new(attributes[:config], attributes[:defaults])
77
+ end
78
+
79
+ def attributes
80
+ self.class.attributes
81
+ end
82
+
83
+ def self.compile
84
+ "# >#{"[ #{name} ]".center(75,'-')}<\n\n# #{description}\nsay_recipe '#{name}'\n\n#{template}\n"
85
+ end
86
+ def compile; self.class.compile end
87
+
88
+ def self.to_mongo(value)
89
+ case value
90
+ when Class
91
+ value.key
92
+ when String
93
+ value
94
+ end
95
+ end
96
+
97
+ def self.from_mongo(key)
98
+ return key if (key.respond_to?(:superclass) && key.superclass == RailsWizard::Recipe)
99
+ return RailsWizard::Recipes[key] if RailsWizard::Recipes[key]
100
+ raise(RailsWizard::UnknownRecipeError.new(key))
101
+ end
102
+
103
+ def self.get_binding
104
+ binding
105
+ end
106
+ end
107
+
108
+ class UnknownRecipeError < StandardError
109
+ def initialize(key)
110
+ message = "No recipe found with name '#{key}'"
111
+ super(message)
112
+ end
113
+ end
114
+ end
@@ -0,0 +1,56 @@
1
+ module RailsWizard
2
+ module Recipes
3
+ @@categories = {}
4
+ @@list = {}
5
+
6
+ def self.add(recipe)
7
+ RailsWizard::Recipes.const_set ActiveSupport::Inflector.camelize(recipe.key), recipe
8
+ @@list[recipe.key] = recipe
9
+ (@@categories[recipe.category.to_s] ||= []) << recipe.key
10
+ @@categories[recipe.category.to_s].uniq!
11
+ recipe
12
+ end
13
+
14
+ def self.clear
15
+ self.list.each do |recipe_key|
16
+ send(:remove_const, ActiveSupport::Inflector.camelize(recipe_key))
17
+ end
18
+ @@categories = {}
19
+ @@list = {}
20
+ end
21
+
22
+ def self.[](key)
23
+ @@list[key.to_s]
24
+ end
25
+
26
+ def self.list
27
+ @@list.keys.sort
28
+ end
29
+
30
+ def self.list_classes
31
+ @@list.values.sort_by{|c| c.key}
32
+ end
33
+
34
+ def self.categories
35
+ @@categories.keys.sort
36
+ end
37
+
38
+ def self.for(category)
39
+ (@@categories[category.to_s] || []).sort
40
+ end
41
+
42
+ def self.remove_from_category(category, recipe)
43
+ (@@categories[category.to_s] ||= []).delete(recipe.key)
44
+ end
45
+
46
+ def self.add_from_directory(directory)
47
+ Dir.foreach(directory) do |file|
48
+ path = File.join(directory, file)
49
+ next unless path.match /\.rb$/
50
+ key = File.basename(path, '.rb')
51
+ recipe = Recipe.generate(key, File.open(path))
52
+ add(recipe)
53
+ end
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,111 @@
1
+ module RailsWizard
2
+ class Template
3
+ attr_reader :recipes, :gems, :args, :defaults
4
+
5
+ def initialize(recipes, gems=[], args=[], defaults={})
6
+ @recipes = recipes.map{|r| RailsWizard::Recipe.from_mongo(r)}
7
+ @args = args
8
+ @defaults = defaults
9
+ unless defaults['prefs'].nil?
10
+ @prefs = defaults['prefs']
11
+ else
12
+ @prefs = {}
13
+ end
14
+ unless defaults['gems'].nil?
15
+ @gems = gems | defaults['gems']
16
+ else
17
+ @gems = gems
18
+ end
19
+ end
20
+
21
+ def self.template_root
22
+ @template_root ||= File.dirname(__FILE__) + '/../../templates'
23
+ end
24
+
25
+ def self.template_root=(root)
26
+ @template_root = root
27
+ end
28
+
29
+ def self.render(template_name, binding = nil)
30
+ erb = ERB.new(File.open(template_root + '/' + template_name + '.erb').read)
31
+ erb.result(binding)
32
+ end
33
+ def render(template_name, binding = nil); self.class.render(template_name, binding) end
34
+
35
+ def resolve_preferences
36
+ @resolve_preferences ||= begin
37
+ @prefs.inspect
38
+ end
39
+ end
40
+
41
+ def resolve_gems
42
+ @resolve_gems ||= begin
43
+ @gems.uniq.inspect
44
+ end
45
+ end
46
+
47
+ def resolve_diagnostics_recipes
48
+ @resolve_diagnostics_recipes ||= begin
49
+ RailsWizard::Diagnostics.recipes.inspect
50
+ end
51
+ end
52
+
53
+ def resolve_diagnostics_prefs
54
+ @resolve_diagnostics_prefs ||= begin
55
+ RailsWizard::Diagnostics.prefs.inspect
56
+ end
57
+ end
58
+
59
+ # Sort the recipes list taking 'run_after' directives into account.
60
+ def resolve_recipes
61
+ @resolve_recipes ||= begin
62
+ list = recipes_with_dependencies
63
+
64
+ for i in 0...list.size
65
+ after_keys = list[i+1..-1].map { |r| r.key }
66
+
67
+ if (list[i].run_after & after_keys).any?
68
+ list.push list.slice!(i)
69
+ redo
70
+ end
71
+ end
72
+
73
+ list.each {|recipe| recipe.defaults = defaults[recipe.key] }
74
+ list
75
+ end
76
+ end
77
+
78
+ def recipe_classes
79
+ @recipe_classes ||= recipes.map{|r| RailsWizard::Recipe.from_mongo(r)}
80
+ end
81
+
82
+ def recipes_with_dependencies
83
+ @recipes_with_dependencies ||= recipe_classes
84
+
85
+ added_more = false
86
+ for recipe in recipe_classes
87
+ recipe.requires.each do |requirement|
88
+ requirement = RailsWizard::Recipe.from_mongo(requirement)
89
+ count = @recipes_with_dependencies.size
90
+ (@recipes_with_dependencies << requirement).uniq!
91
+ unless @recipes_with_dependencies.size == count
92
+ added_more = true
93
+ end
94
+ end
95
+ end
96
+
97
+ added_more ? recipes_with_dependencies : @recipes_with_dependencies
98
+ end
99
+
100
+ def compile
101
+ render 'layout', binding
102
+ end
103
+
104
+ def args
105
+ recipes.map(&:args).uniq
106
+ end
107
+
108
+ def custom_code?; false end
109
+ def custom_code; nil end
110
+ end
111
+ end
@@ -0,0 +1,7 @@
1
+ require 'rails_wizard/recipes'
2
+ require 'rails_wizard/recipe'
3
+ require 'rails_wizard/config'
4
+ require 'rails_wizard/diagnostics'
5
+ require 'rails_wizard/template'
6
+
7
+ RailsWizard::Recipes.add_from_directory(File.dirname(__FILE__) + '/../recipes')
data/recipes/apps4.rb ADDED
@@ -0,0 +1,150 @@
1
+ # Application template recipe for the rails_apps_composer. Change the recipe here:
2
+ # https://github.com/RailsApps/rails_apps_composer/blob/master/recipes/apps4.rb
3
+
4
+ if prefer :apps4, 'learn-rails'
5
+
6
+ # >-------------------------------[ Gems ]--------------------------------<
7
+
8
+ add_gem 'activerecord-tableless'
9
+ add_gem 'high_voltage'
10
+ add_gem 'gibbon'
11
+ add_gem 'google_drive'
12
+ gsub_file 'Gemfile', /gem 'sqlite3'\n/, ''
13
+ add_gem 'sqlite3', :group => :development
14
+ add_gem 'pg', :group => :production
15
+ add_gem 'thin', :group => :production
16
+ add_gem 'rails_12factor', :group => :production
17
+
18
+ # >-------------------------------[ after_everything ]--------------------------------<
19
+
20
+ after_everything do
21
+ say_wizard "recipe running after 'bundle install'"
22
+ repo = 'https://raw.github.com/RailsApps/learn-rails/master/'
23
+
24
+ # >-------------------------------[ Clean up starter app ]--------------------------------<
25
+
26
+ # remove commented lines and multiple blank lines from Gemfile
27
+ # thanks to https://github.com/perfectline/template-bucket/blob/master/cleanup.rb
28
+ gsub_file 'Gemfile', /#.*\n/, "\n"
29
+ gsub_file 'Gemfile', /\n^\s*\n/, "\n"
30
+ # remove commented lines and multiple blank lines from config/routes.rb
31
+ gsub_file 'config/routes.rb', / #.*\n/, "\n"
32
+ gsub_file 'config/routes.rb', /\n^\s*\n/, "\n"
33
+ # GIT
34
+ git :add => '-A' if prefer :git, true
35
+ git :commit => '-qm "rails_apps_composer: clean up starter app"' if prefer :git, true
36
+
37
+ # >-------------------------------[ Models ]--------------------------------<
38
+
39
+ copy_from_repo 'app/models/contact.rb', :repo => repo
40
+ copy_from_repo 'app/models/visitor.rb', :repo => repo
41
+
42
+ # >-------------------------------[ Init ]--------------------------------<
43
+ copy_from_repo 'config/application.yml', :repo => repo
44
+ remove_file 'config/application.example.yml'
45
+ copy_file destination_root + '/config/application.yml', destination_root + '/config/application.example.yml'
46
+
47
+ # >-------------------------------[ Controllers ]--------------------------------<
48
+
49
+ copy_from_repo 'app/controllers/contacts_controller.rb', :repo => repo
50
+ copy_from_repo 'app/controllers/visitors_controller.rb', :repo => repo
51
+
52
+ # >-------------------------------[ Mailers ]--------------------------------<
53
+
54
+ generate 'mailer UserMailer'
55
+ copy_from_repo 'app/mailers/user_mailer.rb', :repo => repo
56
+
57
+ # >-------------------------------[ Views ]--------------------------------<
58
+
59
+ copy_from_repo 'app/views/contacts/new.html.erb', :repo => repo
60
+ copy_from_repo 'app/views/pages/about.html.erb', :repo => repo
61
+ copy_from_repo 'app/views/user_mailer/contact_email.html.erb', :repo => repo
62
+ copy_from_repo 'app/views/user_mailer/contact_email.text.erb', :repo => repo
63
+ copy_from_repo 'app/views/visitors/new.html.erb', :repo => repo
64
+ copy_from_repo 'app/views/layouts/_navigation.html.erb', :repo => repo
65
+
66
+ # >-------------------------------[ Routes ]--------------------------------<
67
+
68
+ copy_from_repo 'config/routes.rb', :repo => repo
69
+ ### CORRECT APPLICATION NAME ###
70
+ gsub_file 'config/routes.rb', /^.*.routes.draw do/, "#{app_const}.routes.draw do"
71
+
72
+ # >-------------------------------[ Assets ]--------------------------------<
73
+
74
+ copy_from_repo 'app/assets/javascripts/segmentio.js', :repo => repo
75
+
76
+ ### GIT ###
77
+ git :add => '-A' if prefer :git, true
78
+ git :commit => '-qm "rails_apps_composer: learn-rails app"' if prefer :git, true
79
+ end # after_bundler
80
+ end # learn-rails
81
+
82
+ if prefer :apps4, 'rails-bootstrap'
83
+
84
+ # >-------------------------------[ Gems ]--------------------------------<
85
+
86
+ add_gem 'high_voltage'
87
+
88
+ # >-------------------------------[ after_everything ]--------------------------------<
89
+
90
+ after_everything do
91
+ say_wizard "recipe running after 'bundle install'"
92
+ repo = 'https://raw.github.com/RailsApps/rails-bootstrap/master/'
93
+
94
+ # >-------------------------------[ Clean up starter app ]--------------------------------<
95
+
96
+ # remove commented lines and multiple blank lines from Gemfile
97
+ # thanks to https://github.com/perfectline/template-bucket/blob/master/cleanup.rb
98
+ gsub_file 'Gemfile', /#.*\n/, "\n"
99
+ gsub_file 'Gemfile', /\n^\s*\n/, "\n"
100
+ # remove commented lines and multiple blank lines from config/routes.rb
101
+ gsub_file 'config/routes.rb', / #.*\n/, "\n"
102
+ gsub_file 'config/routes.rb', /\n^\s*\n/, "\n"
103
+ # GIT
104
+ git :add => '-A' if prefer :git, true
105
+ git :commit => '-qm "rails_apps_composer: clean up starter app"' if prefer :git, true
106
+
107
+ # >-------------------------------[ Models ]--------------------------------<
108
+
109
+ # no models
110
+
111
+ # >-------------------------------[ Init ]--------------------------------<
112
+ copy_from_repo 'config/application.yml', :repo => repo
113
+ remove_file 'config/application.example.yml'
114
+ copy_file destination_root + '/config/application.yml', destination_root + '/config/application.example.yml'
115
+
116
+ # >-------------------------------[ Controllers ]--------------------------------<
117
+
118
+ copy_from_repo 'app/controllers/visitors_controller.rb', :repo => repo
119
+
120
+ # >-------------------------------[ Views ]--------------------------------<
121
+
122
+ copy_from_repo 'app/views/pages/about.html.erb', :repo => repo
123
+ copy_from_repo 'app/views/visitors/new.html.erb', :repo => repo
124
+ copy_from_repo 'app/views/layouts/_navigation.html.erb', :repo => repo
125
+
126
+ # >-------------------------------[ Routes ]--------------------------------<
127
+
128
+ copy_from_repo 'config/routes.rb', :repo => repo
129
+ ### CORRECT APPLICATION NAME ###
130
+ gsub_file 'config/routes.rb', /^.*.routes.draw do/, "#{app_const}.routes.draw do"
131
+
132
+ # >-------------------------------[ Assets ]--------------------------------<
133
+
134
+ # no assets
135
+
136
+ ### GIT ###
137
+ git :add => '-A' if prefer :git, true
138
+ git :commit => '-qm "rails_apps_composer: rails-bootstrap app"' if prefer :git, true
139
+ end # after_bundler
140
+ end # rails-bootstrap
141
+
142
+ __END__
143
+
144
+ name: apps4
145
+ description: "Install RailsApps starter applications for Rails 4.0."
146
+ author: RailsApps
147
+
148
+ requires: [core]
149
+ run_after: [setup, gems]
150
+ category: apps
@@ -0,0 +1,75 @@
1
+ # Application template recipe for the rails_apps_composer. Change the recipe here:
2
+ # https://github.com/RailsApps/rails_apps_composer/blob/master/recipes/controllers.rb
3
+
4
+ after_bundler do
5
+ say_wizard "recipe running after 'bundle install'"
6
+ ### APPLICATION_CONTROLLER ###
7
+ if prefer :authentication, 'omniauth'
8
+ #copy_from_repo 'app/controllers/application_controller.rb', :repo => 'https://raw.github.com/RailsApps/rails3-mongoid-omniauth/master/'
9
+ copy_from_repo 'app/controllers/application_controller-omniauth.rb', :prefs => 'omniauth'
10
+ end
11
+ if prefer :authorization, 'cancan'
12
+ inject_into_file 'app/controllers/application_controller.rb', :before => "\nend" do <<-RUBY
13
+ \n
14
+ rescue_from CanCan::AccessDenied do |exception|
15
+ redirect_to root_path, :alert => exception.message
16
+ end
17
+ RUBY
18
+ end
19
+ end
20
+ ### HOME_CONTROLLER ###
21
+ if ['home_app','users_app','admin_app','subdomains_app'].include? prefs[:starter_app]
22
+ generate(:controller, "home index")
23
+ end
24
+ if ['users_app','admin_app','subdomains_app'].include? prefs[:starter_app]
25
+ gsub_file 'app/controllers/home_controller.rb', /def index/, "def index\n @users = User.all"
26
+ end
27
+ ### USERS_CONTROLLER ###
28
+ case prefs[:starter_app]
29
+ when 'users_app'
30
+ if prefer :authentication, 'devise'
31
+ copy_from_repo 'app/controllers/users_controller.rb', :repo => 'https://raw.github.com/RailsApps/rails3-devise-rspec-cucumber/master/'
32
+ elsif prefer :authentication, 'omniauth'
33
+ copy_from_repo 'app/controllers/users_controller.rb', :repo => 'https://raw.github.com/RailsApps/rails3-mongoid-omniauth/master/'
34
+ end
35
+ when 'admin_app'
36
+ if prefer :authentication, 'devise'
37
+ copy_from_repo 'app/controllers/users_controller.rb', :repo => 'https://raw.github.com/RailsApps/rails3-bootstrap-devise-cancan/master/'
38
+ elsif prefer :authentication, 'omniauth'
39
+ copy_from_repo 'app/controllers/users_controller.rb', :repo => 'https://raw.github.com/RailsApps/rails3-mongoid-omniauth/master/'
40
+ end
41
+ when 'subdomains_app'
42
+ copy_from_repo 'app/controllers/users_controller.rb', :repo => 'https://raw.github.com/RailsApps/rails3-subdomains/master/'
43
+ end
44
+ ### REGISTRATIONS_CONTROLLER ###
45
+ if rails_4?
46
+ if ['users_app','admin_app','subdomains_app'].include? prefs[:starter_app]
47
+ ## accommodate strong parameters in Rails 4
48
+ copy_from_repo 'app/controllers/registrations_controller-devise.rb', :prefs => 'devise'
49
+ end
50
+ end
51
+ ### SESSIONS_CONTROLLER ###
52
+ if prefer :authentication, 'omniauth'
53
+ filename = 'app/controllers/sessions_controller.rb'
54
+ copy_from_repo filename, :repo => 'https://raw.github.com/RailsApps/rails3-mongoid-omniauth/master/'
55
+ gsub_file filename, /twitter/, prefs[:omniauth_provider] unless prefer :omniauth_provider, 'twitter'
56
+ if prefer :authorization, 'cancan'
57
+ 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"
58
+ end
59
+ end
60
+ ### PROFILES_CONTROLLER ###
61
+ copy_from_repo 'app/controllers/profiles_controller.rb', :repo => 'https://raw.github.com/RailsApps/rails3-subdomains/master/' if prefer :starter_app, 'subdomains_app'
62
+ ### GIT ###
63
+ git :add => '-A' if prefer :git, true
64
+ git :commit => '-qm "rails_apps_composer: controllers"' if prefer :git, true
65
+ end # after_bundler
66
+
67
+ __END__
68
+
69
+ name: controllers
70
+ description: "Add controllers needed for starter apps."
71
+ author: RailsApps
72
+
73
+ requires: [setup, gems, models]
74
+ run_after: [setup, gems, models]
75
+ category: mvc