redmint_composer 2.3

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 (57) hide show
  1. checksums.yaml +7 -0
  2. data/README.textile +10 -0
  3. data/bin/redmint_composer +7 -0
  4. data/lib/rails_wizard.rb +7 -0
  5. data/lib/rails_wizard/command.rb +204 -0
  6. data/lib/rails_wizard/config.rb +88 -0
  7. data/lib/rails_wizard/diagnostics.rb +58 -0
  8. data/lib/rails_wizard/recipe.rb +114 -0
  9. data/lib/rails_wizard/recipes.rb +56 -0
  10. data/lib/rails_wizard/template.rb +111 -0
  11. data/recipes/admin.rb +42 -0
  12. data/recipes/analytics.rb +41 -0
  13. data/recipes/core.rb +32 -0
  14. data/recipes/deployment.rb +178 -0
  15. data/recipes/devise.rb +34 -0
  16. data/recipes/email.rb +65 -0
  17. data/recipes/email_dev.rb +92 -0
  18. data/recipes/example.rb +63 -0
  19. data/recipes/extras.rb +283 -0
  20. data/recipes/frontend.rb +33 -0
  21. data/recipes/gems.rb +274 -0
  22. data/recipes/git.rb +27 -0
  23. data/recipes/init.rb +179 -0
  24. data/recipes/learn_rails.rb +89 -0
  25. data/recipes/locale.rb +31 -0
  26. data/recipes/omniauth.rb +38 -0
  27. data/recipes/pages.rb +91 -0
  28. data/recipes/rails_bootstrap.rb +29 -0
  29. data/recipes/rails_devise.rb +26 -0
  30. data/recipes/rails_devise_pundit.rb +25 -0
  31. data/recipes/rails_devise_roles.rb +25 -0
  32. data/recipes/rails_foundation.rb +29 -0
  33. data/recipes/rails_mailinglist_activejob.rb +76 -0
  34. data/recipes/rails_omniauth.rb +27 -0
  35. data/recipes/rails_signup_download.rb +69 -0
  36. data/recipes/rails_stripe_checkout.rb +84 -0
  37. data/recipes/rails_stripe_coupons.rb +125 -0
  38. data/recipes/rails_stripe_membership_saas.rb +112 -0
  39. data/recipes/railsapps.rb +77 -0
  40. data/recipes/readme.rb +161 -0
  41. data/recipes/roles.rb +40 -0
  42. data/recipes/setup.rb +162 -0
  43. data/recipes/tests.rb +59 -0
  44. data/spec/rails_wizard/config_spec.rb +108 -0
  45. data/spec/rails_wizard/recipe_spec.rb +115 -0
  46. data/spec/rails_wizard/recipes/sanity_spec.rb +30 -0
  47. data/spec/rails_wizard/recipes_spec.rb +41 -0
  48. data/spec/rails_wizard/template_spec.rb +92 -0
  49. data/spec/spec_helper.rb +11 -0
  50. data/spec/support/rails_directory.rb +17 -0
  51. data/spec/support/template_runner.rb +28 -0
  52. data/spec/test_recipes/test_recipe_in_file.rb +9 -0
  53. data/templates/helpers.erb +138 -0
  54. data/templates/layout.erb +231 -0
  55. data/templates/recipe.erb +13 -0
  56. data/version.rb +3 -0
  57. metadata +201 -0
@@ -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,42 @@
1
+ # Application template recipe for the rails_apps_composer. Change the recipe here:
2
+ # https://github.com/RailsApps/rails_apps_composer/blob/master/recipes/admin.rb
3
+
4
+ prefs[:admin] = config['admin'] unless config['admin'] == 'none'
5
+
6
+ if prefer :admin, 'activeadmin'
7
+ add_gem 'activeadmin', '~> 1.0.0.pre2'
8
+ elsif prefer :admin, 'rails_admin'
9
+ add_gem 'rails_admin'
10
+ end
11
+
12
+ stage_two do
13
+ say_wizard "recipe stage two"
14
+ if prefer :admin, 'activeadmin'
15
+ say_wizard "recipe installing activeadmin"
16
+ generate 'active_admin:install'
17
+ end
18
+ if prefer :admin, 'rails_admin'
19
+ say_wizard "recipe installing rails_admin"
20
+ generate 'rails_admin:install'
21
+ end
22
+ ### GIT
23
+ git :add => '-A' if prefer :git, true
24
+ git :commit => %Q(-qm "redmint_composer: installed #{prefs[:admin]}") if prefer :git, true
25
+ end
26
+
27
+ __END__
28
+
29
+ name: admin
30
+ description: "Adding rails admin gem to your application"
31
+ author: JangoSteve
32
+
33
+ category: admin
34
+ requires: [setup]
35
+ run_after: [setup]
36
+ args: -T
37
+
38
+ config:
39
+ - admin:
40
+ type: multiple_choice
41
+ prompt: Install admin gem?
42
+ choices: [ ["None", "none"], ["ActiveAdmin", "activeadmin"], ["RailsAdmin", "rails_admin"] ]
@@ -0,0 +1,41 @@
1
+ # Application template recipe for the rails_apps_composer. Change the recipe here:
2
+ # https://github.com/RailsApps/rails_apps_composer/blob/master/recipes/analytics.rb
3
+
4
+ prefs[:analytics] = multiple_choice "Install page-view analytics?", [["None", "none"],
5
+ ["Google Analytics", "ga"],
6
+ ["Segment.io", "segmentio"]] unless prefs.has_key? :analytics
7
+ case prefs[:analytics]
8
+ when 'ga'
9
+ ga_id = ask_wizard('Google Analytics ID?')
10
+ when 'segmentio'
11
+ segmentio_api_key = ask_wizard('Segment.io API key?')
12
+ end
13
+
14
+ stage_two do
15
+ say_wizard "recipe stage two"
16
+ unless prefer :analytics, 'none'
17
+ # don't add the gem if it has already been added by the railsapps recipe
18
+ add_gem 'rails_apps_pages', :group => :development unless prefs[:apps4]
19
+ end
20
+ case prefs[:analytics]
21
+ when 'ga'
22
+ generate 'analytics:google -f'
23
+ gsub_file 'app/assets/javascripts/google_analytics.js.coffee', /UA-XXXXXXX-XX/, ga_id
24
+ when 'segmentio'
25
+ generate 'analytics:segmentio -f'
26
+ gsub_file 'app/assets/javascripts/segmentio.js', /SEGMENTIO_API_KEY/, segmentio_api_key
27
+ end
28
+ ### GIT ###
29
+ git :add => '-A' if prefer :git, true
30
+ git :commit => '-qm "redmint_composer: add analytics"' if prefer :git, true
31
+ end
32
+
33
+ __END__
34
+
35
+ name: analytics
36
+ description: "Add JavaScript files for Segment.io or Google Analytics"
37
+ author: RailsApps
38
+
39
+ requires: [setup, gems]
40
+ run_after: [setup, gems, init]
41
+ category: other
@@ -0,0 +1,32 @@
1
+ # Application template recipe for the rails_apps_composer. Change the recipe here:
2
+ # https://github.com/RailsApps/rails_apps_composer/blob/master/recipes/core.rb
3
+
4
+ ## Git
5
+ say_wizard "selected all core recipes"
6
+
7
+ __END__
8
+
9
+ name: core
10
+ description: "Select all core recipes."
11
+ author: RailsApps
12
+
13
+ requires: [git, railsapps,
14
+ learn_rails,
15
+ rails_bootstrap,
16
+ rails_foundation,
17
+ rails_omniauth,
18
+ rails_devise,
19
+ rails_devise_roles,
20
+ rails_devise_pundit,
21
+ rails_signup_download,
22
+ rails_mailinglist_activejob,
23
+ rails_stripe_checkout,
24
+ rails_stripe_coupons,
25
+ rails_stripe_membership_saas,
26
+ setup, locale, readme, gems,
27
+ tests,
28
+ email,
29
+ devise, omniauth, roles,
30
+ frontend, pages,
31
+ init, analytics, deployment, extras, admin]
32
+ category: collections
@@ -0,0 +1,178 @@
1
+ # Application template recipe for the rails_apps_composer. Change the recipe here:
2
+ # https://github.com/RailsApps/rails_apps_composer/blob/master/recipes/deployment.rb
3
+
4
+ prefs[:deployment] = multiple_choice "Prepare for deployment?", [["no", "none"],
5
+ ["Heroku", "heroku"],
6
+ ["Capistrano", "capistrano3"]] unless prefs.has_key? :deployment
7
+
8
+ if prefer :deployment, 'heroku'
9
+ say_wizard "installing gems for Heroku"
10
+ if prefer :database, 'sqlite'
11
+ gsub_file 'Gemfile', /.*gem 'sqlite3'\n/, ''
12
+ add_gem 'sqlite3', group: [:development, :test]
13
+ add_gem 'pg', group: :production
14
+ end
15
+ add_gem 'rails_12factor', group: :production
16
+ stage_three do
17
+ say_wizard "recipe stage three"
18
+ say_wizard "precompiling assets for Heroku"
19
+ run 'RAILS_ENV=production rake assets:precompile'
20
+ say_wizard "creating app.json file for Heroku Button"
21
+ create_file 'app.json' do <<-TEXT
22
+ {
23
+ "name": "#{app_name.humanize.titleize}",
24
+ "description": "Starter application generated by Rails Composer",
25
+ "logo": "https://avatars3.githubusercontent.com/u/788200",
26
+ TEXT
27
+ end
28
+ append_file 'app.json', " \"repository\": \"https://github.com/RailsApps/#{prefs[:apps4]}\",\n" if prefs.keys.include?(:apps4)
29
+ append_file 'app.json', ' "keywords": [' + "\n"
30
+ append_file 'app.json', ' "Rails Composer",' + "\n"
31
+ append_file 'app.json', ' "RailsApps",' + "\n" + ' "starter",' + "\n" if prefs.keys.include?(:apps4)
32
+ append_file 'app.json', ' "RSpec",' + "\n" if prefer :tests, 'rspec'
33
+ append_file 'app.json', ' "Bootstrap",' + "\n" if prefer :frontend, 'bootstrap3'
34
+ append_file 'app.json', ' "Foundation",' + "\n" if prefer :frontend, 'pundit'
35
+ append_file 'app.json', ' "authentication",' + "\n" + ' "Devise",' + "\n" if prefer :authentication, 'devise'
36
+ append_file 'app.json', ' "authentication",' + "\n" + ' "OmniAuth",' + "\n" if prefer :authentication, 'omniauth'
37
+ append_file 'app.json', ' "authorization",' + "\n" + ' "roles",' + "\n" if prefer :authorization, 'roles'
38
+ append_file 'app.json', ' "authorization",' + "\n" + ' "Pundit",' + "\n" if prefer :authorization, 'pundit'
39
+ append_file 'app.json' do <<-TEXT
40
+ "Ruby",
41
+ "Rails"
42
+ ],
43
+ "scripts": {},
44
+ "env": {
45
+ TEXT
46
+ end
47
+ case prefs[:email]
48
+ when 'gmail'
49
+ append_file 'app.json' do <<-TEXT
50
+ "GMAIL_USERNAME": {
51
+ "description": "Your Gmail address for sending mail.",
52
+ "value": "admin@redmintlabs.com",
53
+ "required": false
54
+ },
55
+ "GMAIL_PASSWORD": {
56
+ "description": "Your Gmail password for sending mail.",
57
+ "value": "changeme",
58
+ "required": false
59
+ },
60
+ TEXT
61
+ end
62
+ when 'sendgrid'
63
+ append_file 'app.json' do <<-TEXT
64
+ "SENDGRID_USERNAME": {
65
+ "description": "Your SendGrid address for sending mail.",
66
+ "value": "admin@redmintlabs.com",
67
+ "required": false
68
+ },
69
+ "SENDGRID_PASSWORD": {
70
+ "description": "Your SendGrid password for sending mail.",
71
+ "value": "changeme",
72
+ "required": false
73
+ },
74
+ TEXT
75
+ end
76
+ when 'mandrill'
77
+ append_file 'app.json' do <<-TEXT
78
+ "MANDRILL_USERNAME": {
79
+ "description": "Your Mandrill address for sending mail.",
80
+ "value": "admin@redmintlabs.com",
81
+ "required": false
82
+ },
83
+ "MANDRILL_APIKEY": {
84
+ "description": "Your Mandrill API key for sending mail.",
85
+ "value": "changeme",
86
+ "required": false
87
+ },
88
+ TEXT
89
+ end
90
+ end
91
+ if prefer :authentication, 'omniauth'
92
+ append_file 'app.json' do <<-TEXT
93
+ "OMNIAUTH_PROVIDER_KEY": {
94
+ "description": "Credentials from Twitter, Facebook, or another provider.",
95
+ "value": "some_long_key",
96
+ "required": false
97
+ },
98
+ "OMNIAUTH_PROVIDER_SECRET": {
99
+ "description": "Credentials from Twitter, Facebook, or another provider.",
100
+ "value": "some_long_key",
101
+ "required": false
102
+ },
103
+ TEXT
104
+ end
105
+ end
106
+ if prefer :authentication, 'devise'
107
+ append_file 'app.json' do <<-TEXT
108
+ "ADMIN_EMAIL": {
109
+ "description": "The administrator's email address for signing in.",
110
+ "value": "admin@redmintlabs.com",
111
+ "required": true
112
+ },
113
+ "ADMIN_PASSWORD": {
114
+ "description": "The administrator's password for signing in.",
115
+ "value": "changeme",
116
+ "required": true
117
+ },
118
+ "DOMAIN_NAME": {
119
+ "description": "Required for sending mail. Give an app name or use a custom domain.",
120
+ "value": "myapp.herokuapp.com",
121
+ "required": false
122
+ },
123
+ TEXT
124
+ end
125
+ end
126
+ if (!prefs[:secrets].nil?)
127
+ prefs[:secrets].each do |secret|
128
+ append_file 'app.json' do <<-TEXT
129
+ "#{secret.upcase}": {
130
+ "description": "no description",
131
+ "required": false
132
+ },
133
+ TEXT
134
+ end
135
+ end
136
+ end
137
+ append_file 'app.json' do <<-TEXT
138
+ "RAILS_ENV": "production"
139
+ }
140
+ }
141
+ TEXT
142
+ end
143
+ if File.exists?('db/migrate')
144
+ gsub_file 'app.json', /"scripts": {/,
145
+ "\"scripts\": {\"postdeploy\": \"bundle exec rake db:migrate; bundle exec rake db:seed\""
146
+ end
147
+ end
148
+ end
149
+
150
+ if prefer :deployment, 'capistrano3'
151
+ say_wizard "installing gems for Capistrano"
152
+ add_gem 'capistrano', '~> 3.0.1', group: :development
153
+ add_gem 'capistrano-rvm', '~> 0.1.1', group: :development
154
+ add_gem 'capistrano-bundler', group: :development
155
+ add_gem 'capistrano-rails', '~> 1.1.0', group: :development
156
+ add_gem 'capistrano-rails-console', group: :development
157
+ stage_two do
158
+ say_wizard "recipe stage two"
159
+ say_wizard "installing Capistrano files"
160
+ run 'bundle exec cap install'
161
+ end
162
+ end
163
+
164
+ stage_three do
165
+ ### GIT ###
166
+ git :add => '-A' if prefer :git, true
167
+ git :commit => '-qm "redmint_composer: prepare for deployment"' if prefer :git, true
168
+ end
169
+
170
+ __END__
171
+
172
+ name: deployment
173
+ description: "Prepare for deployment"
174
+ author: RailsApps
175
+
176
+ requires: [setup]
177
+ run_after: [init]
178
+ category: development