rails_apps_composer 1.5.5 → 2.0.1

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 (69) hide show
  1. data/README.textile +185 -254
  2. data/lib/rails_wizard/command.rb +54 -13
  3. data/lib/rails_wizard/config.rb +1 -1
  4. data/lib/rails_wizard/diagnostics.rb +22 -0
  5. data/lib/rails_wizard/template.rb +36 -2
  6. data/lib/rails_wizard.rb +1 -0
  7. data/recipes/auth.rb +84 -0
  8. data/recipes/controllers.rb +58 -0
  9. data/recipes/{seed_database.rb → database.rb} +35 -22
  10. data/recipes/{action_mailer.rb → email.rb} +29 -50
  11. data/recipes/example.rb +70 -0
  12. data/recipes/extras.rb +91 -30
  13. data/recipes/frontend.rb +59 -0
  14. data/recipes/gems.rb +128 -0
  15. data/recipes/models.rb +61 -0
  16. data/recipes/prelaunch.rb +45 -0
  17. data/recipes/readme.rb +83 -0
  18. data/recipes/routes.rb +36 -0
  19. data/recipes/setup.rb +148 -0
  20. data/recipes/testing.rb +187 -0
  21. data/recipes/views.rb +39 -0
  22. data/spec/rails_wizard/template_spec.rb +4 -2
  23. data/templates/helpers.erb +53 -2
  24. data/templates/layout.erb +81 -20
  25. data/version.rb +1 -1
  26. metadata +19 -49
  27. data/recipes/active_admin.rb +0 -36
  28. data/recipes/activerecord.rb +0 -37
  29. data/recipes/add_user.rb +0 -140
  30. data/recipes/airbrake.rb +0 -34
  31. data/recipes/backbone.rb +0 -23
  32. data/recipes/capybara.rb +0 -34
  33. data/recipes/cleanup.rb +0 -40
  34. data/recipes/cloudfiles.rb +0 -36
  35. data/recipes/compass.rb +0 -46
  36. data/recipes/compass_960.rb +0 -48
  37. data/recipes/cucumber.rb +0 -75
  38. data/recipes/datamapper.rb +0 -111
  39. data/recipes/devise.rb +0 -114
  40. data/recipes/git.rb +0 -40
  41. data/recipes/guard.rb +0 -89
  42. data/recipes/haml.rb +0 -23
  43. data/recipes/heroku.rb +0 -61
  44. data/recipes/home_page.rb +0 -58
  45. data/recipes/home_page_users.rb +0 -47
  46. data/recipes/html5.rb +0 -152
  47. data/recipes/inherited_resources.rb +0 -23
  48. data/recipes/less.rb +0 -12
  49. data/recipes/mongohq.rb +0 -59
  50. data/recipes/mongoid.rb +0 -38
  51. data/recipes/mongolab.rb +0 -59
  52. data/recipes/omniauth.rb +0 -194
  53. data/recipes/omniauth_email.rb +0 -82
  54. data/recipes/paperclip.rb +0 -79
  55. data/recipes/prelaunch_signup.rb +0 -586
  56. data/recipes/rails_admin.rb +0 -29
  57. data/recipes/redis.rb +0 -23
  58. data/recipes/responders.rb +0 -10
  59. data/recipes/resque.rb +0 -25
  60. data/recipes/rspec.rb +0 -131
  61. data/recipes/sass.rb +0 -25
  62. data/recipes/settingslogic.rb +0 -43
  63. data/recipes/simple_form.rb +0 -54
  64. data/recipes/slim.rb +0 -46
  65. data/recipes/static_page.rb +0 -43
  66. data/recipes/subdomains.rb +0 -121
  67. data/recipes/turnip.rb +0 -18
  68. data/recipes/unicorn.rb +0 -29
  69. data/recipes/users_page.rb +0 -165
data/recipes/setup.rb ADDED
@@ -0,0 +1,148 @@
1
+ # Application template recipe for the rails_apps_composer. Change the recipe here:
2
+ # https://github.com/RailsApps/rails_apps_composer/blob/master/recipes/setup.rb
3
+
4
+ ## Ruby on Rails
5
+ say_wizard "You are using Ruby version #{RUBY_VERSION}."
6
+ say_wizard "You are using Rails version #{Rails::VERSION::STRING}."
7
+
8
+ ## Git
9
+ say_wizard "initialize git"
10
+ prefs[:git] = true unless prefs.has_key? :git
11
+ if prefer :git, true
12
+ begin
13
+ remove_file '.gitignore'
14
+ get 'https://raw.github.com/RailsApps/rails3-application-templates/master/files/gitignore.txt', '.gitignore'
15
+ rescue OpenURI::HTTPError
16
+ say_wizard "Unable to obtain gitignore file from the repo"
17
+ end
18
+ git :init
19
+ git :add => '.'
20
+ git :commit => "-aqm 'rails_apps_composer: initial commit'"
21
+ end
22
+
23
+ ## Is sqlite3 in the Gemfile?
24
+ f = File.open(destination_root() + '/Gemfile', "r")
25
+ gemfile = ''
26
+ f.each_line do |line|
27
+ gemfile += line
28
+ end
29
+ sqlite_detected = gemfile.include? 'sqlite3'
30
+
31
+ ## Web Server
32
+ prefs[:dev_webserver] = multiple_choice "Web server for development?", [["WEBrick (default)", "webrick"],
33
+ ["Thin", "thin"], ["Unicorn", "unicorn"], ["Puma", "puma"]] unless prefs.has_key? :dev_webserver
34
+ webserver = multiple_choice "Web server for production?", [["Same as development", "same"],
35
+ ["Thin", "thin"], ["Unicorn", "unicorn"], ["Puma", "puma"]] unless prefs.has_key? :prod_webserver
36
+ if webserver == 'same'
37
+ case prefs[:dev_webserver]
38
+ when 'thin'
39
+ prefs[:prod_webserver] = 'thin'
40
+ when 'unicorn'
41
+ prefs[:prod_webserver] = 'unicorn'
42
+ when 'puma'
43
+ prefs[:prod_webserver] = 'puma'
44
+ end
45
+ else
46
+ prefs[:prod_webserver] = webserver
47
+ end
48
+
49
+ ## Database Adapter
50
+ prefs[:database] = multiple_choice "Database used in development?", [["SQLite", "sqlite"], ["PostgreSQL", "postgresql"],
51
+ ["MySQL", "mysql"], ["MongoDB", "mongodb"]] unless prefs.has_key? :database
52
+ case prefs[:database]
53
+ when 'mongodb'
54
+ unless sqlite_detected
55
+ prefs[:orm] = multiple_choice "How will you connect to MongoDB?", [["Mongoid","mongoid"]] unless prefs.has_key? :orm
56
+ else
57
+ 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"
58
+ end
59
+ end
60
+
61
+ ## Template Engine
62
+ prefs[:templates] = multiple_choice "Template engine?", [["ERB", "erb"], ["Haml", "haml"], ["Slim", "slim"]] unless prefs.has_key? :templates
63
+
64
+ ## Testing Framework
65
+ if recipes.include? 'testing'
66
+ prefs[:unit_test] = multiple_choice "Unit testing?", [["Test::Unit", "test_unit"], ["RSpec", "rspec"]] unless prefs.has_key? :unit_test
67
+ prefs[:integration] = multiple_choice "Integration testing?", [["RSpec with Capybara", "capybara"],
68
+ ["Cucumber with Capybara", "cucumber"], ["Turnip with Capybara", "turnip"]] unless prefs.has_key? :integration
69
+ prefs[:fixtures] = multiple_choice "Fixture replacement?", [["None","none"], ["Factory Girl","factory_girl"], ["Machinist","machinist"]] unless prefs.has_key? :fixtures
70
+ end
71
+
72
+ ## Front-end Framework
73
+ if recipes.include? 'frontend'
74
+ prefs[:frontend] = multiple_choice "Front-end framework?", [["None", "none"], ["Twitter Bootstrap", "bootstrap"],
75
+ ["Zurb Foundation", "foundation"], ["Skeleton", "skeleton"], ["Just normalize CSS for consistent styling", "normalize"]] unless prefs.has_key? :frontend
76
+ if prefer :frontend, 'bootstrap'
77
+ prefs[:bootstrap] = multiple_choice "Twitter Bootstrap version?", [["Twitter Bootstrap (Less)", "less"],
78
+ ["Twitter Bootstrap (Sass)", "sass"]] unless prefs.has_key? :bootstrap
79
+ end
80
+ end
81
+
82
+ ## Email
83
+ if recipes.include? 'email'
84
+ prefs[:email] = multiple_choice "Add support for sending email?", [["None", "none"], ["Gmail","gmail"], ["SMTP","smtp"],
85
+ ["SendGrid","sendgrid"], ["Mandrill","mandrill"]] unless prefs.has_key? :email
86
+ else
87
+ prefs[:email] = 'none'
88
+ end
89
+
90
+ ## Authentication and Authorization
91
+ if recipes.include? 'auth'
92
+ prefs[:authentication] = multiple_choice "Authentication?", [["None", "none"], ["Devise", "devise"], ["OmniAuth", "omniauth"]] unless prefs.has_key? :authentication
93
+ case prefs[:authentication]
94
+ when 'devise'
95
+ if prefer :orm, 'mongoid'
96
+ prefs[:devise_modules] = multiple_choice "Devise modules?", [["Devise with default modules","default"]] unless prefs.has_key? :devise_modules
97
+ else
98
+ prefs[:devise_modules] = multiple_choice "Devise modules?", [["Devise with default modules","default"], ["Devise with Confirmable module","confirmable"],
99
+ ["Devise with Confirmable and Invitable modules","invitable"]] unless prefs.has_key? :devise_modules
100
+ end
101
+ when 'omniauth'
102
+ prefs[:omniauth_provider] = multiple_choice "OmniAuth provider?", [["Facebook", "facebook"], ["Twitter", "twitter"], ["GitHub", "github"],
103
+ ["LinkedIn", "linkedin"], ["Google-Oauth-2", "google-oauth2"], ["Tumblr", "tumblr"]] unless prefs.has_key? :omniauth_provider
104
+ end
105
+ prefs[:authorization] = multiple_choice "Authorization?", [["None", "none"], ["CanCan with Rolify", "cancan"]] unless prefs.has_key? :authorization
106
+ end
107
+
108
+ ## MVC
109
+ if (recipes.include? 'models') && (recipes.include? 'controllers') && (recipes.include? 'views') && (recipes.include? 'routes')
110
+ if prefer :authorization, 'cancan'
111
+ prefs[:starter_app] = multiple_choice "Install a starter app?", [["None", "none"], ["Home Page", "home_app"],
112
+ ["Home Page, User Accounts", "users_app"], ["Home Page, User Accounts, Admin Dashboard", "admin_app"]] unless prefs.has_key? :starter_app
113
+ elsif prefer :authentication, 'devise'
114
+ if prefer :orm, 'mongoid'
115
+ prefs[:starter_app] = multiple_choice "Install a starter app?", [["None", "none"], ["Home Page", "home_app"],
116
+ ["Home Page, User Accounts", "users_app"], ["Home Page, User Accounts, Subdomains", "subdomains_app"]] unless prefs.has_key? :starter_app
117
+ else
118
+ prefs[:starter_app] = multiple_choice "Install a starter app?", [["None", "none"], ["Home Page", "home_app"],
119
+ ["Home Page, User Accounts", "users_app"]] unless prefs.has_key? :starter_app
120
+ end
121
+ elsif prefer :authentication, 'omniauth'
122
+ prefs[:starter_app] = multiple_choice "Install a starter app?", [["None", "none"], ["Home Page", "home_app"],
123
+ ["Home Page, User Accounts", "users_app"]] unless prefs.has_key? :starter_app
124
+ else
125
+ prefs[:starter_app] = multiple_choice "Install a starter app?", [["None", "none"], ["Home Page", "home_app"]] unless prefs.has_key? :starter_app
126
+ end
127
+ if (recipes.include? 'prelaunch') && (prefer :authentication, 'devise') && (prefer :authorization, 'cancan')
128
+ prefs[:prelaunch_app] = multiple_choice "Install a prelaunch app?", [["None", "none"], ["Prelaunch Signup App", "signup_app"]]
129
+ if prefs[:prelaunch_app] == 'signup_app'
130
+ prefs[:devise_modules] = 'confirmable'
131
+ prefs[:bulkmail] = multiple_choice "Send news and announcements with a mail service?", [["None", "none"], ["MailChimp","mailchimp"]]
132
+ if prefer :git, true
133
+ prefs[:prelaunch_branch] = multiple_choice "Git branch for the prelaunch app?", [["wip (work-in-progress)", "wip"], ["master", "master"], ["prelaunch", "prelaunch"], ["staging", "staging"]]
134
+ if prefs[:prelaunch_branch] == 'master'
135
+ prefs[:main_branch] = multiple_choice "Git branch for the main app?", [["None (delete)", "none"], ["wip (work-in-progress)", "wip"], ["edge", "edge"]]
136
+ end
137
+ end
138
+ end
139
+ end
140
+ end
141
+
142
+ __END__
143
+
144
+ name: setup
145
+ description: "Make choices for your application."
146
+ author: RailsApps
147
+
148
+ category: configuration
@@ -0,0 +1,187 @@
1
+ # Application template recipe for the rails_apps_composer. Change the recipe here:
2
+ # https://github.com/RailsApps/rails_apps_composer/blob/master/recipes/testing.rb
3
+
4
+ after_bundler do
5
+ say_wizard "recipe running after 'bundle install'"
6
+ ### RSPEC ###
7
+ if prefer :unit_test, 'rspec'
8
+ say_wizard "recipe installing RSpec"
9
+ generate 'rspec:install'
10
+ unless prefer :email, 'none'
11
+ generate 'email_spec:steps'
12
+ inject_into_file 'spec/spec_helper.rb', "require 'email_spec'\n", :after => "require 'rspec/rails'\n"
13
+ inject_into_file 'spec/spec_helper.rb', :after => "RSpec.configure do |config|\n" do <<-RUBY
14
+ config.include(EmailSpec::Helpers)
15
+ config.include(EmailSpec::Matchers)
16
+ RUBY
17
+ end
18
+ end
19
+ run 'rm -rf test/' # Removing test folder (not needed for RSpec)
20
+ inject_into_file 'config/application.rb', :after => "Rails::Application\n" do <<-RUBY
21
+
22
+ # don't generate RSpec tests for views and helpers
23
+ config.generators do |g|
24
+ g.view_specs false
25
+ g.helper_specs false
26
+ #{"g.fixture_replacement :machinist" if prefer :fixtures, 'machinist'}
27
+ end
28
+
29
+ RUBY
30
+ end
31
+ ## RSPEC AND MONGOID
32
+ if prefer :orm, 'mongoid'
33
+ # remove ActiveRecord artifacts
34
+ gsub_file 'spec/spec_helper.rb', /config.fixture_path/, '# config.fixture_path'
35
+ gsub_file 'spec/spec_helper.rb', /config.use_transactional_fixtures/, '# config.use_transactional_fixtures'
36
+ # reset your application database to a pristine state during testing
37
+ inject_into_file 'spec/spec_helper.rb', :before => "\nend" do
38
+ <<-RUBY
39
+ \n
40
+ require 'database_cleaner'
41
+ config.before(:suite) do
42
+ DatabaseCleaner.strategy = :truncation
43
+ DatabaseCleaner.orm = "mongoid"
44
+ end
45
+
46
+ config.before(:each) do
47
+ DatabaseCleaner.clean
48
+ end
49
+ RUBY
50
+ end
51
+ # remove either possible occurrence of "require rails/test_unit/railtie"
52
+ gsub_file 'config/application.rb', /require 'rails\/test_unit\/railtie'/, '# require "rails/test_unit/railtie"'
53
+ gsub_file 'config/application.rb', /require "rails\/test_unit\/railtie"/, '# require "rails/test_unit/railtie"'
54
+ # configure RSpec to use matchers from the mongoid-rspec gem
55
+ create_file 'spec/support/mongoid.rb' do
56
+ <<-RUBY
57
+ RSpec.configure do |config|
58
+ config.include Mongoid::Matchers
59
+ end
60
+ RUBY
61
+ end
62
+ end
63
+ ## RSPEC AND DEVISE
64
+ if prefer :authentication, 'devise'
65
+ # add Devise test helpers
66
+ create_file 'spec/support/devise.rb' do
67
+ <<-RUBY
68
+ RSpec.configure do |config|
69
+ config.include Devise::TestHelpers, :type => :controller
70
+ end
71
+ RUBY
72
+ end
73
+ end
74
+ end
75
+ ### CUCUMBER ###
76
+ if prefer :integration, 'cucumber'
77
+ say_wizard "recipe installing Cucumber"
78
+ generate "cucumber:install --capybara#{' --rspec' if prefer :unit_test, 'rspec'}#{' -D' if prefer :orm, 'mongoid'}"
79
+ # make it easy to run Cucumber for single features without adding "--require features" to the command line
80
+ gsub_file 'config/cucumber.yml', /std_opts = "/, 'std_opts = "-r features/support/ -r features/step_definitions '
81
+ unless prefer :email, 'none'
82
+ create_file 'features/support/email_spec.rb' do <<-RUBY
83
+ require 'email_spec/cucumber'
84
+ RUBY
85
+ end
86
+ end
87
+ ## CUCUMBER AND MONGOID
88
+ if prefer :orm, 'mongoid'
89
+ gsub_file 'features/support/env.rb', /transaction/, "truncation"
90
+ inject_into_file 'features/support/env.rb', :after => 'begin' do
91
+ "\n DatabaseCleaner.orm = 'mongoid'"
92
+ end
93
+ end
94
+ end
95
+ ## TURNIP
96
+ if prefer :integration, 'turnip'
97
+ append_to_file '.rspec', '-r turnip/rspec'
98
+ inject_into_file 'spec/spec_helper.rb', "require 'turnip/capybara'\n", :after => "require 'rspec/rails'\n"
99
+ create_file 'spec/acceptance/steps/.gitkeep'
100
+ end
101
+ ## FIXTURE REPLACEMENTS
102
+ if prefer :fixtures, 'machinist'
103
+ say_wizard "generating blueprints file for 'machinist'"
104
+ generate 'machinist:install'
105
+ end
106
+ ### GIT ###
107
+ git :add => '.' if prefer :git, true
108
+ git :commit => "-aqm 'rails_apps_composer: testing framework'" if prefer :git, true
109
+ end # after_bundler
110
+
111
+ after_everything do
112
+ say_wizard "recipe running after everything"
113
+ ### RSPEC ###
114
+ if prefer :unit_test, 'rspec'
115
+ if (prefer :authentication, 'devise') && (prefer :starter_app, 'users_app')
116
+ say_wizard "copying RSpec files from the rails3-devise-rspec-cucumber examples"
117
+ repo = 'https://raw.github.com/RailsApps/rails3-devise-rspec-cucumber/master/'
118
+ copy_from_repo 'spec/factories/users.rb', :repo => repo
119
+ gsub_file 'spec/factories/users.rb', /# confirmed_at/, "confirmed_at" if (prefer :devise_modules, 'confirmable') || (prefer :devise_modules, 'invitable')
120
+ copy_from_repo 'spec/controllers/home_controller_spec.rb', :repo => repo
121
+ copy_from_repo 'spec/controllers/users_controller_spec.rb', :repo => repo
122
+ copy_from_repo 'spec/models/user_spec.rb', :repo => repo
123
+ remove_file 'spec/views/home/index.html.erb_spec.rb'
124
+ remove_file 'spec/views/home/index.html.haml_spec.rb'
125
+ remove_file 'spec/views/users/show.html.erb_spec.rb'
126
+ remove_file 'spec/views/users/show.html.haml_spec.rb'
127
+ remove_file 'spec/helpers/home_helper_spec.rb'
128
+ remove_file 'spec/helpers/users_helper_spec.rb'
129
+ end
130
+ ## RSPEC AND OMNIAUTH
131
+ if (prefer :authentication, 'omniauth') && (prefer :starter_app, 'users_app')
132
+ say_wizard "copying RSpec files from the rails3-mongoid-omniauth examples"
133
+ repo = 'https://raw.github.com/RailsApps/rails3-mongoid-omniauth/master/'
134
+ copy_from_repo 'spec/spec_helper.rb', :repo => repo
135
+ copy_from_repo 'spec/factories/users.rb', :repo => repo
136
+ copy_from_repo 'spec/controllers/sessions_controller_spec.rb', :repo => repo
137
+ copy_from_repo 'spec/controllers/home_controller_spec.rb', :repo => repo
138
+ copy_from_repo 'spec/controllers/users_controller_spec.rb', :repo => repo
139
+ copy_from_repo 'spec/models/user_spec.rb', :repo => repo
140
+ end
141
+ ## GIT
142
+ git :add => '.' if prefer :git, true
143
+ git :commit => "-aqm 'rails_apps_composer: rspec files'" if prefer :git, true
144
+ end
145
+ ### CUCUMBER ###
146
+ if prefer :integration, 'cucumber'
147
+ ## CUCUMBER AND DEVISE
148
+ if (prefer :authentication, 'devise') && (prefer :starter_app, 'users_app')
149
+ say_wizard "copying Cucumber scenarios from the rails3-devise-rspec-cucumber examples"
150
+ repo = 'https://raw.github.com/RailsApps/rails3-devise-rspec-cucumber/master/'
151
+ copy_from_repo 'spec/controllers/home_controller_spec.rb', :repo => repo
152
+ copy_from_repo 'features/users/sign_in.feature', :repo => repo
153
+ copy_from_repo 'features/users/sign_out.feature', :repo => repo
154
+ copy_from_repo 'features/users/sign_up.feature', :repo => repo
155
+ copy_from_repo 'features/users/user_edit.feature', :repo => repo
156
+ copy_from_repo 'features/users/user_show.feature', :repo => repo
157
+ copy_from_repo 'features/step_definitions/user_steps.rb', :repo => repo
158
+ copy_from_repo 'features/support/paths.rb', :repo => repo
159
+ if (prefer :devise_modules, 'confirmable') || (prefer :devise_modules, 'invitable')
160
+ 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."
161
+ inject_into_file 'features/users/sign_in.feature', :before => ' Scenario: User signs in successfully' do
162
+ <<-RUBY
163
+ Scenario: User has not confirmed account
164
+ Given I exist as an unconfirmed user
165
+ And I am not logged in
166
+ When I sign in with valid credentials
167
+ Then I see an unconfirmed account message
168
+ And I should be signed out
169
+ RUBY
170
+ end
171
+ end
172
+ end
173
+ ## GIT
174
+ git :add => '.' if prefer :git, true
175
+ git :commit => "-aqm 'rails_apps_composer: cucumber files'" if prefer :git, true
176
+ end
177
+ end # after_everything
178
+
179
+ __END__
180
+
181
+ name: testing
182
+ description: "Add testing framework."
183
+ author: RailsApps
184
+
185
+ requires: [setup, gems]
186
+ run_after: [setup, gems]
187
+ category: testing
data/recipes/views.rb ADDED
@@ -0,0 +1,39 @@
1
+ # Application template recipe for the rails_apps_composer. Change the recipe here:
2
+ # https://github.com/RailsApps/rails_apps_composer/blob/master/recipes/views.rb
3
+
4
+ after_bundler do
5
+ say_wizard "recipe running after 'bundle install'"
6
+ ### DEVISE ###
7
+ copy_from_repo 'app/views/devise/shared/_links.html.erb' if prefer :authentication, 'devise'
8
+ copy_from_repo 'app/views/devise/registrations/edit.html.erb' if prefer :authentication, 'devise'
9
+ copy_from_repo 'app/views/devise/registrations/new.html.erb' if prefer :authentication, 'devise'
10
+ ### HOME ###
11
+ copy_from_repo 'app/views/home/index.html.erb' if prefer :starter_app, 'users_app'
12
+ copy_from_repo 'app/views/home/index.html.erb' if prefer :starter_app, 'admin_app'
13
+ copy_from_repo 'app/views/home/index-subdomains_app.html.erb', :prefs => 'subdomains_app'
14
+ ### USERS ###
15
+ if ['users_app','admin_app','subdomains_app'].include? prefs[:starter_app]
16
+ ## INDEX
17
+ copy_from_repo 'app/views/users/index.html.erb'
18
+ ## SHOW
19
+ copy_from_repo 'app/views/users/show.html.erb'
20
+ copy_from_repo 'app/views/users/show-subdomains_app.html.erb', :prefs => 'subdomains_app'
21
+ ## EDIT
22
+ copy_from_repo 'app/views/users/edit-omniauth.html.erb', :prefs => 'omniauth'
23
+ end
24
+ ### PROFILES ###
25
+ copy_from_repo 'app/views/profiles/show-subdomains_app.html.erb', :prefs => 'subdomains_app'
26
+ ### GIT ###
27
+ git :add => '.' if prefer :git, true
28
+ git :commit => "-aqm 'rails_apps_composer: views'" if prefer :git, true
29
+ end # after_bundler
30
+
31
+ __END__
32
+
33
+ name: views
34
+ description: "Add views needed for starter apps."
35
+ author: RailsApps
36
+
37
+ requires: [setup, gems, auth, models, controllers]
38
+ run_after: [setup, gems, auth, models, controllers]
39
+ category: mvc
@@ -4,14 +4,16 @@ describe RailsWizard::Template do
4
4
  subject{ RailsWizard::Template }
5
5
  let(:recipe){ RailsWizard::Recipe.generate('name','# test') }
6
6
  let(:defaults){ { "some_option" => "value" } }
7
+ let(:gems){ ['foogem'] }
8
+ let(:args){ [] }
7
9
 
8
10
  describe '#initialize' do
9
11
  it 'should work with classes' do
10
- subject.new([recipe]).recipes.should == [recipe]
12
+ subject.new([recipe], gems).recipes.should == [recipe]
11
13
  end
12
14
 
13
15
  it 'should accept optional defaults' do
14
- subject.new([recipe], defaults).defaults.should == defaults
16
+ subject.new([recipe], gems, args, defaults).defaults.should == defaults
15
17
  end
16
18
  end
17
19
 
@@ -1,12 +1,17 @@
1
1
  def recipes; @recipes end
2
2
  def recipe?(name); @recipes.include?(name) end
3
+ def prefs; @prefs end
4
+ def prefer(key, value); @prefs[key].eql? value end
5
+ def gems; @gems end
6
+ def diagnostics_recipes; @diagnostics_recipes end
7
+ def diagnostics_prefs; @diagnostics_prefs end
3
8
 
4
9
  def say_custom(tag, text); say "\033[1m\033[36m" + tag.to_s.rjust(10) + "\033[0m" + " #{text}" end
5
10
  def say_recipe(name); say "\033[1m\033[36m" + "recipe".rjust(10) + "\033[0m" + " Running #{name} recipe..." end
6
- def say_wizard(text); say_custom(@current_recipe || 'wizard', text) end
11
+ def say_wizard(text); say_custom(@current_recipe || 'composer', text) end
7
12
 
8
13
  def ask_wizard(question)
9
- ask "\033[1m\033[30m\033[46m" + (@current_recipe || "prompt").rjust(10) + "\033[0m\033[36m" + " #{question}\033[0m"
14
+ ask "\033[1m\033[30m\033[46m" + (@current_recipe || "prompt").rjust(10) + "\033[1m\033[36m" + " #{question}\033[0m"
10
15
  end
11
16
 
12
17
  def yes_wizard?(question)
@@ -43,3 +48,49 @@ def after_bundler(&block); @after_blocks << [@current_recipe, block]; end
43
48
  def after_everything(&block); @after_everything_blocks << [@current_recipe, block]; end
44
49
  @before_configs = {}
45
50
  def before_config(&block); @before_configs[@current_recipe] = block; end
51
+
52
+ def copy_from_repo(filename, opts = {})
53
+ repo = 'https://raw.github.com/RailsApps/rails3-application-templates/master/files-v2/'
54
+ repo = opts[:repo] unless opts[:repo].nil?
55
+ if (!opts[:prefs].nil?) && (!prefs.has_value? opts[:prefs])
56
+ return
57
+ end
58
+ source_filename = filename
59
+ destination_filename = filename
60
+ unless opts[:prefs].nil?
61
+ if filename.include? opts[:prefs]
62
+ destination_filename = filename.gsub(/\-#{opts[:prefs]}/, '')
63
+ end
64
+ end
65
+ if (prefer :templates, 'haml') && (filename.include? 'views')
66
+ remove_file destination_filename
67
+ destination_filename = destination_filename.gsub(/.erb/, '.haml')
68
+ end
69
+ if (prefer :templates, 'slim') && (filename.include? 'views')
70
+ remove_file destination_filename
71
+ destination_filename = destination_filename.gsub(/.erb/, '.slim')
72
+ end
73
+ begin
74
+ remove_file destination_filename
75
+ if (prefer :templates, 'haml') && (filename.include? 'views')
76
+ create_file destination_filename, html_to_haml(repo + source_filename)
77
+ elsif (prefer :templates, 'slim') && (filename.include? 'views')
78
+ create_file destination_filename, html_to_slim(repo + source_filename)
79
+ else
80
+ get repo + source_filename, destination_filename
81
+ end
82
+ rescue OpenURI::HTTPError
83
+ say_wizard "Unable to obtain #{source_filename} from the repo #{repo}"
84
+ end
85
+ end
86
+
87
+ def html_to_haml(source)
88
+ html = open(source) {|input| input.binmode.read }
89
+ Haml::HTML.new(html, :erb => true, :xhtml => true).render
90
+ end
91
+
92
+ def html_to_slim(source)
93
+ html = open(source) {|input| input.binmode.read }
94
+ haml = Haml::HTML.new(html, :erb => true, :xhtml => true).render
95
+ Haml2Slim.convert!(haml)
96
+ end
data/templates/layout.erb CHANGED
@@ -1,15 +1,17 @@
1
1
  # >---------------------------------------------------------------------------<
2
2
  #
3
- # _____ _ _ __ ___ _
4
- # | __ \ (_) | \ \ / (_) | |
5
- # | |__) |__ _ _| |___\ \ /\ / / _ ______ _ _ __ __| |
6
- # | _ // _` | | / __|\ \/ \/ / | |_ / _` | '__/ _` |
7
- # | | \ \ (_| | | \__ \ \ /\ / | |/ / (_| | | | (_| |
8
- # |_| \_\__,_|_|_|___/ \/ \/ |_/___\__,_|_| \__,_|
3
+ # _____ _ _
4
+ # | __ \ (_) | /\
5
+ # | |__) |__ _ _| |___ / \ _ __ _ __ ___
6
+ # | _ // _` | | / __| / /\ \ | '_ \| '_ \/ __|
7
+ # | | \ \ (_| | | \__ \/ ____ \| |_) | |_) \__ \
8
+ # |_| \_\__,_|_|_|___/_/ \_\ .__/| .__/|___/
9
+ # | | | |
10
+ # |_| |_|
9
11
  #
10
- # This template was generated by rails_apps_composer, a custom version of
11
- # RailsWizard, the application template builder. For more information, see:
12
+ # Template generated by rails_apps_composer. For more information, see:
12
13
  # https://github.com/RailsApps/rails_apps_composer/
14
+ # Thank you to Michael Bleigh for leading the way with the RailsWizard gem.
13
15
  #
14
16
  # >---------------------------------------------------------------------------<
15
17
 
@@ -21,29 +23,40 @@ end
21
23
  RUBY
22
24
 
23
25
  @recipes = <%= resolve_recipes.map(&:key).inspect %>
26
+ @prefs = <%= resolve_preferences %>
27
+ @gems = <%= resolve_gems %>
28
+ @diagnostics_recipes = <%= resolve_diagnostics_recipes %>
29
+ @diagnostics_prefs = <%= resolve_diagnostics_prefs %>
30
+ diagnostics = {}
24
31
 
25
32
  <%= render "helpers" %>
26
33
 
34
+ if diagnostics_recipes.sort.include? recipes.sort
35
+ diagnostics[:recipes] = 'success'
36
+ say_wizard("WOOT! The recipes you've selected are known to work together.")
37
+ else
38
+ diagnostics[:recipes] = 'fail'
39
+ say_wizard("\033[1m\033[36m" + "WARNING! The recipes you've selected might not work together." + "\033[0m")
40
+ say_wizard("Help us out by reporting whether this combination works or fails.")
41
+ say_wizard("Please open an issue for rails_apps_composer on GitHub.")
42
+ say_wizard("Your new application will contain diagnostics in its README file.")
43
+ say_wizard("Continuing...")
44
+ end
45
+
27
46
  # this application template only supports Rails version 3.1 and newer
28
47
  case Rails::VERSION::MAJOR.to_s
29
48
  when "3"
30
49
  case Rails::VERSION::MINOR.to_s
31
- when "2"
32
- say_wizard "You are using Rails version #{Rails::VERSION::STRING}."
33
- when "1"
34
- say_wizard "You are using Rails version #{Rails::VERSION::STRING}."
35
50
  when "0"
36
51
  say_wizard "You are using Rails version #{Rails::VERSION::STRING} which is not supported. Try 3.1 or newer."
37
52
  raise StandardError.new "Rails #{Rails::VERSION::STRING} is not supported. Try 3.1 or newer."
38
- else
39
- say_wizard "You are using Rails version #{Rails::VERSION::STRING}."
40
53
  end
41
54
  else
42
55
  say_wizard "You are using Rails version #{Rails::VERSION::STRING} which is not supported. Try 3.1 or newer."
43
56
  raise StandardError.new "Rails #{Rails::VERSION::STRING} is not supported. Try 3.1 or newer."
44
57
  end
45
58
 
46
- say_wizard "Checking configuration. Please confirm your preferences."
59
+ say_wizard "Using rails_apps_composer recipes to generate an application."
47
60
 
48
61
  # >---------------------------[ Autoload Modules/Classes ]-----------------------------<
49
62
 
@@ -59,25 +72,73 @@ end
59
72
  <%= render 'recipe', recipe.get_binding %>
60
73
  <% end %>
61
74
 
75
+ # >---------------------------------[ Diagnostics ]----------------------------------<
76
+
77
+ # remove prefs which are diagnostically irrelevant
78
+ redacted_prefs = prefs
79
+ redacted_prefs.delete(:git)
80
+ redacted_prefs.delete(:dev_webserver)
81
+ redacted_prefs.delete(:prod_webserver)
82
+ redacted_prefs.delete(:ban_spiders)
83
+ redacted_prefs.delete(:jsruntime)
84
+ redacted_prefs.delete(:rvmrc)
85
+
86
+ if diagnostics_prefs.include? redacted_prefs
87
+ diagnostics[:prefs] = 'success'
88
+ else
89
+ diagnostics[:prefs] = 'fail'
90
+ end
91
+
62
92
  <% if custom_code? %># >-----------------------------[ Custom Code ]-------------------------------<
63
93
 
64
94
  <%= custom_code %><% end %>
65
95
 
66
96
  @current_recipe = nil
67
97
 
68
- # >-----------------------------[ Run Bundler ]-------------------------------<
98
+ # >-----------------------------[ Run 'Bundle Install' ]-------------------------------<
99
+
100
+ say_wizard "Installing gems. This will take a while."
101
+ run 'bundle install --without production'
102
+
103
+ # >-----------------------------[ Run 'After Bundler' Callbacks ]-------------------------------<
69
104
 
70
- say_wizard "Running 'bundle install'. This will take a while."
71
- run 'bundle install'
72
- run 'bundle update'
73
105
  say_wizard "Running 'after bundler' callbacks."
74
106
  require 'bundler/setup'
107
+ if prefer :templates, 'haml'
108
+ say_wizard "importing html2haml conversion tool"
109
+ require 'haml/html'
110
+ end
111
+ if prefer :templates, 'slim'
112
+ say_wizard "importing html2haml and haml2slim conversion tools"
113
+ require 'haml/html'
114
+ require 'haml2slim'
115
+ end
75
116
  @after_blocks.each{|b| config = @configs[b[0]] || {}; @current_recipe = b[0]; b[1].call}
76
117
 
118
+ # >-----------------------------[ Run 'After Everything' Callbacks ]-------------------------------<
119
+
77
120
  @current_recipe = nil
78
121
  say_wizard "Running 'after everything' callbacks."
79
122
  @after_everything_blocks.each{|b| config = @configs[b[0]] || {}; @current_recipe = b[0]; b[1].call}
80
123
 
81
124
  @current_recipe = nil
125
+ if diagnostics[:recipes] == 'success'
126
+ say_wizard("WOOT! The recipes you've selected are known to work together.")
127
+ say_wizard("If they don't, open an issue for rails_apps_composer on GitHub.")
128
+ else
129
+ say_wizard("\033[1m\033[36m" + "WARNING! The recipes you've selected might not work together." + "\033[0m")
130
+ say_wizard("Help us out by reporting whether this combination works or fails.")
131
+ say_wizard("Please open an issue for rails_apps_composer on GitHub.")
132
+ say_wizard("Your new application will contain diagnostics in its README file.")
133
+ end
134
+ if diagnostics[:prefs] == 'success'
135
+ say_wizard("WOOT! The preferences you've selected are known to work together.")
136
+ say_wizard("If they don't, open an issue for rails_apps_composer on GitHub.")
137
+ else
138
+ say_wizard("\033[1m\033[36m" + "WARNING! The preferences you've selected might not work together." + "\033[0m")
139
+ say_wizard("Help us out by reporting whether this combination works or fails.")
140
+ say_wizard("Please open an issue for rails_apps_composer on GitHub.")
141
+ say_wizard("Your new application will contain diagnostics in its README file.")
142
+ end
82
143
  say_wizard "Finished running the rails_apps_composer app template."
83
- say_wizard "Your new Rails app is ready."
144
+ say_wizard "Your new Rails app is ready. Time to run 'bundle install'."
data/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module RailsWizard
2
- VERSION = "1.5.5"
2
+ VERSION = "2.0.1"
3
3
  end