Permalink
Browse files

obtain preferences from a defaults file

  • Loading branch information...
1 parent 66cf0ca commit 76ada65ce0d9839d0b1b874f80e2a8cd7c2fa3d9 @DanielKehoe DanielKehoe committed Jul 30, 2012
View
@@ -2,11 +2,14 @@ h1. CHANGELOG
h2. 2.0 unreleased
-* reorganize recipes for easier maintenance
-* more extensive downloading of files from the example app repos on GitHub
+* extensive conditional configuration options (the 'quiz')
+* 'quiz' preferences can be set in a 'defaults' file
+* recipes reorganized for easier maintenance
+* removed recipes that are outdated or unsupported
+* more downloading of files from the example app repos on GitHub to reduce inline code
* new 'copy_from_repo' method in helpers.erb
* conversion of ERB files to Haml or Slim as needed in helpers.erb
-* new recipe: 'setup' allows conditional configuration options
+* new recipe: 'setup' for conditional configuration options (the 'quiz')
* new recipe: 'readme' to build README files that provide greater detail
* new recipe: 'gems' collects all the gems in one recipe for easier updating
* new recipe: 'testing' combines rspec and cucumber options with fixture replacements
View
@@ -47,3 +47,11 @@ task :print do
recipes = ENV['RECIPES'].split(',')
puts RailsWizard::Template.new(recipes).compile
end
+
+desc "uninstall rails_apps_composer gem and install a new version"
+task :reinstall do
+ Rake::Task['clobber'].invoke
+ Rake::Task['gem'].invoke
+ Rake::Task['gem:install'].invoke
+ puts "installed new rails_apps_composer #{RailsWizard::VERSION}"
+end
@@ -5,6 +5,7 @@ class Template
def initialize(recipes, defaults={})
@recipes = recipes.map{|r| RailsWizard::Recipe.from_mongo(r)}
@defaults = defaults
+ @prefs = defaults['prefs']
end
def self.template_root
@@ -17,7 +18,12 @@ def self.render(template_name, binding = nil)
end
def render(template_name, binding = nil); self.class.render(template_name, binding) end
-
+ def resolve_preferences
+ @resolve_preferences ||= begin
+ @prefs.inspect
+ end
+ end
+
# Sort the recipes list taking 'run_after' directives into account.
def resolve_recipes
@resolve_recipes ||= begin
View
@@ -4,31 +4,31 @@
after_bundler do
say_wizard "recipe running after 'bundle install'"
### DEVISE ###
- if recipes.include? 'devise'
+ if prefer :authentication, 'devise'
# Prevent logging of password_confirmation
gsub_file 'config/application.rb', /:password/, ':password, :password_confirmation'
generate 'devise:install'
- generate 'devise_invitable:install' if recipes.include? 'devise-invitable'
+ generate 'devise_invitable:install' if prefer :devise_modules, 'invitable'
generate 'devise user'
## DEVISE AND CUCUMBER
- if recipes.include? 'cucumber'
+ if prefer :integration, 'cucumber'
# Cucumber wants to test GET requests not DELETE requests for destroy_user_session_path
# (see https://github.com/RailsApps/rails3-devise-rspec-cucumber/issues/3)
gsub_file 'config/initializers/devise.rb', 'config.sign_out_via = :delete', 'config.sign_out_via = Rails.env.test? ? :get : :delete'
end
## DEVISE MODULES
- if recipes.include? 'devise-confirmable'
+ if (prefer :devise_modules, 'confirmable') || (prefer :devise_modules, 'invitable')
gsub_file 'app/models/user.rb', /:registerable,/, ":registerable, :confirmable,"
gsub_file 'app/models/user.rb', /:remember_me/, ':remember_me, :confirmed_at'
- if recipes.include? 'mongoid'
+ if prefer :orm, 'mongoid'
gsub_file 'app/models/user.rb', /# field :confirmation_token/, "field :confirmation_token"
gsub_file 'app/models/user.rb', /# field :confirmed_at/, "field :confirmed_at"
gsub_file 'app/models/user.rb', /# field :confirmation_sent_at/, "field :confirmation_sent_at"
gsub_file 'app/models/user.rb', /# field :unconfirmed_email/, "field :unconfirmed_email"
end
end
- if recipes.include? 'devise-invitable'
- if recipes.include? 'mongoid'
+ if prefer :devise_modules, 'invitable'
+ if prefer :orm, 'mongoid'
gsub_file 'app/models/user.rb', /\bend\s*\Z/ do
<<-RUBY
#invitable
@@ -45,25 +45,19 @@
end
end
### OMNIAUTH ###
- if recipes.include? 'omniauth'
- provider = 'twitter' if recipes.include? 'twitter'
- provider = 'facebook' if recipes.include? 'facebook'
- provider = 'github' if recipes.include? 'github'
- provider = 'linkedin' if recipes.include? 'linkedin'
- provider = 'google-oauth2' if recipes.include? 'google-oauth2'
- provider = 'tumblr' if recipes.include? 'tumblr'
+ if prefer :authentication, 'omniauth'
# Don't use single-quote-style-heredoc: we want interpolation.
create_file 'config/initializers/omniauth.rb' do <<-RUBY
Rails.application.config.middleware.use OmniAuth::Builder do
- provider :#{provider}, ENV['OMNIAUTH_PROVIDER_KEY'], ENV['OMNIAUTH_PROVIDER_SECRET']
+ provider :#{prefs[:omniauth_provider]}, ENV['OMNIAUTH_PROVIDER_KEY'], ENV['OMNIAUTH_PROVIDER_SECRET']
end
RUBY
end
end
### CANCAN ###
- if recipes.include? 'cancan'
+ if prefer :authorization, 'cancan'
generate 'cancan:ability'
- if recipes.include? 'admin_dashboard'
+ if prefer :starter_app, 'admin_dashboard'
# Limit access to the users#index page
inject_into_file 'app/models/ability.rb', :after => "def initialize(user)\n" do <<-RUBY
user ||= User.new # guest user (not logged in)
@@ -75,8 +69,8 @@
end
end
### GIT ###
- git :add => '.' if recipes.include? 'git'
- git :commit => "-aqm 'rails_apps_composer: authentication and authorization'" if recipes.include? 'git'
+ git :add => '.' if prefer :git, true
+ git :commit => "-aqm 'rails_apps_composer: authentication and authorization'" if prefer :git, true
end # after_bundler
__END__
View
@@ -4,10 +4,10 @@
after_bundler do
say_wizard "recipe running after 'bundle install'"
### APPLICATION_CONTROLLER ###
- if recipes.include? 'omniauth'
+ if prefer :authentication, 'omniauth'
copy_from_repo 'app/controllers/application_controller.rb', :repo => 'https://raw.github.com/RailsApps/rails3-mongoid-omniauth/master/'
end
- if recipes.include? 'cancan'
+ if prefer :authorization, 'cancan'
inject_into_file 'app/controllers/application_controller.rb', :before => 'end' do <<-RUBY
rescue_from CanCan::AccessDenied do |exception|
redirect_to root_path, :alert => exception.message
@@ -16,40 +16,35 @@
end
end
### HOME_CONTROLLER ###
- if recipes.include? 'simple_home'
+ if ['home_app','users_app','admin_app','subdomains_app'].include? prefs[:starter_app]
generate(:controller, "home index")
end
- if recipes.include? 'user_accounts'
+ if ['users_app','admin_app','subdomains_app'].include? prefs[:starter_app]
gsub_file 'app/controllers/home_controller.rb', /def index/, "def index\n @users = User.all"
end
### USERS_CONTROLLER ###
- if recipes.include? 'user_accounts'
- if recipes.include? 'devise'
+ if ['users_app','admin_app','subdomains_app'].include? prefs[:starter_app]
+ if prefer :authentication, 'devise'
copy_from_repo 'app/controllers/users_controller.rb', :repo => 'https://raw.github.com/RailsApps/rails3-devise-rspec-cucumber/master/'
- elsif recipes.include? 'omniauth'
+ elsif prefer :authentication, 'omniauth'
copy_from_repo 'app/controllers/users_controller.rb', :repo => 'https://raw.github.com/RailsApps/rails3-mongoid-omniauth/master/'
end
- if recipes.include? 'cancan'
+ if prefer :authorization, 'cancan'
inject_into_file 'app/controllers/users_controller.rb', " authorize! :index, @user, :message => 'Not authorized as an administrator.'\n", :after => "def index\n"
end
end
- gsub_file 'app/controllers/users_controller.rb', /before_filter :authenticate_user!/, '' if recipes.include? 'subdomains'
+ gsub_file 'app/controllers/users_controller.rb', /before_filter :authenticate_user!/, '' if prefer :starter_app, 'subdomains'
### SESSIONS_CONTROLLER ###
- if recipes.include? 'omniauth'
+ if prefer :authentication, 'omniauth'
filename = 'app/controllers/sessions_controller.rb'
copy_from_repo filename, :repo => 'https://raw.github.com/RailsApps/rails3-mongoid-omniauth/master/'
- provider = 'facebook' if recipes.include? 'facebook'
- provider = 'github' if recipes.include? 'github'
- provider = 'linkedin' if recipes.include? 'linkedin'
- provider = 'google-oauth2' if recipes.include? 'google-oauth2'
- provider = 'tumblr' if recipes.include? 'tumblr'
- gsub_file filename, /twitter/, provider unless recipes.include? 'twitter'
+ gsub_file filename, /twitter/, prefs[:omniauth_provider] unless prefer :omniauth_provider, 'twitter'
end
### PROFILES_CONTROLLER ###
- copy_from_repo 'app/controllers/profiles_controller.rb', :repo => 'https://raw.github.com/RailsApps/rails3-subdomains/master/' if recipes.include? 'subdomains'
+ copy_from_repo 'app/controllers/profiles_controller.rb', :repo => 'https://raw.github.com/RailsApps/rails3-subdomains/master/' if prefer :starter_app, 'subdomains'
### GIT ###
- git :add => '.' if recipes.include? 'git'
- git :commit => "-aqm 'rails_apps_composer: controllers'" if recipes.include? 'git'
+ git :add => '.' if prefer :git, true
+ git :commit => "-aqm 'rails_apps_composer: controllers'" if prefer :git, true
end # after_bundler
__END__
View
@@ -4,8 +4,8 @@
after_everything do
say_wizard "recipe running after everything"
### PREPARE SEED ###
- if recipes.include? 'devise'
- if recipes.include? 'devise-confirmable'
+ if prefer :authentication, 'devise'
+ if (prefer :devise_modules, 'confirmable') || (prefer :devise_modules, 'invitable')
## DEVISE-CONFIRMABLE
append_file 'db/seeds.rb' do <<-FILE
puts 'SETTING UP DEFAULT USER LOGIN'
@@ -26,24 +26,24 @@
FILE
end
end
- if recipes.include? 'subdomains'
+ if prefer :starter_app, 'subdomains'
gsub_file 'db/seeds.rb', /First User/, 'user1'
gsub_file 'db/seeds.rb', /Second User/, 'user2'
end
- if recipes.include? 'cancan'
+ if prefer :authorization, 'cancan'
append_file 'db/seeds.rb' do <<-FILE
user.add_role :admin
FILE
end
end
## DEVISE-INVITABLE
- if recipes.include? 'devise-invitable'
+ if prefer :devise_modules, 'invitable'
run 'bundle exec rake db:migrate'
generate 'devise_invitable user'
end
end
### APPLY SEED ###
- unless recipes.include? 'mongoid'
+ unless prefer :orm, 'mongoid'
## MONGOID
say_wizard "applying migrations and seeding the database"
run 'bundle exec rake db:migrate'
@@ -56,8 +56,8 @@
end
run 'bundle exec rake db:seed'
### GIT ###
- git :add => '.' if recipes.include? 'git'
- git :commit => "-aqm 'rails_apps_composer: set up database'" if recipes.include? 'git'
+ git :add => '.' if prefer :git, true
+ git :commit => "-aqm 'rails_apps_composer: set up database'" if prefer :git, true
end # after_everything
__END__
View
@@ -3,7 +3,7 @@
after_bundler do
say_wizard "recipe running after 'bundle install'"
- if recipes.include? 'email'
+ unless prefer :email, 'none'
### DEVELOPMENT
gsub_file 'config/environments/development.rb', /# Don't care if the mailer can't send/, '# ActionMailer Config'
gsub_file 'config/environments/development.rb', /config.action_mailer.raise_delivery_errors = false/ do
@@ -40,7 +40,7 @@
end
end
### GMAIL ACCOUNT
- if recipes.include? 'gmail'
+ if prefer :email, 'gmail'
gmail_configuration_text = <<-TEXT
\n
config.action_mailer.smtp_settings = {
@@ -57,7 +57,7 @@
inject_into_file 'config/environments/production.rb', gmail_configuration_text, :after => 'config.action_mailer.default :charset => "utf-8"'
end
### SENDGRID ACCOUNT
- if recipes.include? 'sendgrid'
+ if prefer :email, 'sendgrid'
sendgrid_configuration_text = <<-TEXT
\n
config.action_mailer.smtp_settings = {
@@ -73,7 +73,7 @@
inject_into_file 'config/environments/production.rb', sendgrid_configuration_text, :after => 'config.action_mailer.default :charset => "utf-8"'
end
### MANDRILL ACCOUNT
- if recipes.include? 'mandrill'
+ if prefer :email, 'mandrill'
mandrill_configuration_text = <<-TEXT
\n
config.action_mailer.smtp_settings = {
@@ -87,8 +87,8 @@
inject_into_file 'config/environments/production.rb', mandrill_configuration_text, :after => 'config.action_mailer.default :charset => "utf-8"'
end
### GIT
- git :add => '.' if recipes.include? 'git'
- git :commit => "-aqm 'rails_apps_composer: set email accounts'" if recipes.include? 'git'
+ git :add => '.' if prefer :git, true
+ git :commit => "-aqm 'rails_apps_composer: set email accounts'" if prefer :git, true
end # after_bundler
__END__
View
@@ -12,7 +12,7 @@
if config['jsruntime']
say_wizard "Adding 'therubyracer' JavaScript runtime gem"
# maybe it was already added for bootstrap-less?
- unless recipes.include? 'bootstrap-less'
+ unless prefer :bootstrap, 'less'
gem 'therubyracer', :group => :assets, :platform => :ruby
end
end
@@ -59,8 +59,8 @@
gsub_file 'config/routes.rb', / #.*\n/, "\n"
gsub_file 'config/routes.rb', /\n^\s*\n/, "\n"
# GIT
- git :add => '.' if recipes.include? 'git'
- git :commit => "-aqm 'rails_apps_composer: starter app complete'" if recipes.include? 'git'
+ git :add => '.' if prefer :git, true
+ git :commit => "-aqm 'rails_apps_composer: starter app complete'" if prefer :git, true
end
__END__
View
@@ -5,51 +5,51 @@
say_wizard "recipe running after 'bundle install'"
### LAYOUTS ###
copy_from_repo 'app/views/layouts/application.html.erb'
- copy_from_repo 'app/views/layouts/application-bootstrap.html.erb', :recipe => 'bootstrap'
+ copy_from_repo 'app/views/layouts/application-bootstrap.html.erb', :prefs => 'bootstrap'
copy_from_repo 'app/views/layouts/_messages.html.erb'
- copy_from_repo 'app/views/layouts/_messages-bootstrap.html.erb', :recipe => 'bootstrap'
+ copy_from_repo 'app/views/layouts/_messages-bootstrap.html.erb', :prefs => 'bootstrap'
copy_from_repo 'app/views/layouts/_navigation.html.erb'
- copy_from_repo 'app/views/layouts/_navigation-devise.html.erb', :recipe => 'devise'
- copy_from_repo 'app/views/layouts/_navigation-cancan.html.erb', :recipe => 'cancan'
- copy_from_repo 'app/views/layouts/_navigation-omniauth.html.erb', :recipe => 'omniauth'
- copy_from_repo 'app/views/layouts/_navigation-subdomains.html.erb', :recipe => 'subdomains'
+ copy_from_repo 'app/views/layouts/_navigation-devise.html.erb', :prefs => 'devise'
+ copy_from_repo 'app/views/layouts/_navigation-cancan.html.erb', :prefs => 'cancan'
+ copy_from_repo 'app/views/layouts/_navigation-omniauth.html.erb', :prefs => 'omniauth'
+ copy_from_repo 'app/views/layouts/_navigation-subdomains_app.html.erb', :prefs => 'subdomains_app'
## APPLICATION NAME
application_layout_file = 'app/views/layouts/application.html.erb'
- application_layout_file = 'app/views/layouts/application.html.haml' if recipes.include? 'haml'
- application_layout_file = 'app/views/layouts/application.html.slim' if recipes.include? 'slim'
+ application_layout_file = 'app/views/layouts/application.html.haml' if prefer :templates, 'haml'
+ application_layout_file = 'app/views/layouts/application.html.slim' if prefer :templates, 'slim'
navigation_partial_file = 'app/views/layouts/_navigation.html.erb'
- navigation_partial_file = 'app/views/layouts/_navigation.html.haml' if recipes.include? 'haml'
- navigation_partial_file = 'app/views/layouts/_navigation.html.slim' if recipes.include? 'slim'
+ navigation_partial_file = 'app/views/layouts/_navigation.html.haml' if prefer :templates, 'haml'
+ navigation_partial_file = 'app/views/layouts/_navigation.html.slim' if prefer :templates, 'slim'
gsub_file application_layout_file, /App_Name/, "#{app_name.humanize.titleize}"
gsub_file navigation_partial_file, /App_Name/, "#{app_name.humanize.titleize}"
### CSS ###
remove_file 'app/assets/stylesheets/application.css'
copy_from_repo 'app/assets/stylesheets/application.css.scss'
- copy_from_repo 'app/assets/stylesheets/application-bootstrap.css.scss', :recipe => 'bootstrap'
- if recipes.include? 'bootstrap-less'
+ copy_from_repo 'app/assets/stylesheets/application-bootstrap.css.scss', :prefs => 'bootstrap'
+ if prefer :bootstrap, 'less'
generate 'bootstrap:install'
insert_into_file 'app/assets/stylesheets/bootstrap_and_overrides.css.less', "body { padding-top: 60px; }\n", :after => "@import \"twitter/bootstrap/bootstrap\";\n"
- elsif recipes.include? 'bootstrap-sass'
+ elsif prefer :bootstrap, 'sass'
insert_into_file 'app/assets/javascripts/application.js', "//= require bootstrap\n", :after => "jquery_ujs\n"
create_file 'app/assets/stylesheets/bootstrap_and_overrides.css.scss', <<-RUBY
@import "bootstrap";
body { padding-top: 60px; }
@import "bootstrap-responsive";
RUBY
- elsif recipes.include? 'foundation'
+ elsif prefer :frontend, 'foundation'
insert_into_file 'app/assets/javascripts/application.js', "//= require foundation\n", :after => "jquery_ujs\n"
insert_into_file 'app/assets/stylesheets/application.css.scss', " *= require foundation\n", :after => "require_self\n"
- elsif recipes.include? 'skeleton'
+ elsif prefer :frontend, 'skeleton'
copy_from_repo 'app/assets/stylesheets/normalize.css.scss', :repo => 'https://raw.github.com/necolas/normalize.css/master/normalize.css'
copy_from_repo 'app/assets/stylesheets/base.css.scss', :repo => 'https://raw.github.com/dhgamache/Skeleton/master/stylesheets/base.css'
copy_from_repo 'app/assets/stylesheets/layout.css.scss', :repo => 'https://raw.github.com/dhgamache/Skeleton/master/stylesheets/layout.css'
copy_from_repo 'app/assets/stylesheets/skeleton.css.scss', :repo => 'https://raw.github.com/dhgamache/Skeleton/master/stylesheets/skeleton.css'
- elsif recipes.include? 'normalize'
+ elsif prefer :frontend, 'normalize'
copy_from_repo 'app/assets/stylesheets/normalize.css.scss', :repo => 'https://raw.github.com/necolas/normalize.css/master/normalize.css'
end
### GIT ###
- git :add => '.' if recipes.include? 'git'
- git :commit => "-aqm 'rails_apps_composer: front-end framework'" if recipes.include? 'git'
+ git :add => '.' if prefer :git, true
+ git :commit => "-aqm 'rails_apps_composer: front-end framework'" if prefer :git, true
end # after_bundler
__END__
Oops, something went wrong.

0 comments on commit 76ada65

Please sign in to comment.