etc/rails/template.rb in zsh_dots-0.5.1 vs etc/rails/template.rb in zsh_dots-0.5.3

- old
+ new

@@ -1,1419 +1,46 @@ -# >---------------------------------------------------------------------------< # -# _____ _ _ -# | __ \ (_) | /\ -# | |__) |__ _ _| |___ / \ _ __ _ __ ___ -# | _ // _` | | / __| / /\ \ | '_ \| '_ \/ __| -# | | \ \ (_| | | \__ \/ ____ \| |_) | |_) \__ \ -# |_| \_\__,_|_|_|___/_/ \_\ .__/| .__/|___/ -# | | | | -# |_| |_| +# Default Rails application template # -# Template generated by rails_apps_composer. For more information, see: -# https://github.com/RailsApps/rails_apps_composer/ -# Thank you to Michael Bleigh for leading the way with the RailsWizard gem. -# -# >---------------------------------------------------------------------------< -# >----------------------------[ Initial Setup ]------------------------------< +gem 'haml' -initializer 'generators.rb', <<-RUBY -Rails.application.config.generators do |g| +gem_group :development do + gem 'haml-rails' + gem 'ruby_parser' + gem 'hpricot' + gem 'puma' end -RUBY -@recipes = ["git", "setup", "readme_markdown", "gems", "testing", "auth", "models", "controllers", "views", "haml_views", "routes", "frontend", "html5", "extras"] -@prefs = {:dev_webserver=>"thin", :prod_webserver=>"unicorn", :database=>"postgresql", :templates=>"haml", :unit_test=>"minitest", :integration=>"capybara", :fixtures=>"factory_girl", :frontend=>"bootstrap", :bootstrap=>"sass", :form_builder=>"simpleform", :email=>"gmail", :authentication=>"devise", :devise_modules=>"default", :authorization=>"none"} -@gems = [] -@diagnostics_recipes = [["example"], ["setup"], ["railsapps"], ["gems", "setup"], ["gems", "readme", "setup"], ["extras", "gems", "readme", "setup"], ["example", "git"], ["git", "setup"], ["git", "railsapps"], ["gems", "git", "setup"], ["gems", "git", "readme", "setup"], ["extras", "gems", "git", "readme", "setup"], ["auth", "controllers", "email", "extras", "frontend", "gems", "git", "init", "models", "railsapps", "readme", "routes", "setup", "testing", "views"], ["all", "auth", "controllers", "email", "extras", "frontend", "gems", "git", "init", "models", "railsapps", "readme", "routes", "setup", "testing", "views"], ["auth", "controllers", "email", "example", "extras", "frontend", "gems", "git", "init", "models", "railsapps", "readme", "routes", "setup", "testing", "views"], ["auth", "controllers", "email", "example", "extras", "frontend", "gems", "git", "init", "models", "prelaunch", "railsapps", "readme", "routes", "setup", "testing", "views"], ["all", "auth", "controllers", "email", "example", "extras", "frontend", "gems", "git", "init", "models", "prelaunch", "railsapps", "readme", "routes", "setup", "testing", "views"]] -@diagnostics_prefs = [{:railsapps=>"rails3-bootstrap-devise-cancan", :database=>"sqlite", :templates=>"erb", :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=>"none"}, {:railsapps=>"rails3-devise-rspec-cucumber", :database=>"sqlite", :templates=>"erb", :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"}, {:railsapps=>"rails3-mongoid-devise", :database=>"mongodb", :orm=>"mongoid", :templates=>"erb", :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"}, {:railsapps=>"rails3-mongoid-omniauth", :database=>"mongodb", :orm=>"mongoid", :templates=>"erb", :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"}, {:railsapps=>"rails3-subdomains", :database=>"mongodb", :orm=>"mongoid", :templates=>"haml", :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"}] -diagnostics = {} - -def recipes; @recipes end -def recipe?(name); @recipes.include?(name) end -def prefs; @prefs end -def prefer(key, value); @prefs[key].eql? value end -def gems; @gems end -def diagnostics_recipes; @diagnostics_recipes end -def diagnostics_prefs; @diagnostics_prefs end - -def say_custom(tag, text); say "\033[1m\033[36m" + tag.to_s.rjust(10) + "\033[0m" + " #{text}" end -def say_recipe(name); say "\033[1m\033[36m" + "recipe".rjust(10) + "\033[0m" + " Running #{name} recipe..." end -def say_wizard(text); say_custom(@current_recipe || 'composer', text) end - -def ask_wizard(question) - ask "\033[1m\033[30m\033[46m" + (@current_recipe || "prompt").rjust(10) + "\033[1m\033[36m" + " #{question}\033[0m" +gem_group :test do + gem 'rspec-rails' + gem 'capybara' end -def yes_wizard?(question) - answer = ask_wizard(question + " \033[33m(y/n)\033[0m") - case answer.downcase - when "yes", "y" - true - when "no", "n" - false - else - yes_wizard?(question) - end +initializer "generators.rb", <<-RUBY +Rails.application.config.generators do |g| + g.template_engine :haml + g.test_framework :rspec, fixtures: true, fixture_location: "spec/fixtures" end - -def no_wizard?(question); !yes_wizard?(question) end - -def multiple_choice(question, choices) - say_custom('question', question) - values = {} - choices.each_with_index do |choice,i| - values[(i + 1).to_s] = choice[1] - say_custom (i + 1).to_s + ')', choice[0] - end - answer = ask_wizard("Enter your selection:") while !values.keys.include?(answer) - values[answer] -end - -@current_recipe = nil -@configs = {} - -@after_blocks = [] -def after_bundler(&block); @after_blocks << [@current_recipe, block]; end -@after_everything_blocks = [] -def after_everything(&block); @after_everything_blocks << [@current_recipe, block]; end -@before_configs = {} -def before_config(&block); @before_configs[@current_recipe] = block; end - -def copy_from(source, destination) - begin - remove_file destination - get source, destination - rescue OpenURI::HTTPError - say_wizard "Unable to obtain #{source}" - end -end - -def copy_from_repo(filename, opts = {}) - repo = 'https://raw.github.com/RailsApps/rails-composer/master/files/' - repo = opts[:repo] unless opts[:repo].nil? - if (!opts[:prefs].nil?) && (!prefs.has_value? opts[:prefs]) - return - end - source_filename = filename - destination_filename = filename - unless opts[:prefs].nil? - if filename.include? opts[:prefs] - destination_filename = filename.gsub(/\-#{opts[:prefs]}/, '') - end - end - if (prefer :templates, 'haml') && (filename.include? 'views') - remove_file destination_filename - destination_filename = destination_filename.gsub(/.erb/, '.haml') - end - if (prefer :templates, 'slim') && (filename.include? 'views') - remove_file destination_filename - destination_filename = destination_filename.gsub(/.erb/, '.slim') - end - begin - remove_file destination_filename - if (prefer :templates, 'haml') && (filename.include? 'views') - create_file destination_filename, html_to_haml(repo + source_filename) - elsif (prefer :templates, 'slim') && (filename.include? 'views') - create_file destination_filename, html_to_slim(repo + source_filename) - else - get repo + source_filename, destination_filename - end - rescue OpenURI::HTTPError - say_wizard "Unable to obtain #{source_filename} from the repo #{repo}" - end -end - -def html_to_haml(source) - html = open(source) {|input| input.binmode.read } - Haml::HTML.new(html, :erb => true, :xhtml => true).render -end - -def html_to_slim(source) - html = open(source) {|input| input.binmode.read } - haml = Haml::HTML.new(html, :erb => true, :xhtml => true).render - Haml2Slim.convert!(haml) -end - - -if diagnostics_recipes.sort.include? recipes.sort - diagnostics[:recipes] = 'success' - say_wizard("WOOT! The recipes you've selected are known to work together.") -else - diagnostics[:recipes] = 'fail' - say_wizard("\033[1m\033[36m" + "WARNING! The recipes you've selected might not work together." + "\033[0m") - say_wizard("Help us out by reporting whether this combination works or fails.") - say_wizard("Please open an issue for rails_apps_composer on GitHub.") - say_wizard("Your new application will contain diagnostics in its README file.") - say_wizard("Continuing...") -end - -# this application template only supports Rails version 3.1 and newer -case Rails::VERSION::MAJOR.to_s -when "3" - case Rails::VERSION::MINOR.to_s - when "0" - say_wizard "You are using Rails version #{Rails::VERSION::STRING} which is not supported. Try 3.1 or newer." - raise StandardError.new "Rails #{Rails::VERSION::STRING} is not supported. Try 3.1 or newer." - end -else - say_wizard "You are using Rails version #{Rails::VERSION::STRING} which is not supported. Try 3.1 or newer." - raise StandardError.new "Rails #{Rails::VERSION::STRING} is not supported. Try 3.1 or newer." -end - -say_wizard "Using rails_apps_composer recipes to generate an application." - -# >---------------------------[ Autoload Modules/Classes ]-----------------------------< - -inject_into_file 'config/application.rb', :after => 'config.autoload_paths += %W(#{config.root}/extras)' do <<-'RUBY' - - config.autoload_paths += %W(#{config.root}/lib) RUBY -end -# >---------------------------------[ Recipes ]----------------------------------< - - -# >----------------------------------[ git ]----------------------------------< - -@current_recipe = "git" -@before_configs["git"].call if @before_configs["git"] -say_recipe 'git' - - -@configs[@current_recipe] = config - -# Application template recipe for the rails_apps_composer. Change the recipe here: -# https://github.com/RailsApps/rails_apps_composer/blob/master/recipes/git.rb - -## Git -say_wizard "initialize git" -prefs[:git] = true unless prefs.has_key? :git -if prefer :git, true - copy_from 'https://raw.github.com/RailsApps/rails-composer/master/files/gitignore.txt', '.gitignore' - git :init - git :add => '.' - git :commit => "-aqm 'rails_apps_composer: initial commit'" -end - - -# >---------------------------------[ setup ]---------------------------------< - -@current_recipe = "setup" -@before_configs["setup"].call if @before_configs["setup"] -say_recipe 'setup' - - -@configs[@current_recipe] = config - -# Application template recipe for the rails_apps_composer. Change the recipe here: -# https://github.com/RailsApps/rails_apps_composer/blob/master/recipes/setup.rb - -## Ruby on Rails -say_wizard "You are using Ruby version #{RUBY_VERSION}." -say_wizard "You are using Rails version #{Rails::VERSION::STRING}." - -## Is sqlite3 in the Gemfile? -gemfile = File.read(destination_root() + '/Gemfile') -sqlite_detected = gemfile.include? 'sqlite3' - -## Web Server -prefs[:dev_webserver] = multiple_choice "Web server for development?", [["WEBrick (default)", "webrick"], - ["Thin", "thin"], ["Unicorn", "unicorn"], ["Puma", "puma"]] unless prefs.has_key? :dev_webserver -webserver = multiple_choice "Web server for production?", [["Same as development", "same"], - ["Thin", "thin"], ["Unicorn", "unicorn"], ["Puma", "puma"]] unless prefs.has_key? :prod_webserver -if webserver == 'same' - case prefs[:dev_webserver] - when 'thin' - prefs[:prod_webserver] = 'thin' - when 'unicorn' - prefs[:prod_webserver] = 'unicorn' - when 'puma' - prefs[:prod_webserver] = 'puma' - end -else - prefs[:prod_webserver] = webserver -end - -## Database Adapter -prefs[:database] = multiple_choice "Database used in development?", [["SQLite", "sqlite"], ["PostgreSQL", "postgresql"], - ["MySQL", "mysql"], ["MongoDB", "mongodb"]] unless prefs.has_key? :database -case prefs[:database] - when 'mongodb' - unless sqlite_detected - prefs[:orm] = multiple_choice "How will you connect to MongoDB?", [["Mongoid","mongoid"]] unless prefs.has_key? :orm - else - say_wizard "WARNING! SQLite gem detected in the Gemfile" - say_wizard "If you wish to use MongoDB you must skip Active Record." - say_wizard "When launching rails_apps_composer, choose 'skip Active Record'." - say_wizard "If using an application template, use the '-O' flag as in 'rails new foo -O'." - prefs[:fail] = multiple_choice "Abort or continue?", [["abort", "abort"], ["continue", "continue"]] - if prefer :fail, 'abort' - 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" - end - end -end - -## Template Engine -prefs[:templates] = multiple_choice "Template engine?", [["ERB", "erb"], ["Haml", "haml"], ["Slim", "slim"]] unless prefs.has_key? :templates - -## Testing Framework -if recipes.include? 'testing' - prefs[:unit_test] = multiple_choice "Unit testing?", [["Test::Unit", "test_unit"], ["RSpec", "rspec"]] unless prefs.has_key? :unit_test - prefs[:integration] = multiple_choice "Integration testing?", [["RSpec with Capybara", "capybara"], - ["Cucumber with Capybara", "cucumber"], ["Turnip with Capybara", "turnip"]] unless prefs.has_key? :integration - prefs[:fixtures] = multiple_choice "Fixture replacement?", [["None","none"], ["Factory Girl","factory_girl"], ["Machinist","machinist"]] unless prefs.has_key? :fixtures -end - -## Front-end Framework -if recipes.include? 'frontend' - prefs[:frontend] = multiple_choice "Front-end framework?", [["None", "none"], ["Twitter Bootstrap", "bootstrap"], - ["Zurb Foundation", "foundation"], ["Skeleton", "skeleton"], ["Just normalize CSS for consistent styling", "normalize"]] unless prefs.has_key? :frontend - if prefer :frontend, 'bootstrap' - prefs[:bootstrap] = multiple_choice "Twitter Bootstrap version?", [["Twitter Bootstrap (Less)", "less"], - ["Twitter Bootstrap (Sass)", "sass"]] unless prefs.has_key? :bootstrap - end -end - -## Email -if recipes.include? 'email' - prefs[:email] = multiple_choice "Add support for sending email?", [["None", "none"], ["Gmail","gmail"], ["SMTP","smtp"], - ["SendGrid","sendgrid"], ["Mandrill","mandrill"]] unless prefs.has_key? :email -else - prefs[:email] = 'none' -end - -## Authentication and Authorization -if recipes.include? 'auth' - prefs[:authentication] = multiple_choice "Authentication?", [["None", "none"], ["Devise", "devise"], ["OmniAuth", "omniauth"]] unless prefs.has_key? :authentication - case prefs[:authentication] - when 'devise' - if prefer :orm, 'mongoid' - prefs[:devise_modules] = multiple_choice "Devise modules?", [["Devise with default modules","default"]] unless prefs.has_key? :devise_modules - else - prefs[:devise_modules] = multiple_choice "Devise modules?", [["Devise with default modules","default"], ["Devise with Confirmable module","confirmable"], - ["Devise with Confirmable and Invitable modules","invitable"]] unless prefs.has_key? :devise_modules - end - when 'omniauth' - prefs[:omniauth_provider] = multiple_choice "OmniAuth provider?", [["Facebook", "facebook"], ["Twitter", "twitter"], ["GitHub", "github"], - ["LinkedIn", "linkedin"], ["Google-Oauth-2", "google-oauth2"], ["Tumblr", "tumblr"]] unless prefs.has_key? :omniauth_provider - end - prefs[:authorization] = multiple_choice "Authorization?", [["None", "none"], ["CanCan with Rolify", "cancan"]] unless prefs.has_key? :authorization -end - -## MVC -if (recipes.include? 'models') && (recipes.include? 'controllers') && (recipes.include? 'views') && (recipes.include? 'routes') - if prefer :authorization, 'cancan' - prefs[:starter_app] = multiple_choice "Install a starter app?", [["None", "none"], ["Home Page", "home_app"], - ["Home Page, User Accounts", "users_app"], ["Home Page, User Accounts, Admin Dashboard", "admin_app"]] unless prefs.has_key? :starter_app - elsif prefer :authentication, 'devise' - if prefer :orm, 'mongoid' - prefs[:starter_app] = multiple_choice "Install a starter app?", [["None", "none"], ["Home Page", "home_app"], - ["Home Page, User Accounts", "users_app"], ["Home Page, User Accounts, Subdomains", "subdomains_app"]] unless prefs.has_key? :starter_app - else - prefs[:starter_app] = multiple_choice "Install a starter app?", [["None", "none"], ["Home Page", "home_app"], - ["Home Page, User Accounts", "users_app"]] unless prefs.has_key? :starter_app - end - elsif prefer :authentication, 'omniauth' - prefs[:starter_app] = multiple_choice "Install a starter app?", [["None", "none"], ["Home Page", "home_app"], - ["Home Page, User Accounts", "users_app"]] unless prefs.has_key? :starter_app - else - prefs[:starter_app] = multiple_choice "Install a starter app?", [["None", "none"], ["Home Page", "home_app"]] unless prefs.has_key? :starter_app - end - if (recipes.include? 'prelaunch') && (prefer :authentication, 'devise') && (prefer :authorization, 'cancan') - prefs[:prelaunch_app] = multiple_choice "Install a prelaunch app?", [["None", "none"], ["Prelaunch Signup App", "signup_app"]] - if prefs[:prelaunch_app] == 'signup_app' - prefs[:devise_modules] = 'confirmable' - prefs[:bulkmail] = multiple_choice "Send news and announcements with a mail service?", [["None", "none"], ["MailChimp","mailchimp"]] - if prefer :git, true - prefs[:prelaunch_branch] = multiple_choice "Git branch for the prelaunch app?", [["wip (work-in-progress)", "wip"], ["master", "master"], ["prelaunch", "prelaunch"], ["staging", "staging"]] - if prefs[:prelaunch_branch] == 'master' - prefs[:main_branch] = multiple_choice "Git branch for the main app?", [["None (delete)", "none"], ["wip (work-in-progress)", "wip"], ["edge", "edge"]] - end - end - end - end -end - - -# >----------------------------[ readme_markdown ]----------------------------< - -@current_recipe = "readme_markdown" -@before_configs["readme_markdown"].call if @before_configs["readme_markdown"] -say_recipe 'readme_markdown' - - -@configs[@current_recipe] = config - -# Application template recipe for the rails_apps_composer. Change the recipe here: -# https://github.com/RailsApps/rails_apps_composer/blob/master/recipes/readme.rb - -after_everything do - say_wizard "recipe running after everything" - - # remove default READMEs - %w{ - README - README.rdoc - doc/README_FOR_APP - }.each { |file| remove_file file } - - # add placeholder READMEs and humans.txt file - copy_from_repo 'public/humans.txt' - copy_from_repo 'README' - copy_from_repo 'README.md' - gsub_file "README", /App_Name/, "#{app_name.humanize.titleize}" - gsub_file "README.md", /App_Name/, "#{app_name.humanize.titleize}" - - # Diagnostics - gsub_file "README.md", /recipes that are known/, "recipes that are NOT known" if diagnostics[:recipes] == 'fail' - gsub_file "README.md", /preferences that are known/, "preferences that are NOT known" if diagnostics[:prefs] == 'fail' - gsub_file "README.md", /RECIPES/, recipes.sort.inspect - gsub_file "README.md", /PREFERENCES/, prefs.inspect - gsub_file "README", /RECIPES/, recipes.sort.inspect - gsub_file "README", /PREFERENCES/, prefs.inspect - - # Ruby on Rails - gsub_file "README.md", /\* Ruby/, "* Ruby version #{RUBY_VERSION}" - gsub_file "README.md", /\* Rails/, "* Rails version #{Rails::VERSION::STRING}" - - # Database - gsub_file "README.md", /SQLite/, "PostgreSQL" if prefer :database, 'postgresql' - gsub_file "README.md", /SQLite/, "MySQL" if prefer :database, 'mysql' - gsub_file "README.md", /SQLite/, "MongoDB" if prefer :database, 'mongodb' - gsub_file "README.md", /ActiveRecord/, "the Mongoid ORM" if prefer :orm, 'mongoid' - - # Template Engine - gsub_file "README.md", /ERB/, "Haml" if prefer :templates, 'haml' - gsub_file "README.md", /ERB/, "Slim" if prefer :templates, 'slim' - - # Testing Framework - gsub_file "README.md", /Test::Unit/, "RSpec" if prefer :unit_test, 'rspec' - gsub_file "README.md", /RSpec/, "RSpec and Cucumber" if prefer :integration, 'cucumber' - gsub_file "README.md", /RSpec/, "RSpec and Factory Girl" if prefer :fixtures, 'factory_girl' - gsub_file "README.md", /RSpec/, "RSpec and Machinist" if prefer :fixtures, 'machinist' - - # Front-end Framework - gsub_file "README.md", /Front-end Framework: None/, "Front-end Framework: Twitter Bootstrap (Sass)" if prefer :bootstrap, 'sass' - gsub_file "README.md", /Front-end Framework: None/, "Front-end Framework: Twitter Bootstrap (Less)" if prefer :bootstrap, 'less' - gsub_file "README.md", /Front-end Framework: None/, "Front-end Framework: Zurb Foundation" if prefer :frontend, 'foundation' - gsub_file "README.md", /Front-end Framework: None/, "Front-end Framework: Skeleton" if prefer :frontend, 'skeleton' - gsub_file "README.md", /Front-end Framework: None/, "Front-end Framework: Normalized CSS" if prefer :frontend, 'normalize' - - # Form Builder - gsub_file "README.md", /Form Builder: None/, "Form Builder: SimpleForm" if prefer :form_builder, 'simple_form' - - # Email - unless prefer :email, 'none' - gsub_file "README.md", /Gmail/, "SMTP" if prefer :email, 'smtp' - gsub_file "README.md", /Gmail/, "SendGrid" if prefer :email, 'sendgrid' - gsub_file "README.md", /Gmail/, "Mandrill" if prefer :email, 'mandrill' - else - gsub_file "README.md", /h2. Email/, "" - gsub_file "README.md", /The application is configured to send email using a Gmail account./, "" - end - - # Authentication and Authorization - gsub_file "README.md", /Authentication: None/, "Authentication: Devise" if prefer :authentication, 'devise' - gsub_file "README.md", /Authentication: None/, "Authentication: OmniAuth" if prefer :authentication, 'omniauth' - gsub_file "README.md", /Authorization: None/, "Authorization: CanCan" if prefer :authorization, 'cancan' - - git :add => '.' if prefer :git, true - git :commit => "-aqm 'rails_apps_composer: add README files'" if prefer :git, true - -end # after_everything - - -# >---------------------------------[ gems ]----------------------------------< - -@current_recipe = "gems" -@before_configs["gems"].call if @before_configs["gems"] -say_recipe 'gems' - - -@configs[@current_recipe] = config - -# Application template recipe for the rails_apps_composer. Change the recipe here: -# https://github.com/RailsApps/rails_apps_composer/blob/master/recipes/gems.rb - -### GEMFILE ### - -## Ruby on Rails -insert_into_file 'Gemfile', "ruby '1.9.3'\n", :before => "gem 'rails', '3.2.6'" if prefer :deploy, 'heroku' - -## Web Server -gem 'thin', '>= 1.4.1', :group => [:development, :test] if prefer :dev_webserver, 'thin' -gem 'unicorn', '>= 4.3.1', :group => [:development, :test] if prefer :dev_webserver, 'unicorn' -gem 'puma', '>= 1.5.0', :group => [:development, :test] if prefer :dev_webserver, 'puma' -gem 'thin', '>= 1.4.1', :group => :production if prefer :prod_webserver, 'thin' -gem 'unicorn', '>= 4.3.1', :group => :production if prefer :prod_webserver, 'unicorn' -gem 'puma', '>= 1.6.1', :group => :production if prefer :prod_webserver, 'puma' - -## Database Adapter -gsub_file 'Gemfile', /gem 'sqlite3'\n/, '' unless prefer :database, 'sqlite' -gem 'mongoid', '>= 3.0.3' if prefer :orm, 'mongoid' -gem 'pg', '>= 0.14.0' if prefer :database, 'postgresql' -gem 'mysql2', '>= 0.3.11' if prefer :database, 'mysql' -copy_from_repo 'config/database-postgresql.yml', :prefs => 'postgresql' -copy_from_repo 'config/database-mysql.yml', :prefs => 'mysql' - -## Template Engine -if prefer :templates, 'haml' - gem 'haml', '>= 3.1.7' - gem 'haml-rails', '>= 0.3.4', :group => :development - # hpricot and ruby_parser are needed for conversion of HTML to Haml - gem 'hpricot', '>= 0.8.6', :group => :development - gem 'ruby_parser', '>= 2.3.1', :group => :development -end -if prefer :templates, 'slim' - gem 'slim', '>= 1.2.2' - gem 'haml2slim', '>= 0.4.6', :group => :development - # Haml is needed for conversion of HTML to Slim - gem 'haml', '>= 3.1.6', :group => :development - gem 'haml-rails', '>= 0.3.4', :group => :development - gem 'hpricot', '>= 0.8.6', :group => :development - gem 'ruby_parser', '>= 2.3.1', :group => :development -end - -## Testing Framework -if prefer :unit_test, 'rspec' - gem 'rspec-rails', '>= 2.11.0', :group => [:development, :test] - gem 'capybara', '>= 1.1.2', :group => :test - if prefer :orm, 'mongoid' - # use the database_cleaner gem to reset the test database - gem 'database_cleaner', '>= 0.8.0', :group => :test - # include RSpec matchers from the mongoid-rspec gem - gem 'mongoid-rspec', '>= 1.4.6', :group => :test - end - gem 'email_spec', '>= 1.2.1', :group => :test unless prefer :email, 'none' -end -if prefer :integration, 'cucumber' - gem 'cucumber-rails', '>= 1.3.0', :group => :test, :require => false - gem 'database_cleaner', '>= 0.8.0', :group => :test unless prefer :orm, 'mongoid' - gem 'launchy', '>= 2.1.2', :group => :test -end -gem 'turnip', '>= 1.0.0', :group => :test if prefer :integration, 'turnip' -gem 'factory_girl_rails', '>= 4.0.0', :group => [:development, :test] if prefer :fixtures, 'factory_girl' -gem 'machinist', '>= 2.0', :group => :test if prefer :fixtures, 'machinist' - -## Front-end Framework -gem 'bootstrap-sass', '>= 2.0.4.0' if prefer :bootstrap, 'sass' -gem 'zurb-foundation', '>= 3.0.8' if prefer :frontend, 'foundation' -if prefer :bootstrap, 'less' - gem 'twitter-bootstrap-rails', '>= 2.1.1', :group => :assets - # install gem 'therubyracer' to use Less - gem 'therubyracer', '>= 0.10.2', :group => :assets, :platform => :ruby -end - -## Email -gem 'sendgrid', '>= 1.0.1' if prefer :email, 'sendgrid' -gem 'hominid', '>= 3.0.5' if prefer :email, 'mandrill' - -## Authentication (Devise) -gem 'devise', '>= 2.1.2' if prefer :authentication, 'devise' -gem 'devise_invitable', '>= 1.0.3' if prefer :devise_modules, 'invitable' - -## Authentication (OmniAuth) -gem 'omniauth', '>= 1.1.0' if prefer :authentication, 'omniauth' -gem 'omniauth-twitter' if prefer :omniauth_provider, 'twitter' -gem 'omniauth-facebook' if prefer :omniauth_provider, 'facebook' -gem 'omniauth-github' if prefer :omniauth_provider, 'github' -gem 'omniauth-linkedin' if prefer :omniauth_provider, 'linkedin' -gem 'omniauth-google-oauth2' if prefer :omniauth_provider, 'google-oauth2' -gem 'omniauth-tumblr' if prefer :omniauth_provider, 'tumblr' - -## Authorization -if prefer :authorization, 'cancan' - gem 'cancan', '>= 1.6.8' - gem 'rolify', '>= 3.2.0' -end - -## Signup App -if prefer :prelaunch_app, 'signup_app' - gem 'google_visualr', '>= 2.1.2' - gem 'jquery-datatables-rails', '>= 1.10.0' -end - -## Gems from a defaults file or added interactively -gems.each do |g| - gem g -end - -## Git -git :add => '.' if prefer :git, true -git :commit => "-aqm 'rails_apps_composer: Gemfile'" if prefer :git, true - -### GENERATORS ### -after_bundler do - ## Database - generate 'mongoid:config' if prefer :orm, 'mongoid' - remove_file 'config/database.yml' if prefer :orm, 'mongoid' - ## Git - git :add => '.' if prefer :git, true - git :commit => "-aqm 'rails_apps_composer: generators'" if prefer :git, true -end # after_bundler - - -# >--------------------------------[ testing ]--------------------------------< - -@current_recipe = "testing" -@before_configs["testing"].call if @before_configs["testing"] -say_recipe 'testing' - - -@configs[@current_recipe] = config - -# Application template recipe for the rails_apps_composer. Change the recipe here: -# https://github.com/RailsApps/rails_apps_composer/blob/master/recipes/testing.rb - -after_bundler do - say_wizard "recipe running after 'bundle install'" - ### RSPEC ### - if prefer :unit_test, 'rspec' - say_wizard "recipe installing RSpec" - generate 'rspec:install' - unless prefer :email, 'none' - generate 'email_spec:steps' - inject_into_file 'spec/spec_helper.rb', "require 'email_spec'\n", :after => "require 'rspec/rails'\n" - inject_into_file 'spec/spec_helper.rb', :after => "RSpec.configure do |config|\n" do <<-RUBY - config.include(EmailSpec::Helpers) - config.include(EmailSpec::Matchers) -RUBY - end - end - run 'rm -rf test/' # Removing test folder (not needed for RSpec) - inject_into_file 'config/application.rb', :after => "Rails::Application\n" do <<-RUBY - - # don't generate RSpec tests for views and helpers - config.generators do |g| - g.view_specs false - g.helper_specs false - #{"g.fixture_replacement :machinist" if prefer :fixtures, 'machinist'} - end - -RUBY - end - ## RSPEC AND MONGOID - if prefer :orm, 'mongoid' - # remove ActiveRecord artifacts - gsub_file 'spec/spec_helper.rb', /config.fixture_path/, '# config.fixture_path' - gsub_file 'spec/spec_helper.rb', /config.use_transactional_fixtures/, '# config.use_transactional_fixtures' - # reset your application database to a pristine state during testing - inject_into_file 'spec/spec_helper.rb', :before => "\nend" do - <<-RUBY - \n - require 'database_cleaner' - config.before(:suite) do - DatabaseCleaner.strategy = :truncation - DatabaseCleaner.orm = "mongoid" - end - - config.before(:each) do - DatabaseCleaner.clean - end -RUBY - end - # remove either possible occurrence of "require rails/test_unit/railtie" - gsub_file 'config/application.rb', /require 'rails\/test_unit\/railtie'/, '# require "rails/test_unit/railtie"' - gsub_file 'config/application.rb', /require "rails\/test_unit\/railtie"/, '# require "rails/test_unit/railtie"' - # configure RSpec to use matchers from the mongoid-rspec gem - create_file 'spec/support/mongoid.rb' do - <<-RUBY -RSpec.configure do |config| - config.include Mongoid::Matchers -end -RUBY - end - end - ## RSPEC AND DEVISE - if prefer :authentication, 'devise' - # add Devise test helpers - create_file 'spec/support/devise.rb' do - <<-RUBY -RSpec.configure do |config| - config.include Devise::TestHelpers, :type => :controller -end -RUBY - end - end - end - ### CUCUMBER ### - if prefer :integration, 'cucumber' - say_wizard "recipe installing Cucumber" - generate "cucumber:install --capybara#{' --rspec' if prefer :unit_test, 'rspec'}#{' -D' if prefer :orm, 'mongoid'}" - # make it easy to run Cucumber for single features without adding "--require features" to the command line - gsub_file 'config/cucumber.yml', /std_opts = "/, 'std_opts = "-r features/support/ -r features/step_definitions ' - unless prefer :email, 'none' - create_file 'features/support/email_spec.rb' do <<-RUBY -require 'email_spec/cucumber' -RUBY - end - end - ## CUCUMBER AND MONGOID - if prefer :orm, 'mongoid' - gsub_file 'features/support/env.rb', /transaction/, "truncation" - inject_into_file 'features/support/env.rb', :after => 'begin' do - "\n DatabaseCleaner.orm = 'mongoid'" - end - end - end - ## TURNIP - if prefer :integration, 'turnip' - append_to_file '.rspec', '-r turnip/rspec' - inject_into_file 'spec/spec_helper.rb', "require 'turnip/capybara'\n", :after => "require 'rspec/rails'\n" - create_file 'spec/acceptance/steps/.gitkeep' - end - ## FIXTURE REPLACEMENTS - if prefer :fixtures, 'machinist' - say_wizard "generating blueprints file for 'machinist'" - generate 'machinist:install' - end - ### GIT ### - git :add => '.' if prefer :git, true - git :commit => "-aqm 'rails_apps_composer: testing framework'" if prefer :git, true -end # after_bundler - -after_everything do - say_wizard "recipe running after everything" - ### RSPEC ### - if prefer :unit_test, 'rspec' - if (prefer :authentication, 'devise') && (prefer :starter_app, 'users_app') - say_wizard "copying RSpec files from the rails3-devise-rspec-cucumber examples" - repo = 'https://raw.github.com/RailsApps/rails3-devise-rspec-cucumber/master/' - copy_from_repo 'spec/factories/users.rb', :repo => repo - gsub_file 'spec/factories/users.rb', /# confirmed_at/, "confirmed_at" if (prefer :devise_modules, 'confirmable') || (prefer :devise_modules, 'invitable') - copy_from_repo 'spec/controllers/home_controller_spec.rb', :repo => repo - copy_from_repo 'spec/controllers/users_controller_spec.rb', :repo => repo - copy_from_repo 'spec/models/user_spec.rb', :repo => repo - remove_file 'spec/views/home/index.html.erb_spec.rb' - remove_file 'spec/views/home/index.html.haml_spec.rb' - remove_file 'spec/views/users/show.html.erb_spec.rb' - remove_file 'spec/views/users/show.html.haml_spec.rb' - remove_file 'spec/helpers/home_helper_spec.rb' - remove_file 'spec/helpers/users_helper_spec.rb' - end - if (prefer :authentication, 'devise') && (prefer :starter_app, 'admin_app') - say_wizard "copying RSpec files from the rails3-bootstrap-devise-cancan examples" - repo = 'https://raw.github.com/RailsApps/rails3-bootstrap-devise-cancan/master/' - copy_from_repo 'spec/factories/users.rb', :repo => repo - gsub_file 'spec/factories/users.rb', /# confirmed_at/, "confirmed_at" if (prefer :devise_modules, 'confirmable') || (prefer :devise_modules, 'invitable') - copy_from_repo 'spec/controllers/home_controller_spec.rb', :repo => repo - copy_from_repo 'spec/controllers/users_controller_spec.rb', :repo => repo - copy_from_repo 'spec/models/user_spec.rb', :repo => repo - remove_file 'spec/views/home/index.html.erb_spec.rb' - remove_file 'spec/views/home/index.html.haml_spec.rb' - remove_file 'spec/views/users/show.html.erb_spec.rb' - remove_file 'spec/views/users/show.html.haml_spec.rb' - remove_file 'spec/helpers/home_helper_spec.rb' - remove_file 'spec/helpers/users_helper_spec.rb' - end - ## RSPEC AND OMNIAUTH - if (prefer :authentication, 'omniauth') && (prefer :starter_app, 'users_app') - say_wizard "copying RSpec files from the rails3-mongoid-omniauth examples" - repo = 'https://raw.github.com/RailsApps/rails3-mongoid-omniauth/master/' - copy_from_repo 'spec/spec_helper.rb', :repo => repo - copy_from_repo 'spec/factories/users.rb', :repo => repo - copy_from_repo 'spec/controllers/sessions_controller_spec.rb', :repo => repo - copy_from_repo 'spec/controllers/home_controller_spec.rb', :repo => repo - copy_from_repo 'spec/controllers/users_controller_spec.rb', :repo => repo - copy_from_repo 'spec/models/user_spec.rb', :repo => repo - end - ## GIT - git :add => '.' if prefer :git, true - git :commit => "-aqm 'rails_apps_composer: rspec files'" if prefer :git, true - end - ### CUCUMBER ### - if prefer :integration, 'cucumber' - ## CUCUMBER AND DEVISE - if (prefer :authentication, 'devise') && (prefer :starter_app, 'users_app') - say_wizard "copying Cucumber scenarios from the rails3-devise-rspec-cucumber examples" - repo = 'https://raw.github.com/RailsApps/rails3-devise-rspec-cucumber/master/' - copy_from_repo 'spec/controllers/home_controller_spec.rb', :repo => repo - copy_from_repo 'features/users/sign_in.feature', :repo => repo - copy_from_repo 'features/users/sign_out.feature', :repo => repo - copy_from_repo 'features/users/sign_up.feature', :repo => repo - copy_from_repo 'features/users/user_edit.feature', :repo => repo - copy_from_repo 'features/users/user_show.feature', :repo => repo - copy_from_repo 'features/step_definitions/user_steps.rb', :repo => repo - copy_from_repo 'features/support/paths.rb', :repo => repo - if (prefer :devise_modules, 'confirmable') || (prefer :devise_modules, 'invitable') - 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." - inject_into_file 'features/users/sign_in.feature', :before => ' Scenario: User signs in successfully' do -<<-RUBY - Scenario: User has not confirmed account - Given I exist as an unconfirmed user - And I am not logged in - When I sign in with valid credentials - Then I see an unconfirmed account message - And I should be signed out -RUBY - end - end - end - if (prefer :authentication, 'devise') && (prefer :starter_app, 'admin_app') - say_wizard "copying Cucumber scenarios from the rails3-bootstrap-devise-cancan examples" - repo = 'https://raw.github.com/RailsApps/rails3-bootstrap-devise-cancan/master/' - copy_from_repo 'spec/controllers/home_controller_spec.rb', :repo => repo - copy_from_repo 'features/users/sign_in.feature', :repo => repo - copy_from_repo 'features/users/sign_out.feature', :repo => repo - copy_from_repo 'features/users/sign_up.feature', :repo => repo - copy_from_repo 'features/users/user_edit.feature', :repo => repo - copy_from_repo 'features/users/user_show.feature', :repo => repo - copy_from_repo 'features/step_definitions/user_steps.rb', :repo => repo - copy_from_repo 'features/support/paths.rb', :repo => repo - if (prefer :devise_modules, 'confirmable') || (prefer :devise_modules, 'invitable') - 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." - inject_into_file 'features/users/sign_in.feature', :before => ' Scenario: User signs in successfully' do -<<-RUBY - Scenario: User has not confirmed account - Given I exist as an unconfirmed user - And I am not logged in - When I sign in with valid credentials - Then I see an unconfirmed account message - And I should be signed out -RUBY - end - end - end - ## GIT - git :add => '.' if prefer :git, true - git :commit => "-aqm 'rails_apps_composer: cucumber files'" if prefer :git, true - end -end # after_everything - - -# >---------------------------------[ auth ]----------------------------------< - -@current_recipe = "auth" -@before_configs["auth"].call if @before_configs["auth"] -say_recipe 'auth' - - -@configs[@current_recipe] = config - -# Application template recipe for the rails_apps_composer. Change the recipe here: -# https://github.com/RailsApps/rails_apps_composer/blob/master/recipes/auth.rb - -after_bundler do - say_wizard "recipe running after 'bundle install'" - ### 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 prefer :devise_modules, 'invitable' - generate 'devise user' - ## DEVISE AND 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 (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 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 prefer :devise_modules, 'invitable' - if prefer :orm, 'mongoid' - gsub_file 'app/models/user.rb', /\bend\s*\Z/ do +rakefile "base.rake" do <<-RUBY - #invitable - field :invitation_token, :type => String - field :invitation_sent_at, :type => Time - field :invitation_accepted_at, :type => Time - field :invitation_limit, :type => Integer - field :invited_by_id, :type => String - field :invited_by_type, :type => String +task :server do + sh "rails server puma" end -RUBY - end - end - end - end - ### OMNIAUTH ### - 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 :#{prefs[:omniauth_provider]}, ENV['OMNIAUTH_PROVIDER_KEY'], ENV['OMNIAUTH_PROVIDER_SECRET'] + RUBY end -RUBY - end - end - ### CANCAN ### - if prefer :authorization, 'cancan' - generate 'cancan:ability' - if prefer :starter_app, 'admin_app' - # 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) - if user.has_role? :admin - can :manage, :all - end -RUBY - end - end - end - ### GIT ### - git :add => '.' if prefer :git, true - git :commit => "-aqm 'rails_apps_composer: authentication and authorization'" if prefer :git, true -end # after_bundler - -# >--------------------------------[ models ]---------------------------------< - -@current_recipe = "models" -@before_configs["models"].call if @before_configs["models"] -say_recipe 'models' - - -@configs[@current_recipe] = config - -# Application template recipe for the rails_apps_composer. Change the recipe here: -# https://github.com/RailsApps/rails_apps_composer/blob/master/recipes/models.rb - -after_bundler do - say_wizard "recipe running after 'bundle install'" - ### DEVISE ### - if prefer :authentication, 'devise' - if prefer :orm, 'mongoid' - copy_from_repo 'app/models/user.rb', :repo => 'https://raw.github.com/RailsApps/rails3-mongoid-devise/master/' if prefer :orm, 'mongoid' - else - generate 'migration AddNameToUsers name:string' - if (prefer :devise_modules, 'confirmable') || (prefer :devise_modules, 'invitable') - generate 'migration AddConfirmableToUsers confirmation_token:string confirmed_at:datetime confirmation_sent_at:datetime unconfirmed_email:string' - end - copy_from_repo 'app/models/user.rb', :repo => 'https://raw.github.com/RailsApps/rails3-devise-rspec-cucumber/master/' - end - end - ### OMNIAUTH ### - if prefer :authentication, 'omniauth' - if prefer :orm, 'mongoid' - copy_from_repo 'app/models/user.rb', :repo => 'https://raw.github.com/RailsApps/rails3-mongoid-omniauth/master/' - else - generate 'model User name:string email:string provider:string uid:string' - run 'bundle exec rake db:migrate' - copy_from_repo 'app/models/user.rb', :repo => 'https://raw.github.com/RailsApps/rails3-mongoid-omniauth/master/' - gsub_file 'app/models/user.rb', /class User/, 'class User < ActiveRecord::Base' - gsub_file 'app/models/user.rb', /^\s*include Mongoid::Document\n/, '' - gsub_file 'app/models/user.rb', /^\s*field.*\n/, '' - gsub_file 'app/models/user.rb', /^\s*# run 'rake db:mongoid:create_indexes' to create indexes\n/, '' - gsub_file 'app/models/user.rb', /^\s*index\(\{ email: 1 \}, \{ unique: true, background: true \}\)\n/, '' - end - end - ### SUBDOMAINS ### - copy_from_repo 'app/models/user.rb', :repo => 'https://raw.github.com/RailsApps/rails3-subdomains/master/' if prefer :starter_app, 'subdomains' - ### AUTHORIZATION (insert 'rolify' after User model is created) ### - if prefer :authorization, 'cancan' - unless prefer :orm, 'mongoid' - generate 'rolify:role Role User' - else - generate 'rolify:role Role User mongoid' - # correct the generation of rolify 3.1 with mongoid - # the call to `rolify` should be *after* the inclusion of mongoid - # (see https://github.com/EppO/rolify/issues/61) - # This isn't needed for rolify>=3.2.0.beta4, but should cause no harm - gsub_file 'app/models/user.rb', - /^\s*(rolify.*?)$\s*(include Mongoid::Document.*?)$/, - " \\2\n extend Rolify\n \\1\n" - end - end - ### GIT ### - git :add => '.' if prefer :git, true - git :commit => "-aqm 'rails_apps_composer: models'" if prefer :git, true -end # after_bundler - - -# >------------------------------[ controllers ]------------------------------< - -@current_recipe = "controllers" -@before_configs["controllers"].call if @before_configs["controllers"] -say_recipe 'controllers' - - -@configs[@current_recipe] = config - -# Application template recipe for the rails_apps_composer. Change the recipe here: -# https://github.com/RailsApps/rails_apps_composer/blob/master/recipes/controllers.rb - -after_bundler do - say_wizard "recipe running after 'bundle install'" - ### APPLICATION_CONTROLLER ### - if prefer :authentication, 'omniauth' - copy_from_repo 'app/controllers/application_controller.rb', :repo => 'https://raw.github.com/RailsApps/rails3-mongoid-omniauth/master/' - end - 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 - end -RUBY - end - end - ### HOME_CONTROLLER ### - if ['home_app','users_app','admin_app','subdomains_app'].include? prefs[:starter_app] - generate(:controller, "home index") - end - 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 ['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 prefer :authentication, 'omniauth' - copy_from_repo 'app/controllers/users_controller.rb', :repo => 'https://raw.github.com/RailsApps/rails3-mongoid-omniauth/master/' - end - 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 prefer :starter_app, 'subdomains' - ### SESSIONS_CONTROLLER ### - if prefer :authentication, 'omniauth' - filename = 'app/controllers/sessions_controller.rb' - copy_from_repo filename, :repo => 'https://raw.github.com/RailsApps/rails3-mongoid-omniauth/master/' - 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 prefer :starter_app, 'subdomains' - ### GIT ### - git :add => '.' if prefer :git, true - git :commit => "-aqm 'rails_apps_composer: controllers'" if prefer :git, true -end # after_bundler - - -# >---------------------------------[ views ]---------------------------------< - -@current_recipe = "views" -@before_configs["views"].call if @before_configs["views"] -say_recipe 'views' - - -@configs[@current_recipe] = config - -# Application template recipe for the rails_apps_composer. Change the recipe here: -# https://github.com/RailsApps/rails_apps_composer/blob/master/recipes/views.rb - -after_bundler do - say_wizard "recipe running after 'bundle install'" - ### DEVISE ### - copy_from_repo 'app/views/devise/shared/_links.html.erb' if prefer :authentication, 'devise' - copy_from_repo 'app/views/devise/registrations/edit.html.erb' if prefer :authentication, 'devise' - copy_from_repo 'app/views/devise/registrations/new.html.erb' if prefer :authentication, 'devise' - ### HOME ### - copy_from_repo 'app/views/home/index.html.erb' if prefer :starter_app, 'users_app' - copy_from_repo 'app/views/home/index.html.erb' if prefer :starter_app, 'admin_app' - copy_from_repo 'app/views/home/index-subdomains_app.html.erb', :prefs => 'subdomains_app' - ### USERS ### - if ['users_app','admin_app','subdomains_app'].include? prefs[:starter_app] - ## INDEX - copy_from_repo 'app/views/users/index.html.erb' - ## SHOW - copy_from_repo 'app/views/users/show.html.erb' - copy_from_repo 'app/views/users/show-subdomains_app.html.erb', :prefs => 'subdomains_app' - ## EDIT - copy_from_repo 'app/views/users/edit-omniauth.html.erb', :prefs => 'omniauth' - end - ### PROFILES ### - copy_from_repo 'app/views/profiles/show-subdomains_app.html.erb', :prefs => 'subdomains_app' - ### GIT ### - git :add => '.' if prefer :git, true - git :commit => "-aqm 'rails_apps_composer: views'" if prefer :git, true -end # after_bundler - - -# >------------------------------[ haml_views ]-------------------------------< - -@current_recipe = "haml_views" -@before_configs["haml_views"].call if @before_configs["haml_views"] -say_recipe 'haml_views' - - -@configs[@current_recipe] = config - -after_bundler do - say_wizard "recipe running after 'bundle install'" - - # Convert all views to Haml - run "for i in `find app/views -name '*.erb'` ; do html2haml -e $i ${i%erb}haml ; rm $i ; done" - - ### GIT ### - git :add => '.' if prefer :git, true - git :commit => "-aqm 'rails_apps_composer: Haml starter views.'" if prefer :git, true -end # after_bundler - - -# >--------------------------------[ routes ]---------------------------------< - -@current_recipe = "routes" -@before_configs["routes"].call if @before_configs["routes"] -say_recipe 'routes' - - -@configs[@current_recipe] = config - -# Application template recipe for the rails_apps_composer. Change the recipe here: -# https://github.com/RailsApps/rails_apps_composer/blob/master/recipes/routes.rb - -after_bundler do - say_wizard "recipe running after 'bundle install'" - ### HOME ### - if prefer :starter_app, 'home_app' - remove_file 'public/index.html' - gsub_file 'config/routes.rb', /get \"home\/index\"/, 'root :to => "home#index"' - end - ### USER_ACCOUNTS ### - if ['users_app','admin_app'].include? prefs[:starter_app] - ## DEVISE - copy_from_repo 'config/routes.rb', :repo => 'https://raw.github.com/RailsApps/rails3-devise-rspec-cucumber/master/' if prefer :authentication, 'devise' - ## OMNIAUTH - copy_from_repo 'config/routes.rb', :repo => 'https://raw.github.com/RailsApps/rails3-mongoid-omniauth/master/' if prefer :authentication, 'omniauth' - end - ### SUBDOMAINS ### - copy_from_repo 'lib/subdomain.rb', :repo => 'https://raw.github.com/RailsApps/rails3-subdomains/master/' if prefer :starter_app, 'subdomains' - copy_from_repo 'config/routes.rb', :repo => 'https://raw.github.com/RailsApps/rails3-subdomains/master/' if prefer :starter_app, 'subdomains' - ### CORRECT APPLICATION NAME ### - gsub_file 'config/routes.rb', /^.*.routes.draw do/, "#{app_const}.routes.draw do" - ### GIT ### - git :add => '.' if prefer :git, true - git :commit => "-aqm 'rails_apps_composer: routes'" if prefer :git, true -end # after_bundler - - -# >-------------------------------[ frontend ]--------------------------------< - -@current_recipe = "frontend" -@before_configs["frontend"].call if @before_configs["frontend"] -say_recipe 'frontend' - - -@configs[@current_recipe] = config - -# Application template recipe for the rails_apps_composer. Change the recipe here: -# https://github.com/RailsApps/rails_apps_composer/blob/master/recipes/frontend.rb - -after_bundler do - 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', :prefs => 'bootstrap' - copy_from_repo 'app/views/layouts/_messages.html.erb' - 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', :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 = Dir['app/views/layouts/application.html.*'].first - navigation_partial_file = Dir['app/views/layouts/_navigation.html.*'].first - 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', :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 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 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 prefer :frontend, 'skeleton' - copy_from 'https://raw.github.com/necolas/normalize.css/master/normalize.css', 'app/assets/stylesheets/normalize.css' - copy_from 'https://raw.github.com/dhgamache/Skeleton/master/stylesheets/base.css', 'app/assets/stylesheets/base.css' - copy_from 'https://raw.github.com/dhgamache/Skeleton/master/stylesheets/layout.css', 'app/assets/stylesheets/layout.css' - copy_from 'https://raw.github.com/dhgamache/Skeleton/master/stylesheets/skeleton.css', 'app/assets/stylesheets/skeleton.css' - elsif prefer :frontend, 'normalize' - copy_from 'https://raw.github.com/necolas/normalize.css/master/normalize.css', 'app/assets/stylesheets/normalize.css' - end - ### GIT ### - git :add => '.' if prefer :git, true - git :commit => "-aqm 'rails_apps_composer: front-end framework'" if prefer :git, true -end # after_bundler - - -# >---------------------------------[ html5 ]---------------------------------< - -@current_recipe = "html5" -@before_configs["html5"].call if @before_configs["html5"] -say_recipe 'html5' - - -@configs[@current_recipe] = config - -# Application template recipe for the rails_apps_composer. Check for a newer version here: -# https://github.com/RailsApps/rails_apps_composer/blob/master/recipes/html5.rb - -after_bundler do - say_wizard "HTML5 recipe running 'after bundler'" - # add a humans.txt file - get 'https://raw.github.com/RailsApps/rails3-application-templates/master/files/humans.txt', 'public/humans.txt' - # install a front-end framework for HTML5 and CSS3 - remove_file 'app/assets/stylesheets/application.css' - remove_file 'app/views/layouts/application.html.erb' - remove_file 'app/views/layouts/application.html.haml' - unless recipes.include? 'bootstrap' - if recipes.include? 'haml' - # Haml version of a simple application layout - get 'https://raw.github.com/RailsApps/rails3-application-templates/master/files/simple/views/layouts/application.html.haml', 'app/views/layouts/application.html.haml' - get 'https://raw.github.com/RailsApps/rails3-application-templates/master/files/simple/views/layouts/_messages.html.haml', 'app/views/layouts/_messages.html.haml' - else - # ERB version of a simple application layout - get 'https://raw.github.com/RailsApps/rails3-application-templates/master/files/simple/views/layouts/application.html.erb', 'app/views/layouts/application.html.erb' - get 'https://raw.github.com/RailsApps/rails3-application-templates/master/files/simple/views/layouts/_messages.html.erb', 'app/views/layouts/_messages.html.erb' - end - # simple css styles - get 'https://raw.github.com/RailsApps/rails3-application-templates/master/files/simple/assets/stylesheets/application.css.scss', 'app/assets/stylesheets/application.css.scss' - else # for Twitter Bootstrap - if recipes.include? 'haml' - # Haml version of a complex application layout using Twitter Bootstrap - get 'https://raw.github.com/RailsApps/rails3-application-templates/master/files/twitter-bootstrap/views/layouts/application.html.haml', 'app/views/layouts/application.html.haml' - get 'https://raw.github.com/RailsApps/rails3-application-templates/master/files/twitter-bootstrap/views/layouts/_messages.html.haml', 'app/views/layouts/_messages.html.haml' - else - # ERB version of a complex application layout using Twitter Bootstrap - get 'https://raw.github.com/RailsApps/rails3-application-templates/master/files/twitter-bootstrap/views/layouts/application.html.erb', 'app/views/layouts/application.html.erb' - get 'https://raw.github.com/RailsApps/rails3-application-templates/master/files/twitter-bootstrap/views/layouts/_messages.html.erb', 'app/views/layouts/_messages.html.erb' - end - # complex css styles using Twitter Bootstrap - get 'https://raw.github.com/RailsApps/rails3-application-templates/master/files/twitter-bootstrap/assets/stylesheets/application.css.scss', 'app/assets/stylesheets/application.css.scss' - end - # get an appropriate navigation partial - if recipes.include? 'haml' - if recipes.include? 'devise' - if recipes.include? 'authorization' - get 'https://raw.github.com/RailsApps/rails3-application-templates/master/files/navigation/devise/authorization/_navigation.html.haml', 'app/views/layouts/_navigation.html.haml' - else - get 'https://raw.github.com/RailsApps/rails3-application-templates/master/files/navigation/devise/_navigation.html.haml', 'app/views/layouts/_navigation.html.haml' - end - elsif recipes.include? 'omniauth' - get 'https://raw.github.com/RailsApps/rails3-application-templates/master/files/navigation/omniauth/_navigation.html.haml', 'app/views/layouts/_navigation.html.haml' - elsif recipes.include? 'subdomains' - get 'https://raw.github.com/RailsApps/rails3-application-templates/master/files/navigation/subdomains/_navigation.html.haml', 'app/views/layouts/_navigation.html.haml' - else - get 'https://raw.github.com/RailsApps/rails3-application-templates/master/files/navigation/none/_navigation.html.haml', 'app/views/layouts/_navigation.html.haml' - end - else - if recipes.include? 'devise' - if recipes.include? 'authorization' - get 'https://raw.github.com/RailsApps/rails3-application-templates/master/files/navigation/devise/authorization/_navigation.html.erb', 'app/views/layouts/_navigation.html.erb' - else - get 'https://raw.github.com/RailsApps/rails3-application-templates/master/files/navigation/devise/_navigation.html.erb', 'app/views/layouts/_navigation.html.erb' - end - elsif recipes.include? 'omniauth' - get 'https://raw.github.com/RailsApps/rails3-application-templates/master/files/navigation/omniauth/_navigation.html.erb', 'app/views/layouts/_navigation.html.erb' - elsif recipes.include? 'subdomains' - get 'https://raw.github.com/RailsApps/rails3-application-templates/master/files/navigation/subdomains/_navigation.html.erb', 'app/views/layouts/_navigation.html.erb' - else - get 'https://raw.github.com/RailsApps/rails3-application-templates/master/files/navigation/none/_navigation.html.erb', 'app/views/layouts/_navigation.html.erb' - end - end - if recipes.include? 'haml' - gsub_file 'app/views/layouts/application.html.haml', /App_Name/, "#{app_name.humanize.titleize}" - gsub_file 'app/views/layouts/_navigation.html.haml', /App_Name/, "#{app_name.humanize.titleize}" - else - gsub_file 'app/views/layouts/application.html.erb', /App_Name/, "#{app_name.humanize.titleize}" - gsub_file 'app/views/layouts/_navigation.html.erb', /App_Name/, "#{app_name.humanize.titleize}" - end +%w(.env .travis.yml).each do |name| + file(name) { IO.read File.expand_path("~/etc/rails/template/#{name}") } end +file("README.md") { "# #{app_name.titleize}" } -# >--------------------------------[ extras ]---------------------------------< - -@current_recipe = "extras" -@before_configs["extras"].call if @before_configs["extras"] -say_recipe 'extras' - -config = {} -config['form_builder'] = multiple_choice("Use a form builder gem?", [["None", "none"], ["SimpleForm", "simple_form"]]) if true && true unless config.key?('form_builder') || prefs.has_key?(:form_builder) -config['ban_spiders'] = yes_wizard?("Set a robots.txt file to ban spiders?") if true && true unless config.key?('ban_spiders') || prefs.has_key?(:ban_spiders) -config['jsruntime'] = yes_wizard?("Add 'therubyracer' JavaScript runtime (for Linux users without node.js)?") if true && true unless config.key?('jsruntime') || prefs.has_key?(:jsruntime) -config['rvmrc'] = yes_wizard?("Create a project-specific rvm gemset and .rvmrc?") if true && true unless config.key?('rvmrc') || prefs.has_key?(:rvmrc) -@configs[@current_recipe] = config - -# Application template recipe for the rails_apps_composer. Change the recipe here: -# https://github.com/RailsApps/rails_apps_composer/blob/master/recipes/extras.rb - -## FORM BUILDER -case config['form_builder'] - when 'simple_form' - prefs[:form_builder] = 'simple_form' -end -case prefs[:form_builder] - when 'simple_form' - gem 'simple_form' - after_bundler do - if prefer :frontend, 'bootstrap' - say_wizard "recipe installing simple_form for use with Twitter Bootstrap" - generate 'simple_form:install --bootstrap' - else - say_wizard "recipe installing simple_form" - generate 'simple_form:install' - end - end -end - -## BAN SPIDERS -if config['ban_spiders'] - prefs[:ban_spiders] = true -end -if prefs[:ban_spiders] - say_wizard "Banning spiders by modifying 'public/robots.txt'" - after_bundler do - gsub_file 'public/robots.txt', /# User-Agent/, 'User-Agent' - gsub_file 'public/robots.txt', /# Disallow/, 'Disallow' - end -end - -## JSRUNTIME -if config['jsruntime'] - prefs[:jsruntime] = true -end -if prefs[:jsruntime] - say_wizard "Adding 'therubyracer' JavaScript runtime gem" - # maybe it was already added for bootstrap-less? - unless prefer :bootstrap, 'less' - gem 'therubyracer', :group => :assets, :platform => :ruby - end -end - -## RVMRC -if config['rvmrc'] - prefs[:rvmrc] = true -end -if prefs[:rvmrc] - # using the rvm Ruby API, see: - # http://blog.thefrontiergroup.com.au/2010/12/a-brief-introduction-to-the-rvm-ruby-api/ - if ENV['MY_RUBY_HOME'] && ENV['MY_RUBY_HOME'].include?('rvm') - begin - rvm_path = File.dirname(File.dirname(ENV['MY_RUBY_HOME'])) - rvm_lib_path = File.join(rvm_path, 'lib') - require 'rvm' - rescue LoadError - raise "RVM ruby lib is currently unavailable." - end - else - raise "RVM ruby lib is currently unavailable." - end - say_wizard "creating RVM gemset '#{app_name}'" - RVM.gemset_create app_name - run "rvm rvmrc trust" - say_wizard "switching to gemset '#{app_name}'" - begin - RVM.gemset_use! app_name - rescue StandardError - raise "rvm failure: unable to use gemset #{app_name}" - end - run "rvm gemset list" - copy_from_repo '.rvmrc' - gsub_file '.rvmrc', /App_Name/, "#{app_name}" -end - -## AFTER_EVERYTHING -after_everything do - say_wizard "recipe removing unnecessary files and whitespace" - %w{ - public/index.html - app/assets/images/rails.png - }.each { |file| remove_file file } - # remove commented lines and multiple blank lines from Gemfile - # thanks to https://github.com/perfectline/template-bucket/blob/master/cleanup.rb - gsub_file 'Gemfile', /#.*\n/, "\n" - gsub_file 'Gemfile', /\n^\s*\n/, "\n" - # remove commented lines and multiple blank lines from config/routes.rb - gsub_file 'config/routes.rb', / #.*\n/, "\n" - gsub_file 'config/routes.rb', /\n^\s*\n/, "\n" - # GIT - git :add => '.' if prefer :git, true - git :commit => "-aqm 'rails_apps_composer: extras'" if prefer :git, true -end - - - -# >---------------------------------[ Diagnostics ]----------------------------------< - -# remove prefs which are diagnostically irrelevant -redacted_prefs = prefs -redacted_prefs.delete(:git) -redacted_prefs.delete(:dev_webserver) -redacted_prefs.delete(:prod_webserver) -redacted_prefs.delete(:ban_spiders) -redacted_prefs.delete(:jsruntime) -redacted_prefs.delete(:rvmrc) - -if diagnostics_prefs.include? redacted_prefs - diagnostics[:prefs] = 'success' -else - diagnostics[:prefs] = 'fail' -end - - - -@current_recipe = nil - -# >-----------------------------[ Run 'Bundle Install' ]-------------------------------< - -say_wizard "Installing gems. This will take a while." -if prefs.has_key? :bundle_path - run "bundle install --without production --path #{prefs[:bundle_path]}" -else - run 'bundle install --without production' -end - -# >-----------------------------[ Run 'After Bundler' Callbacks ]-------------------------------< - -say_wizard "Running 'after bundler' callbacks." -require 'bundler/setup' -if prefer :templates, 'haml' - say_wizard "importing html2haml conversion tool" - require 'haml/html' -end -if prefer :templates, 'slim' - say_wizard "importing html2haml and haml2slim conversion tools" - require 'haml/html' - require 'haml2slim' -end -@after_blocks.each{|b| config = @configs[b[0]] || {}; @current_recipe = b[0]; b[1].call} - -# >-----------------------------[ Run 'After Everything' Callbacks ]-------------------------------< - -@current_recipe = nil -say_wizard "Running 'after everything' callbacks." -@after_everything_blocks.each{|b| config = @configs[b[0]] || {}; @current_recipe = b[0]; b[1].call} - -@current_recipe = nil -if diagnostics[:recipes] == 'success' - say_wizard("WOOT! The recipes you've selected are known to work together.") - say_wizard("If they don't, open an issue for rails_apps_composer on GitHub.") -else - say_wizard("\033[1m\033[36m" + "WARNING! The recipes you've selected might not work together." + "\033[0m") - say_wizard("Help us out by reporting whether this combination works or fails.") - say_wizard("Please open an issue for rails_apps_composer on GitHub.") - say_wizard("Your new application will contain diagnostics in its README file.") -end -if diagnostics[:prefs] == 'success' - say_wizard("WOOT! The preferences you've selected are known to work together.") - say_wizard("If they don't, open an issue for rails_apps_composer on GitHub.") -else - say_wizard("\033[1m\033[36m" + "WARNING! The preferences you've selected might not work together." + "\033[0m") - say_wizard("Help us out by reporting whether this combination works or fails.") - say_wizard("Please open an issue for rails_apps_composer on GitHub.") - say_wizard("Your new application will contain diagnostics in its README file.") -end -say_wizard "Finished running the rails_apps_composer app template." -say_wizard "Your new Rails app is ready. Time to run 'bundle install'." +run "createuser -s #{app_name}" +run "bundle install" +run "bundle exec rails generate rspec:install" +rake 'db:create' +rake 'db:test:prepare' +run "rm -rf test/; rm -rf README.rdoc; rm -rf public/index.html" +run "git init && git add . && git commit -am 'Initial commit.'"