├── sample_readme.txt
├── irb.rb
├── rspec_extras.rb
├── flashes_partial.haml.rb
├── flashes_partial.erb.rb
├── bson_ext.rb
├── activerecord_extras.rb
├── rake_init_tasks.rb
├── heroku.rb
├── ban_spiders.rb
├── jquery_fix.rb
├── git.rb
├── mongoid_cleanup.rb
├── css_setup.rb
├── rvm.rb
├── cucumber_extras.rb
├── yard.rb
├── seed_database.rb
├── exclude_database_yaml.rb
├── cleanup.rb
├── home_page.rb
├── jquery.rb
├── sample_readme.textile
├── application_layout.rb
├── action_mailer.rb
├── home_page_users.rb
├── capistrano_lastmile.rb
├── devise.rb
├── rspec.rb
├── devise_navigation.rb
├── autotest.rb
├── add_user_name.rb
├── cucumber.rb
├── users_page.rb
└── README.textile
/sample_readme.txt:
--------------------------------------------------------------------------------
1 | App_Name
2 | ========================
3 |
4 |
5 | ________________________
6 |
7 | License
8 |
9 |
--------------------------------------------------------------------------------
/irb.rb:
--------------------------------------------------------------------------------
1 | say_recipe 'irb'
2 |
3 | gem 'wirble', :group => :development
4 | gem 'awesome_print', :require => 'ap', :group => :developemnt
5 | gem 'interactive_editor', :group => :development
6 |
7 |
--------------------------------------------------------------------------------
/rspec_extras.rb:
--------------------------------------------------------------------------------
1 | say_recipe 'RSpec extras'
2 |
3 | after_bundler do
4 | # customize default formatting
5 | append_to_file ".rspec" do
6 | <<-'RSPEC'.gsub(/^ {6}/, '')
7 | --format progress
8 | RSPEC
9 | end
10 | end
11 |
12 |
--------------------------------------------------------------------------------
/flashes_partial.haml.rb:
--------------------------------------------------------------------------------
1 | if recipe_list.include? 'haml'
2 | say_recipe 'Flashes partial (Haml)'
3 |
4 | create_file 'app/views/shared/_flashes.html.haml' do
5 | <<-'FLASHES'.gsub(/^ {6}/, '')
6 | #flash
7 | - flash.each do |key, value|
8 | %div{ :id => "flash_#{key}" }
9 | =h value
10 | FLASHES
11 | end
12 | end
13 |
--------------------------------------------------------------------------------
/flashes_partial.erb.rb:
--------------------------------------------------------------------------------
1 | if recipe_list.include? 'erb'
2 | say_recipe 'Flashes partial (ERb)'
3 |
4 | create_file 'app/views/shared/_flashes.html.erb' do
5 | <<-'FLASHES'.gsub(/^ {6}/, '')
6 |
7 | <% flash.each do |key, value| -%>
8 |
<%=h value %>
9 | <% end -%>
10 |
11 | FLASHES
12 | end
13 | end
14 |
--------------------------------------------------------------------------------
/bson_ext.rb:
--------------------------------------------------------------------------------
1 | # >--------------------------------[ bson_ext ]--------------------------------<
2 |
3 | # Application template recipe. Check for a newer version here:
4 | # https://github.com/fortuity/rails-template-recipes/blob/master/bson_ext.rb
5 |
6 | if recipe_list.include? 'mongoid'
7 |
8 | # Add bson_ext gem for use with Mongoid
9 | say_recipe 'bson_ext'
10 |
11 | gem 'bson_ext', '>= 1.2.4'
12 |
13 | end
14 |
15 |
16 |
--------------------------------------------------------------------------------
/activerecord_extras.rb:
--------------------------------------------------------------------------------
1 | say_recipe 'ActiveRecord extras'
2 |
3 | gsub_file "Gemfile", /^gem 'sqlite3-ruby', :require => 'sqlite3'$/, ''
4 |
5 | gem 'mysql',
6 | :group => :production, :platforms => :ruby
7 | gem 'activerecord-jdbcmysql-adapter',
8 | :group => :production, :platforms => :jruby, :require => false
9 |
10 | gem 'sqlite3-ruby',
11 | :group => [:development, :test], :platforms => :ruby, :require => 'sqlite3'
12 | gem 'activerecord-jdbcsqlite3-adapter',
13 | :group => [:development, :test], :platforms => :jruby, :require => false
14 |
--------------------------------------------------------------------------------
/rake_init_tasks.rb:
--------------------------------------------------------------------------------
1 | say_recipe 'Create rake init:* tasks'
2 |
3 | create_file 'lib/tasks/init.rake' do
4 | <<-'RAKE'.gsub(/^ {4}/, '')
5 | unless Rake::Task.task_defined?("init")
6 | desc "Initializes the rails environment for development"
7 | task :init do ; end
8 | end
9 |
10 | # Add namespaced tasks to default :init task
11 | db_tasks = %w{ tmp:create db:schema:dump db:setup db:test:prepare }
12 | Rake::Task["init"].enhance do
13 | db_tasks.each { |t| Rake::Task[t].invoke }
14 | end
15 | RAKE
16 | end
17 |
18 |
--------------------------------------------------------------------------------
/heroku.rb:
--------------------------------------------------------------------------------
1 | # >--------------------------------[ heroku ]--------------------------------<
2 |
3 | # Application template recipe. Check for a newer version here:
4 | # https://github.com/fortuity/rails-template-recipes/blob/master/heroku.rb
5 |
6 | say_recipe 'Heroku'
7 |
8 | # Add a Heroku gem to the Gemfile
9 | gem 'heroku', :group => :development
10 |
11 | # Add a Heroku ignore file
12 | file ".slugignore", <<-EOS.gsub(/^ /, '')
13 | *.psd
14 | *.pdf
15 | test
16 | spec
17 | features
18 | doc
19 | docs
20 | EOS
21 |
22 | if extra_recipes.include? 'git'
23 | say_wizard "commiting changes to git"
24 | git :add => '.'
25 | git :commit => "-am 'Add a Heroku gem and slugignore file.'"
26 | end
27 |
--------------------------------------------------------------------------------
/ban_spiders.rb:
--------------------------------------------------------------------------------
1 | # >--------------------------------[ ban_spiders ]--------------------------------<
2 |
3 | # Application template recipe. Check for a newer version here:
4 | # https://github.com/fortuity/rails-template-recipes/blob/master/ban_spiders.rb
5 |
6 | say_recipe 'ban spiders'
7 |
8 | # ban spiders from your site by changing robots.txt
9 | say_wizard "banning spiders from your site by changing robots.txt"
10 | gsub_file 'public/robots.txt', /# User-Agent/, 'User-Agent'
11 | gsub_file 'public/robots.txt', /# Disallow/, 'Disallow'
12 |
13 | if extra_recipes.include? 'git'
14 | git :tag => "ban_spiders"
15 | git :add => '.'
16 | git :commit => "-am 'Ban spiders from the site by changing robots.txt'"
17 | end
18 |
--------------------------------------------------------------------------------
/jquery_fix.rb:
--------------------------------------------------------------------------------
1 | # >--------------------------------[ jquery_fix ]--------------------------------<
2 |
3 | # Application template recipe. Check for a newer version here:
4 | # https://github.com/fortuity/rails-template-recipes/blob/master/jquery_fix.rb
5 |
6 | say_recipe 'jQuery Fix'
7 |
8 | # see https://github.com/intridea/rails_wizard/issues#issue/27
9 | # the standard RailsWizard jQuery recipe has an error that must be fixed with this:
10 | gsub_file "config/application.rb", / config.action_view.javascript_expansions\[:defaults\] = \%w\(\)\n/, ""
11 |
12 | # Alternatively, use the "jquery" recipe from the fortuity/rails-template-recipes repository.
13 | # It substitutes for selecting jQuery in the Javascript Framework section of the RailsWizard web application.
14 |
--------------------------------------------------------------------------------
/git.rb:
--------------------------------------------------------------------------------
1 | # >--------------------------------[ Git ]---------------------------------<
2 |
3 | # Application template recipe. Check for a newer version here:
4 | # https://github.com/fortuity/rails-template-recipes/blob/master/git.rb
5 |
6 | # Set up Git for version control
7 | say_recipe 'Git'
8 |
9 | # Git should ignore some files
10 | remove_file '.gitignore'
11 | get "https://github.com/fortuity/rails3-gitignore/raw/master/gitignore.txt", ".gitignore"
12 |
13 | # Initialize new Git repo
14 | git :init
15 | git :add => '.'
16 | git :commit => "-aqm 'Initial commit of new Rails app'"
17 |
18 | say_wizard "Creating a git working_branch (to follow the stream of development)."
19 | git :checkout => ' -b working_branch'
20 | git :add => '.'
21 | git :commit => "-m 'Initial commit of working_branch (to establish a clean base line).'"
22 |
--------------------------------------------------------------------------------
/mongoid_cleanup.rb:
--------------------------------------------------------------------------------
1 | # >--------------------------------[ mongoid_cleanup ]--------------------------------<
2 |
3 | # Application template recipe. Check for a newer version here:
4 | # https://github.com/fortuity/rails-template-recipes/blob/master/mongoid_cleanup.rb
5 |
6 | say_recipe 'Mongoid Cleanup'
7 |
8 | if recipe_list.include? 'mongoid'
9 |
10 | # update to a newer Mongoid version
11 | gsub_file 'Gemfile', /"mongoid", ">= 2.0.0.beta.19"/, '"mongoid", ">= 2.0.0.rc.8"'
12 |
13 | # note: the mongoid generator automatically modifies the config/application.rb file
14 | # to remove the ActiveRecord dependency by commenting out "require active_record/railtie'"
15 |
16 | # remove unnecessary 'config/database.yml' file
17 | remove_file 'config/database.yml'
18 |
19 | if extra_recipes.include? 'git'
20 | git :tag => "mongoid_cleanup"
21 | git :add => '.'
22 | git :commit => "-am 'use newer Mongoid gem and remove database.yml file.'"
23 | end
24 |
25 | end
--------------------------------------------------------------------------------
/css_setup.rb:
--------------------------------------------------------------------------------
1 | # >--------------------------------[ css_setup ]--------------------------------<
2 |
3 | # Application template recipe. Check for a newer version here:
4 | # https://github.com/fortuity/rails-template-recipes/blob/master/css_setup.rb
5 |
6 | say_recipe 'CSS Setup'
7 |
8 | after_bundler do
9 |
10 | #----------------------------------------------------------------------------
11 | # Add a stylesheet with styles for a horizontal menu and flash messages
12 | #----------------------------------------------------------------------------
13 | create_file 'public/stylesheets/application.css' do <<-CSS
14 | ul.hmenu {
15 | list-style: none;
16 | margin: 0 0 2em;
17 | padding: 0;
18 | }
19 | ul.hmenu li {
20 | display: inline;
21 | }
22 | #flash_notice, #flash_alert {
23 | padding: 5px 8px;
24 | margin: 10px 0;
25 | }
26 | #flash_notice {
27 | background-color: #CFC;
28 | border: solid 1px #6C6;
29 | }
30 | #flash_alert {
31 | background-color: #FCC;
32 | border: solid 1px #C66;
33 | }
34 | CSS
35 | end
36 |
37 | end
--------------------------------------------------------------------------------
/rvm.rb:
--------------------------------------------------------------------------------
1 | say_recipe 'rvm'
2 |
3 | # load in RVM environment
4 | if ENV['MY_RUBY_HOME'] && ENV['MY_RUBY_HOME'].include?('rvm')
5 | begin
6 | rvm_path = File.dirname(File.dirname(ENV['MY_RUBY_HOME']))
7 | rvm_lib_path = File.join(rvm_path, 'lib')
8 | $LOAD_PATH.unshift rvm_lib_path
9 |
10 | require 'rvm'
11 | rescue LoadError
12 | # RVM is unavailable at this point.
13 | raise "RVM ruby lib is currently unavailable."
14 | end
15 | else
16 | raise "RVM ruby lib is currently unavailable."
17 | end
18 |
19 | rvm_env = "default@#{app_name}"
20 |
21 | say_wizard "Creating RVM gemset #{app_name}"
22 | RVM.gemset_create app_name
23 |
24 | say_wizard "Trusting project's .rvmrc"
25 | run "rvm rvmrc trust"
26 |
27 | say_wizard "Switching to use RVM gemset #{app_name}"
28 | RVM.gemset_use! app_name
29 |
30 | # create rvmrc file
31 | create_file '.rvmrc' do
32 | "rvm #{rvm_env}"
33 | end
34 |
35 | if run("gem list --installed bundler", :capture => true) =~ /false/
36 | run "gem install bundler --no-rdoc --no-ri"
37 | end
38 |
--------------------------------------------------------------------------------
/cucumber_extras.rb:
--------------------------------------------------------------------------------
1 | say_recipe 'Cucumber extras'
2 |
3 | # pop a browser window in cucumber and other tasks
4 | gem 'launchy', :group => :test
5 |
6 | gem 'database_cleaner', :group => :test
7 |
8 | gem 'factory_girl_rails', :group => [:development, :test]
9 |
10 | after_bundler do
11 | # Add autotest runner erb opts
12 | gsub_file "config/cucumber.yml", /^(std_opts = .*wip")$/, '\1' << <<-'OPTS'.gsub(/^ {4}/, '')
13 |
14 | std_opts += " --tags ~@proposed --color"
15 | autotest_opts = "--format pretty --strict --tags ~@proposed --color"
16 | autotest_all_opts = "--format #{ENV['CUCUMBER_FORMAT'] || 'progress'} --strict --tags ~@proposed --color #{ENV['CUCUMBER_EXCLUDE']}"
17 | OPTS
18 |
19 | # Add autotest runner formats
20 | gsub_file "config/cucumber.yml", /^(rerun: .* ~@wip)$/, '\1 --tags ~@proposed'
21 | append_to_file "config/cucumber.yml" do
22 | <<-'YAML'.gsub(/^ {6}/, '')
23 | autotest: <%= autotest_opts %> features
24 | autotest-all: <%= autotest_all_opts %> features
25 | YAML
26 | end
27 | end
28 |
29 |
--------------------------------------------------------------------------------
/yard.rb:
--------------------------------------------------------------------------------
1 | # >---------------------------------[ Yard ]----------------------------------<
2 |
3 | # Application template recipe. Check for a newer version here:
4 | # https://github.com/fortuity/rails-template-recipes/blob/master/yard.rb
5 |
6 | # Replaces RDoc with Yard for documentation.
7 |
8 | if recipe_list.include? 'yard'
9 |
10 | say_recipe 'yard'
11 |
12 | gem 'yard', :group => [:development, :test]
13 | gem 'yardstick', :group => [:development, :test]
14 |
15 | run 'rm -rf /doc/'
16 | say_wizard "generating a .yardopts file for yardoc configuration"
17 | file '.yardopts',<<-RUBY
18 | ## --use-cache
19 | --title #{app_name}
20 | app/**/*.rb
21 | config/routes.rb
22 | lib/**/*.rb
23 | README.textile
24 | spec/
25 | --exclude README.md --exclude LICENSE
26 | RUBY
27 |
28 | after_bundler do
29 |
30 | run 'yardoc'
31 |
32 | if extra_recipes.include? 'git'
33 | git :tag => "yard_installation"
34 | git :add => '.'
35 | git :commit => "-am 'Installed Yard as an alternative to RDoc.'"
36 | end
37 |
38 | end
39 |
40 | end
--------------------------------------------------------------------------------
/seed_database.rb:
--------------------------------------------------------------------------------
1 | # >--------------------------------[ seed_database ]--------------------------------<
2 |
3 | # Application template recipe. Check for a newer version here:
4 | # https://github.com/fortuity/rails-template-recipes/blob/master/seed_database.rb
5 |
6 | say_recipe 'Seed Database'
7 |
8 | after_bundler do
9 |
10 | if extra_recipes.include? 'devise'
11 |
12 | if recipe_list.include? 'mongoid'
13 | # create a default user
14 | say_wizard "creating a default user"
15 | append_file 'db/seeds.rb' do <<-FILE
16 | puts 'EMPTY THE MONGODB DATABASE'
17 | Mongoid.master.collections.reject { |c| c.name =~ /^system/}.each(&:drop)
18 | puts 'SETTING UP DEFAULT USER LOGIN'
19 | user = User.create! :name => 'First User', :email => 'user@test.com', :password => 'please', :password_confirmation => 'please'
20 | puts 'New user created: ' << user.name
21 | FILE
22 | end
23 | end
24 |
25 | run 'rake db:seed'
26 |
27 | end
28 |
29 | if extra_recipes.include? 'git'
30 | git :tag => "database_seed"
31 | git :add => '.'
32 | git :commit => "-am 'Create a database seed file with a default user.'"
33 | end
34 |
35 | end
36 |
--------------------------------------------------------------------------------
/exclude_database_yaml.rb:
--------------------------------------------------------------------------------
1 | say_recipe 'Exclude database.yml from version control'
2 |
3 | create_file 'lib/tasks/init_database_yaml.rake' do
4 | <<-'RAKE'.gsub(/^ {4}/, '')
5 | namespace :init do
6 | task 'database_yaml' do
7 | unless File.exists?(File.join('config', 'database.yml'))
8 | cp(File.join('config', 'database.sample.yml'),
9 | File.join('config', 'database.yml'), :verbose => true)
10 | end
11 | end
12 | end
13 |
14 | unless Rake::Task.task_defined?("init")
15 | desc "Initializes the rails environment for development"
16 | task :init do ; end
17 | end
18 |
19 | # Add namespaced tasks to default :init task
20 | Rake::Task["init"].enhance ["init:database_yaml"]
21 | RAKE
22 | end
23 |
24 | # wait until all generators have had a chance to touch config/database.yml
25 | after_bundler do
26 | say_wizard "Adding Java platform detection in database.yml"
27 | gsub_file "config/database.yml", /^(\s*adapter:) (.+)$/,
28 | %q{\1 <%= RUBY_PLATFORM =~ /java/ ? 'jdbc\2' : '\2' %>}
29 |
30 | say_wizard "Creating config/database.sample.yml for version control"
31 | FileUtils.cp "config/database.yml", "config/database.sample.yml"
32 | end
33 |
--------------------------------------------------------------------------------
/cleanup.rb:
--------------------------------------------------------------------------------
1 | # >--------------------------------[ cleanup ]--------------------------------<
2 |
3 | # Application template recipe. Check for a newer version here:
4 | # https://github.com/fortuity/rails-template-recipes/blob/master/cleanup.rb
5 |
6 | say_recipe 'cleanup'
7 |
8 | # remove unnecessary files
9 | %w{
10 | README
11 | doc/README_FOR_APP
12 | public/index.html
13 | public/images/rails.png
14 | }.each { |file| remove_file file }
15 |
16 | # add placeholder READMEs
17 | get "https://github.com/fortuity/rails-template-recipes/raw/master/sample_readme.txt", "README"
18 | get "https://github.com/fortuity/rails-template-recipes/raw/master/sample_readme.textile", "README.textile"
19 | gsub_file "README", /App_Name/, "#{app_name.humanize.titleize}"
20 | gsub_file "README.textile", /App_Name/, "#{app_name.humanize.titleize}"
21 |
22 | # remove commented lines from Gemfile
23 | # thanks to https://github.com/perfectline/template-bucket/blob/master/cleanup.rb
24 | gsub_file "Gemfile", /#.*\n/, "\n"
25 | gsub_file "Gemfile", /\n+/, "\n"
26 |
27 | if extra_recipes.include? 'git'
28 | git :tag => "file_cleanup"
29 | git :add => '.'
30 | git :commit => "-am 'Removed unnecessary files left over from initial app generation.'"
31 | end
32 |
--------------------------------------------------------------------------------
/home_page.rb:
--------------------------------------------------------------------------------
1 | # >--------------------------------[ home_page ]--------------------------------<
2 |
3 | # Application template recipe. Check for a newer version here:
4 | # https://github.com/fortuity/rails-template-recipes/blob/master/home_page.rb
5 |
6 | # There is Haml code in this script. Changing the indentation is perilous between HAMLs.
7 |
8 | say_recipe 'Home Page'
9 |
10 | after_bundler do
11 |
12 | # remove the default home page
13 | remove_file 'public/index.html'
14 |
15 | # create a home controller and view
16 | generate(:controller, "home index")
17 |
18 | # set up a simple home page (with placeholder content)
19 | if recipe_list.include? 'haml'
20 | remove_file 'app/views/home/index.html.haml'
21 | # we have to use single-quote-style-heredoc to avoid interpolation
22 | create_file 'app/views/home/index.html.haml' do
23 | <<-'HAML'
24 | %h3 Home
25 | HAML
26 | end
27 | else
28 | remove_file 'app/views/home/index.html.erb'
29 | create_file 'app/views/home/index.html.erb' do <<-ERB
30 | Home
31 | ERB
32 | end
33 | end
34 |
35 | # set routes
36 | gsub_file 'config/routes.rb', /get \"home\/index\"/, 'root :to => "home#index"'
37 |
38 | if extra_recipes.include? 'git'
39 | git :tag => "home_page"
40 | git :add => '.'
41 | git :commit => "-am 'Create a home controller and view.'"
42 | end
43 |
44 | end
--------------------------------------------------------------------------------
/jquery.rb:
--------------------------------------------------------------------------------
1 | # >--------------------------------[ jQuery ]---------------------------------<
2 |
3 | # Application template recipe. Check for a newer version here:
4 | # https://github.com/fortuity/rails-template-recipes/blob/master/jquery.rb
5 |
6 | # This recipe replaces the RailsWizard standard jQuery recipe which has an error as of 18 Feb 2011:
7 | # https://github.com/intridea/rails_wizard/issues#issue/27
8 |
9 | # Utilize the jQuery Javascript framework instead of Protoype.
10 |
11 | if extra_recipes.include? 'jquery'
12 |
13 | # Adds the latest jQuery and Rails UJS helpers for jQuery.
14 | say_recipe 'jQuery'
15 |
16 | # remove the Prototype adapter file
17 | remove_file 'public/javascripts/rails.js'
18 | # add jQuery files
19 | inside "public/javascripts" do
20 | get "https://github.com/rails/jquery-ujs/raw/master/src/rails.js", "rails.js"
21 | get "http://code.jquery.com/jquery-1.5.min.js", "jquery.js"
22 | end
23 | # adjust the Javascript defaults
24 | inject_into_file 'config/application.rb', "config.action_view.javascript_expansions[:defaults] = %w(jquery rails)\n", :after => "config.action_view.javascript_expansions[:defaults] = %w()\n", :verbose => false
25 | gsub_file "config/application.rb", /config.action_view.javascript_expansions\[:defaults\] = \%w\(\)\n/, ""
26 |
27 | if extra_recipes.include? 'git'
28 | git :tag => "jquery_installation"
29 | git :add => '.'
30 | git :commit => "-am 'jQuery installation.'"
31 | end
32 |
33 | end
34 |
35 |
--------------------------------------------------------------------------------
/sample_readme.textile:
--------------------------------------------------------------------------------
1 | h1. App_Name
2 |
3 | Lorem ipsum dolor sit amet, consectetur adipiscing elit.
4 |
5 | h2. More Information
6 |
7 | Lorem ipsum dolor sit amet, consectetur adipiscing elit.
8 |
9 | h2. Required Gems
10 |
11 | This application requires this gem:
12 |
13 | * "rails":http://rubygems.org/gems/rails
14 |
15 | h2. Dependencies
16 |
17 | To use this application, you will need:
18 |
19 | * The Ruby language (version 1.8.7 or 1.9.2)
20 | * Rails (version 3.0.4 or newer)
21 |
22 | h2. Installing the Application
23 |
24 | Lorem ipsum dolor sit amet, consectetur adipiscing elit.
25 |
26 | h2. Getting Started
27 |
28 | Lorem ipsum dolor sit amet, consectetur adipiscing elit.
29 |
30 | h2. Documentation and Support
31 |
32 | This is the only documentation.
33 |
34 | h4. Issues
35 |
36 | Lorem ipsum dolor sit amet, consectetur adipiscing elit.
37 |
38 | h2. Similar Projects
39 |
40 | Lorem ipsum dolor sit amet, consectetur adipiscing elit.
41 |
42 | h2. Contributing
43 |
44 | If you make improvements to this application, please share with others.
45 |
46 | * Fork the project on GitHub.
47 | * Make your feature addition or bug fix.
48 | * Commit with Git.
49 | * Send the author a pull request.
50 |
51 | If you add functionality to this application, create an alternative implementation, or build an application that is similar, please contact me and I'll add a note to the README so that others can find your work.
52 |
53 | h2. Credits
54 |
55 | Lorem ipsum dolor sit amet, consectetur adipiscing elit.
56 |
57 | h2. License
58 |
59 | Lorem ipsum dolor sit amet, consectetur adipiscing elit.
60 |
--------------------------------------------------------------------------------
/application_layout.rb:
--------------------------------------------------------------------------------
1 | # >--------------------------------[ application_layout ]--------------------------------<
2 |
3 | # Application template recipe. Check for a newer version here:
4 | # https://github.com/fortuity/rails-template-recipes/blob/master/application_layout.rb
5 |
6 | # There is Haml code in this script. Changing the indentation is perilous between HAMLs.
7 |
8 | say_recipe 'Application Layout'
9 |
10 | after_bundler do
11 |
12 | #----------------------------------------------------------------------------
13 | # Set up the default application layout
14 | #----------------------------------------------------------------------------
15 | if recipe_list.include? 'haml'
16 | remove_file 'app/views/layouts/application.html.erb'
17 | create_file 'app/views/layouts/application.html.haml' do <<-HAML
18 | !!!
19 | %html
20 | %head
21 | %title #{app_name}
22 | = stylesheet_link_tag :all
23 | = javascript_include_tag :defaults
24 | = csrf_meta_tag
25 | %body
26 | - flash.each do |name, msg|
27 | = content_tag :div, msg, :id => "flash_\#{name}" if msg.is_a?(String)
28 | = yield
29 | HAML
30 | end
31 | else
32 | inject_into_file 'app/views/layouts/application.html.erb', :after => "\n" do
33 | <<-ERB
34 | <%- flash.each do |name, msg| -%>
35 | <%= content_tag :div, msg, :id => "flash_\#{name}" if msg.is_a?(String) %>
36 | <%- end -%>
37 | ERB
38 | end
39 | end
40 |
41 | if extra_recipes.include? 'git'
42 | git :tag => "app_layout"
43 | git :add => '.'
44 | git :commit => "-am 'Add application layout.'"
45 | end
46 |
47 | end
--------------------------------------------------------------------------------
/action_mailer.rb:
--------------------------------------------------------------------------------
1 | # >--------------------------------[ action_mailer ]--------------------------------<
2 |
3 | # Application template recipe. Check for a newer version here:
4 | # https://github.com/fortuity/rails-template-recipes/blob/master/action_mailer.rb
5 |
6 | say_recipe 'ActionMailer configuration'
7 |
8 | # modifying environment configuration files for ActionMailer
9 | gsub_file 'config/environments/development.rb', /# Don't care if the mailer can't send/, '# ActionMailer Config'
10 | gsub_file 'config/environments/development.rb', /config.action_mailer.raise_delivery_errors = false/ do
11 | <<-RUBY
12 | config.action_mailer.default_url_options = { :host => 'localhost:3000' }
13 | # A dummy setup for development - no deliveries, but logged
14 | config.action_mailer.delivery_method = :smtp
15 | config.action_mailer.perform_deliveries = false
16 | config.action_mailer.raise_delivery_errors = true
17 | config.action_mailer.default :charset => "utf-8"
18 | RUBY
19 | end
20 | gsub_file 'config/environments/production.rb', /config.active_support.deprecation = :notify/ do
21 | <<-RUBY
22 | config.active_support.deprecation = :notify
23 |
24 | config.action_mailer.default_url_options = { :host => 'yourhost.com' }
25 | # ActionMailer Config
26 | # Setup for production - deliveries, no errors raised
27 | config.action_mailer.delivery_method = :smtp
28 | config.action_mailer.perform_deliveries = true
29 | config.action_mailer.raise_delivery_errors = false
30 | config.action_mailer.default :charset => "utf-8"
31 | RUBY
32 | end
33 |
34 | if extra_recipes.include? 'git'
35 | git :tag => "ActionMailer_config"
36 | git :add => '.'
37 | git :commit => "-am 'Set ActionMailer configuration.'"
38 | end
39 |
--------------------------------------------------------------------------------
/home_page_users.rb:
--------------------------------------------------------------------------------
1 | # >--------------------------------[ home_page_users ]--------------------------------<
2 |
3 | # Application template recipe. Check for a newer version here:
4 | # https://github.com/fortuity/rails-template-recipes/blob/master/home_page_users.rb
5 |
6 | # There is Haml code in this script. Changing the indentation is perilous between HAMLs.
7 |
8 | say_recipe 'Home Page Showing Users'
9 |
10 | after_bundler do
11 |
12 | if extra_recipes.include? 'devise'
13 |
14 | #----------------------------------------------------------------------------
15 | # Modify the home controller
16 | #----------------------------------------------------------------------------
17 | gsub_file 'app/controllers/home_controller.rb', /def index/ do
18 | <<-RUBY
19 | def index
20 | @users = User.all
21 | RUBY
22 | end
23 |
24 | #----------------------------------------------------------------------------
25 | # Replace the home page
26 | #----------------------------------------------------------------------------
27 | if recipe_list.include? 'haml'
28 | remove_file 'app/views/home/index.html.haml'
29 | # we have to use single-quote-style-heredoc to avoid interpolation
30 | create_file 'app/views/home/index.html.haml' do
31 | <<-'HAML'
32 | %h3 Home
33 | - @users.each do |user|
34 | %p User: #{user.name}
35 | HAML
36 | end
37 | else
38 | append_file 'app/views/home/index.html.erb' do <<-ERB
39 | Home
40 | <% @users.each do |user| %>
41 | User: <%= user.name %>
42 | <% end %>
43 | ERB
44 | end
45 | end
46 |
47 | end
48 |
49 | if extra_recipes.include? 'git'
50 | git :tag => "home_page_with_users"
51 | git :add => '.'
52 | git :commit => "-am 'Added display of users to the home page.'"
53 | end
54 |
55 | end
--------------------------------------------------------------------------------
/capistrano_lastmile.rb:
--------------------------------------------------------------------------------
1 | say_recipe "Capistrano (lastmile)"
2 |
3 | gem 'capistrano', :group => :development
4 | gem 'capistrano-ext', :group => :development, :require => nil
5 | gem 'capistrano-lastmile', :group => :development, :require => nil,
6 | :git => "git://github.com/fnichol/capistrano-lastmile.git"
7 | gem 'ffi-ncurses', :group => :development, :platforms => :jruby
8 |
9 | after_bundler do
10 | file 'Capfile', <<-CAPFILE.gsub(/^ {4}/, '')
11 | require "rubygems"
12 | require "bundler/setup"
13 |
14 | # override default staging environments set by capistrano-lastmile
15 | #set :stages, %w{uat testing staging production}
16 | # override default stage set by capistrano-lastmile
17 | #set :default_stage, "uat"
18 |
19 | # enable default-disabled recipes
20 | #set :use_config_yaml, true
21 | #set :use_whenever, true
22 |
23 | require "capistrano/lastmile"
24 | CAPFILE
25 |
26 | file 'config/deploy.rb', <<-DEPLOY.gsub(/^ {4}/, '')
27 | # general deployment configuration
28 | # please put specific deployment config in config/deploy/*.rb
29 |
30 | set :application, "#{app_name}"
31 |
32 | set :repository, "git://github.com/"
33 | DEPLOY
34 |
35 | file 'config/deploy/staging.rb', <<-STAGING.gsub(/^ {4}/, '')
36 | # STAGING-specific deployment configuration
37 | # please put general deployment config in config/deploy.rb
38 |
39 | set :db_username, "#{app_name[0,11]}_stg"
40 |
41 | set :deploy_server, "vagrant"
42 | STAGING
43 |
44 | file 'config/deploy/production.rb', <<-PRODUCTION.gsub(/^ {4}/, '')
45 | # PRODUCTION-specific deployment configuration
46 | # please put general deployment config in config/deploy.rb
47 |
48 | set :db_username, "#{app_name[0,11]}_prd"
49 |
50 | set :deploy_server, "prd.example.com"
51 | PRODUCTION
52 | end
53 |
--------------------------------------------------------------------------------
/devise.rb:
--------------------------------------------------------------------------------
1 | # >--------------------------------[ Devise ]---------------------------------<
2 |
3 | # Application template recipe. Check for a newer version here:
4 | # https://github.com/fortuity/rails-template-recipes/blob/master/devise.rb
5 |
6 | # This recipe replaces the RailsWizard standard Devise recipe which has an error as of 18 Feb 2011:
7 | # https://github.com/intridea/rails_wizard/issues#issue/13
8 |
9 | # Utilize Devise for authentication, automatically configured for your selected ORM.
10 | say_recipe 'Devise'
11 |
12 | gem "devise", ">= 1.2.0"
13 |
14 | after_bundler do
15 |
16 | #----------------------------------------------------------------------------
17 | # Run the Devise generator
18 | #----------------------------------------------------------------------------
19 | generate 'devise:install'
20 |
21 | if recipe_list.include? 'mongo_mapper'
22 | gem 'mm-devise'
23 | gsub_file 'config/initializers/devise.rb', 'devise/orm/active_record', 'devise/orm/mongo_mapper_active_model'
24 | elsif recipe_list.include? 'mongoid'
25 | # Nothing to do (Devise changes its initializer automatically when Mongoid is detected)
26 | # gsub_file 'config/initializers/devise.rb', 'devise/orm/active_record', 'devise/orm/mongoid'
27 | elsif recipe_list.include? 'active_record'
28 | # Nothing to do
29 | else
30 | # Nothing to do
31 | end
32 |
33 | #----------------------------------------------------------------------------
34 | # Prevent logging of password_confirmation
35 | #----------------------------------------------------------------------------
36 | gsub_file 'config/application.rb', /:password/, ':password, :password_confirmation'
37 |
38 | if extra_recipes.include? 'git'
39 | git :tag => "devise_installation"
40 | git :add => '.'
41 | git :commit => "-am 'Added Devise for authentication.'"
42 | end
43 |
44 | #----------------------------------------------------------------------------
45 | # Generate models and routes for a User
46 | #----------------------------------------------------------------------------
47 | generate 'devise user'
48 |
49 | if extra_recipes.include? 'git'
50 | git :tag => "devise_user"
51 | git :add => '.'
52 | git :commit => "-am 'Devise generated models and routes for a User.'"
53 | end
54 |
55 | end
--------------------------------------------------------------------------------
/rspec.rb:
--------------------------------------------------------------------------------
1 | # >---------------------------------[ RSpec ]---------------------------------<
2 |
3 | # Application template recipe. Check for a newer version here:
4 | # https://github.com/fortuity/rails-template-recipes/blob/master/rspec.rb
5 |
6 | # This recipe replaces the RailsWizard standard RSpec recipe and adds extras.
7 |
8 | if extra_recipes.include? 'rspec'
9 |
10 | # Use RSpec instead of TestUnit
11 | say_recipe 'RSpec'
12 |
13 | gem 'rspec-rails', '>= 2.5', :group => [:development, :test]
14 | gem 'database_cleaner', '>= 0.6.6', :group => :test
15 | gem 'factory_girl_rails', ">= 1.1.beta1", :group => :test
16 |
17 | if extra_recipes.include? 'mongoid'
18 | # include RSpec matchers from the mongoid-rspec gem
19 | gem 'mongoid-rspec', ">= 1.4.1", :group => :test
20 | end
21 |
22 | # note: there is no need to specify the RSpec generator in the config/application.rb file
23 |
24 | after_bundler do
25 |
26 | generate 'rspec:install'
27 |
28 | # remove ActiveRecord artifacts
29 | gsub_file 'spec/spec_helper.rb', /config.fixture_path/, '# config.fixture_path'
30 | gsub_file 'spec/spec_helper.rb', /config.use_transactional_fixtures/, '# config.use_transactional_fixtures'
31 |
32 | # reset your application database to a pristine state during testing
33 | inject_into_file 'spec/spec_helper.rb', :before => "\nend" do
34 | <<-RUBY
35 | \n
36 | # Clean up the database
37 | require 'database_cleaner'
38 | config.before(:suite) do
39 | DatabaseCleaner.strategy = :truncation
40 | DatabaseCleaner.orm = "mongoid"
41 | end
42 |
43 | config.before(:each) do
44 | DatabaseCleaner.clean
45 | end
46 | RUBY
47 | end
48 |
49 | # remove either possible occurrence of "require rails/test_unit/railtie"
50 | gsub_file 'config/application.rb', /require 'rails\/test_unit\/railtie'/, "# require 'rails/test_unit/railtie'"
51 | gsub_file 'config/application.rb', /require "rails\/test_unit\/railtie"/, "# require 'rails/test_unit/railtie'"
52 |
53 | say_wizard "Removing test folder (not needed for RSpec)"
54 | run 'rm -rf test/'
55 |
56 | if extra_recipes.include? 'mongoid'
57 | # configure RSpec to use matchers from the mongoid-rspec gem
58 | create_file 'spec/support/mongoid.rb' do
59 | <<-RUBY
60 | RSpec.configure do |config|
61 | config.include Mongoid::Matchers
62 | end
63 | RUBY
64 | end
65 | end
66 |
67 | if extra_recipes.include? 'devise'
68 | # add Devise test helpers
69 | create_file 'spec/support/devise.rb' do
70 | <<-RUBY
71 | RSpec.configure do |config|
72 | config.include Devise::TestHelpers, :type => :controller
73 | end
74 | RUBY
75 | end
76 | end
77 |
78 | if extra_recipes.include? 'git'
79 | git :tag => "rspec_installation"
80 | git :add => '.'
81 | git :commit => "-am 'Installed RSpec.'"
82 | end
83 |
84 | end
85 |
86 | end
--------------------------------------------------------------------------------
/devise_navigation.rb:
--------------------------------------------------------------------------------
1 | # >--------------------------------[ devise_navigation ]--------------------------------<
2 |
3 | # Application template recipe. Check for a newer version here:
4 | # https://github.com/fortuity/rails-template-recipes/blob/master/devise_navigation.rb
5 |
6 | # There is Haml code in this script. Changing the indentation is perilous between HAMLs.
7 |
8 | say_recipe 'Devise Navigation'
9 |
10 | after_bundler do
11 |
12 | if extra_recipes.include? 'devise'
13 |
14 | #----------------------------------------------------------------------------
15 | # Create navigation links for Devise
16 | #----------------------------------------------------------------------------
17 | if recipe_list.include? 'haml'
18 | create_file "app/views/devise/menu/_login_items.html.haml" do <<-'HAML'
19 | - if user_signed_in?
20 | %li
21 | = link_to('Logout', destroy_user_session_path)
22 | - else
23 | %li
24 | = link_to('Login', new_user_session_path)
25 | HAML
26 | end
27 | else
28 | create_file "app/views/devise/menu/_login_items.html.erb" do <<-ERB
29 | <% if user_signed_in? %>
30 |
31 | <%= link_to('Logout', destroy_user_session_path) %>
32 |
33 | <% else %>
34 |
35 | <%= link_to('Login', new_user_session_path) %>
36 |
37 | <% end %>
38 | ERB
39 | end
40 | end
41 |
42 | if recipe_list.include? 'haml'
43 | create_file "app/views/devise/menu/_registration_items.html.haml" do <<-'HAML'
44 | - if user_signed_in?
45 | %li
46 | = link_to('Edit account', edit_user_registration_path)
47 | - else
48 | %li
49 | = link_to('Sign up', new_user_registration_path)
50 | HAML
51 | end
52 | else
53 | create_file "app/views/devise/menu/_registration_items.html.erb" do <<-ERB
54 | <% if user_signed_in? %>
55 |
56 | <%= link_to('Edit account', edit_user_registration_path) %>
57 |
58 | <% else %>
59 |
60 | <%= link_to('Sign up', new_user_registration_path) %>
61 |
62 | <% end %>
63 | ERB
64 | end
65 | end
66 |
67 | #----------------------------------------------------------------------------
68 | # Add navigation links to the default application layout
69 | #----------------------------------------------------------------------------
70 | if recipe_list.include? 'haml'
71 | inject_into_file 'app/views/layouts/application.html.haml', :after => "%body\n" do <<-HAML
72 | %ul.hmenu
73 | = render 'devise/menu/registration_items'
74 | = render 'devise/menu/login_items'
75 | HAML
76 | end
77 | else
78 | inject_into_file 'app/views/layouts/application.html.erb', :after => "\n" do
79 | <<-ERB
80 |
84 | ERB
85 | end
86 | end
87 |
88 | if extra_recipes.include? 'git'
89 | git :tag => "devise_navlinks"
90 | git :add => '.'
91 | git :commit => "-am 'Add navigation links for Devise.'"
92 | end
93 |
94 | end
95 |
96 | end
--------------------------------------------------------------------------------
/autotest.rb:
--------------------------------------------------------------------------------
1 | say_recipe 'autotest'
2 |
3 | gem 'autotest', :group => :test
4 | gem 'autotest-growl', :group => :test
5 |
6 | # if rails project is being generated from a mac, then add a mac bundler group
7 | # and exclude the group when bundler'ing on other platforms
8 | if RUBY_PLATFORM =~ /darwin/
9 | gem 'autotest-fsevent', :group => :test_mac, :platforms => :ruby
10 | end
11 |
12 | create_file 'lib/tasks/auto.rake' do
13 | <<-'RAKE'.gsub(/^ {4}/, '')
14 | namespace :auto do
15 | desc 'Runs autotest on cucumber and rspec tests'
16 | task :test do
17 | gem 'test-unit', '1.2.3' if RUBY_VERSION.to_f >= 1.9
18 | ENV['RSPEC'] = 'true' # allows autotest to discover rspec
19 | ENV['AUTOTEST'] = 'true' # allows autotest to run w/ color on linux
20 | ENV['AUTOFEATURE'] = 'true' # allows autotest to discover cucumber
21 | system((RUBY_PLATFORM =~ /mswin|mingw/ ? 'autotest.bat' : 'autotest'), *ARGV) ||
22 | $stderr.puts("Unable to find autotest. Please install ZenTest or fix your PATH")
23 | end
24 |
25 | desc 'Runs autotest on only rspec tests'
26 | task :spec do
27 | gem 'test-unit', '1.2.3' if RUBY_VERSION.to_f >= 1.9
28 | ENV['RSPEC'] = 'true' # allows autotest to discover rspec
29 | ENV['AUTOTEST'] = 'true' # allows autotest to run w/ color on linux
30 | ENV['AUTOFEATURE'] = 'false' # allows autotest to discover cucumber
31 | system((RUBY_PLATFORM =~ /mswin|mingw/ ? 'autotest.bat' : 'autotest'), *ARGV) ||
32 | $stderr.puts("Unable to find autotest. Please install ZenTest or fix your PATH")
33 | end
34 |
35 | desc 'Runs autotest on only cucumber tests'
36 | task :cucumber do
37 | gem 'test-unit', '1.2.3' if RUBY_VERSION.to_f >= 1.9
38 | ENV['RSPEC'] = 'false' # allows autotest to discover rspec
39 | ENV['AUTOTEST'] = 'true' # allows autotest to run w/ color on linux
40 | ENV['AUTOFEATURE'] = 'true' # allows autotest to discover cucumber
41 | system((RUBY_PLATFORM =~ /mswin|mingw/ ? 'autotest.bat' : 'autotest'), *ARGV) ||
42 | $stderr.puts("Unable to find autotest. Please install ZenTest or fix your PATH")
43 | end
44 |
45 | desc 'Alias for auto:test'
46 | task :all => 'auto:test'
47 | end
48 |
49 | desc 'Autotest'
50 | task :auto => 'auto:test'
51 | RAKE
52 | end
53 |
54 | after_bundler do
55 | create_file '.autotest' do
56 | <<-'AUTOTEST'.gsub(/^ {6}/, '')
57 | require 'autotest/growl'
58 | if RUBY_PLATFORM =~ /-darwin/
59 | begin
60 | require 'autotest/fsevent'
61 | rescue LoadError
62 | puts "== autotest-fsevent gem will improve performance on Mac OS X"
63 | puts "== to use, just: gem install autotest-fsevent"
64 | end
65 | end
66 |
67 | Autotest.add_hook :initialize do |autotest|
68 | %w{.git .svn .hg .DS_Store ._* vendor tmp log doc}.each do |exception|
69 | autotest.add_exception(exception)
70 | end
71 | end
72 | AUTOTEST
73 | end
74 | end
75 |
76 |
--------------------------------------------------------------------------------
/add_user_name.rb:
--------------------------------------------------------------------------------
1 | # >--------------------------------[ add_user_name ]--------------------------------<
2 |
3 | # Application template recipe. Check for a newer version here:
4 | # https://github.com/fortuity/rails-template-recipes/blob/master/add_user_name.rb
5 |
6 | # There is Haml code in this script. Changing the indentation is perilous between HAMLs.
7 |
8 | say_recipe 'add_user_name'
9 |
10 | after_bundler do
11 |
12 | #----------------------------------------------------------------------------
13 | # Add a 'name' attribute to the User model
14 | #----------------------------------------------------------------------------
15 | if recipe_list.include? 'mongoid'
16 | gsub_file 'app/models/user.rb', /end/ do
17 | <<-RUBY
18 | field :name
19 | validates_presence_of :name
20 | validates_uniqueness_of :name, :email, :case_sensitive => false
21 | attr_accessible :name, :email, :password, :password_confirmation, :remember_me
22 | end
23 | RUBY
24 | end
25 | elsif recipe_list.include? 'mongo_mapper'
26 | # Using MongoMapper? Create an issue, suggest some code, and I'll add it
27 | elsif recipe_list.include? 'active_record'
28 | gsub_file 'app/models/user.rb', /end/ do
29 | <<-RUBY
30 | validates_presence_of :name
31 | validates_uniqueness_of :name, :email, :case_sensitive => false
32 | attr_accessible :name, :email, :password, :password_confirmation, :remember_me
33 | end
34 | RUBY
35 | end
36 | else
37 | # Placeholder for some other ORM
38 | end
39 |
40 | if extra_recipes.include? 'git'
41 | git :tag => "add_user_name"
42 | git :add => '.'
43 | git :commit => "-am 'Add a name attribute to the User model.'"
44 | end
45 |
46 | if extra_recipes.include? 'devise'
47 | unless extra_recipes.include? 'haml'
48 | #----------------------------------------------------------------------------
49 | # Generate Devise views (unless you are using Haml)
50 | #----------------------------------------------------------------------------
51 | run 'rails generate devise:views'
52 |
53 | #----------------------------------------------------------------------------
54 | # Modify Devise views to add 'name'
55 | #----------------------------------------------------------------------------
56 | inject_into_file "app/views/devise/registrations/edit.html.erb", :after => "<%= devise_error_messages! %>\n" do
57 | <<-ERB
58 | <%= f.label :name %>
59 | <%= f.text_field :name %>
60 | ERB
61 | end
62 |
63 | inject_into_file "app/views/devise/registrations/new.html.erb", :after => "<%= devise_error_messages! %>\n" do
64 | <<-ERB
65 | <%= f.label :name %>
66 | <%= f.text_field :name %>
67 | ERB
68 | end
69 |
70 | else
71 |
72 | # copy Haml versions of modified Devise views
73 | inside 'app/views/devise/registrations' do
74 | get 'https://github.com/fortuity/rails3-application-templates/raw/master/files/rails3-mongoid-devise/app/views/devise/registrations/edit.html.haml', 'edit.html.haml'
75 | get 'https://github.com/fortuity/rails3-application-templates/raw/master/files/rails3-mongoid-devise/app/views/devise/registrations/new.html.haml', 'new.html.haml'
76 | end
77 |
78 | end
79 |
80 | if extra_recipes.include? 'git'
81 | git :tag => "devise_views"
82 | git :add => '.'
83 | git :commit => "-am 'Generate and modify Devise views.'"
84 | end
85 |
86 | end
87 |
88 | end
89 |
--------------------------------------------------------------------------------
/cucumber.rb:
--------------------------------------------------------------------------------
1 | # >-------------------------------[ Cucumber ]--------------------------------<
2 |
3 | # Application template recipe. Check for a newer version here:
4 | # https://github.com/fortuity/rails-template-recipes/blob/master/cucumber.rb
5 |
6 | # This recipe replaces the RailsWizard standard Cucumber recipe and adds extras.
7 |
8 | if extra_recipes.include? 'cucumber'
9 |
10 | #----------------------------------------------------------------------------
11 | # Use Cucumber for BDD. Include Capybara.
12 | #----------------------------------------------------------------------------
13 |
14 | say_recipe 'Cucumber'
15 |
16 | gem 'cucumber-rails', ">= 0.4.0", :group => :test
17 | gem 'capybara', ">= 0.4.1.2", :group => :test
18 | gem 'relish', ">= 0.2.2", :group => :development
19 |
20 | after_bundler do
21 | generate "cucumber:install --capybara#{' --rspec' if extra_recipes.include?('rspec')}#{' -D' unless recipe_list.include?('activerecord')}"
22 |
23 | # reset your application database to a pristine state during testing
24 | create_file 'features/support/local_env.rb' do
25 | <<-RUBY
26 | require 'database_cleaner'
27 | DatabaseCleaner.strategy = :truncation
28 | DatabaseCleaner.orm = "mongoid"
29 | Before { DatabaseCleaner.clean }
30 | RUBY
31 | end
32 |
33 | # see https://github.com/aslakhellesoy/cucumber-rails/issues/closed/#issue/77
34 | gsub_file 'features/support/env.rb', /require 'cucumber\/rails\/capybara_javascript_emulation'/, "# require 'cucumber/rails/capybara_javascript_emulation'"
35 |
36 | if extra_recipes.include? 'git'
37 | git :tag => "cucumber_installation"
38 | git :add => '.'
39 | git :commit => "-am 'Installed Cucumber.'"
40 | end
41 |
42 | end
43 |
44 | #----------------------------------------------------------------------------
45 | # Add Cucumber scenarios for Devise
46 | #----------------------------------------------------------------------------
47 |
48 | if extra_recipes.include? 'devise'
49 |
50 | say_recipe 'Cucumber Scenarios'
51 |
52 | after_bundler do
53 |
54 | # copy all the Cucumber scenario files from the rails3-mongoid-devise example app
55 | inside 'features/users' do
56 | get 'https://github.com/fortuity/rails3-mongoid-devise/raw/master/features/users/sign_in.feature', 'sign_in.feature'
57 | get 'https://github.com/fortuity/rails3-mongoid-devise/raw/master/features/users/sign_out.feature', 'sign_out.feature'
58 | get 'https://github.com/fortuity/rails3-mongoid-devise/raw/master/features/users/sign_up.feature', 'sign_up.feature'
59 | get 'https://github.com/fortuity/rails3-mongoid-devise/raw/master/features/users/user_edit.feature', 'user_edit.feature'
60 | get 'https://github.com/fortuity/rails3-mongoid-devise/raw/master/features/users/user_show.feature', 'user_show.feature'
61 | end
62 | inside 'features/step_definitions' do
63 | get 'https://github.com/fortuity/rails3-mongoid-devise/raw/master/features/step_definitions/user_steps.rb', 'user_steps.rb'
64 | end
65 | remove_file 'features/support/paths.rb'
66 | inside 'features/support' do
67 | get 'https://github.com/fortuity/rails3-mongoid-devise/raw/master/features/support/paths.rb', 'paths.rb'
68 | end
69 |
70 | if extra_recipes.include? 'git'
71 | git :tag => 'cucumber_scenarios'
72 | git :add => '.'
73 | git :commit => "-am 'Installed Cucumber Scenarios for Devise.'"
74 | end
75 |
76 | end
77 |
78 | end
79 |
80 | end
--------------------------------------------------------------------------------
/users_page.rb:
--------------------------------------------------------------------------------
1 | # >--------------------------------[ users_page ]--------------------------------<
2 |
3 | # Application template recipe. Check for a newer version here:
4 | # https://github.com/fortuity/rails-template-recipes/blob/master/users_page.rb
5 |
6 | # There is Haml code in this script. Changing the indentation is perilous between HAMLs.
7 |
8 | say_recipe 'Users Page'
9 |
10 | after_bundler do
11 |
12 | if extra_recipes.include? 'devise'
13 |
14 | #----------------------------------------------------------------------------
15 | # Create a users controller
16 | #----------------------------------------------------------------------------
17 | generate(:controller, "users show")
18 | gsub_file 'app/controllers/users_controller.rb', /def show/ do
19 | <<-RUBY
20 | before_filter :authenticate_user!
21 |
22 | def show
23 | @user = User.find(params[:id])
24 | RUBY
25 | end
26 |
27 | #----------------------------------------------------------------------------
28 | # Modify the routes
29 | #----------------------------------------------------------------------------
30 | # @devise_for :users@ route must be placed above @resources :users, :only => :show@.
31 | gsub_file 'config/routes.rb', /get \"users\/show\"/, '#get \"users\/show\"'
32 | gsub_file 'config/routes.rb', /devise_for :users/ do
33 | <<-RUBY
34 | devise_for :users
35 | resources :users, :only => :show
36 | RUBY
37 | end
38 |
39 | #----------------------------------------------------------------------------
40 | # Create a users show page
41 | #----------------------------------------------------------------------------
42 | if recipe_list.include? 'haml'
43 | remove_file 'app/views/users/show.html.haml'
44 | # we have to use single-quote-style-heredoc to avoid interpolation
45 | create_file 'app/views/users/show.html.haml' do <<-'HAML'
46 | %p
47 | User: #{@user.name}
48 | HAML
49 | end
50 | else
51 | append_file 'app/views/users/show.html.erb' do <<-ERB
52 | User: <%= @user.name %>
53 | ERB
54 | end
55 | end
56 |
57 | #----------------------------------------------------------------------------
58 | # Create a home page containing links to user show pages
59 | # (clobbers code from the home_page_users recipe)
60 | #----------------------------------------------------------------------------
61 | # set up the controller
62 | remove_file 'app/controllers/home_controller.rb'
63 | create_file 'app/controllers/home_controller.rb' do
64 | <<-RUBY
65 | class HomeController < ApplicationController
66 | def index
67 | @users = User.all
68 | end
69 | end
70 | RUBY
71 | end
72 |
73 | # modify the home page
74 | if recipe_list.include? 'haml'
75 | remove_file 'app/views/home/index.html.haml'
76 | # we have to use single-quote-style-heredoc to avoid interpolation
77 | create_file 'app/views/home/index.html.haml' do
78 | <<-'HAML'
79 | %h3 Home
80 | - @users.each do |user|
81 | %p User: #{link_to user.name, user}
82 | HAML
83 | end
84 | else
85 | remove_file 'app/views/home/index.html.erb'
86 | create_file 'app/views/home/index.html.erb' do <<-ERB
87 | Home
88 | <% @users.each do |user| %>
89 | User: <%=link_to user.name, user %>
90 | <% end %>
91 | ERB
92 | end
93 | end
94 |
95 | end
96 |
97 | if extra_recipes.include? 'git'
98 | git :tag => "users_page"
99 | git :add => '.'
100 | git :commit => "-am 'Add a users controller and user show page with links from the home page.'"
101 | end
102 |
103 | end
--------------------------------------------------------------------------------
/README.textile:
--------------------------------------------------------------------------------
1 | h1. UPDATE
2 |
3 | This project is no longer active or useful. It was developed for an older version of "RailsWizard":http://railswizard.org/.
4 |
5 | Use the "rails3_devise_wizard":https://github.com/fortuity/rails3_devise_wizard instead.
6 |
7 | h1. Rails-Template-Recipes
8 |
9 | This is a collection of Ruby scripts ("recipes") used to create custom application templates.
10 |
11 | h4. Build Custom Application Templates
12 |
13 | Application templates are often used to generate a Rails 3 "starter" or "skeleton" app that can be the basis for many projects.
14 |
15 | Here's an example of an application template for a starter app that was assembled from these recipes:
16 |
17 | * "rails3-mongoid-devise application template":https://github.com/fortuity/rails3-application-templates/blob/master/rails3-mongoid-devise-template.rb
18 |
19 | h4. Or Use RailsWizard
20 |
21 | "RailsWizard":http://railswizard.org/ is a website you can visit to create application templates that are used to generate a Rails 3 web application. RailsWizard might not have all the ingredients or customizations you want for your Rails app. This is a collection of extra recipes that you can add to the RailsWizard mix.
22 |
23 | h4. Inspired By
24 |
25 | This project was inspired by "fnichol/rails-template-recipes":https://github.com/fnichol/rails-template-recipes.
26 |
27 | h2. Related Projects
28 |
29 | Here's a tutorial that shows how an example application is built from a combination of recipes:
30 |
31 | * "Tutorial for rails3-mongoid-devise":http://github.com/fortuity/rails3-mongoid-devise/wiki/Tutorial-%28Walkthrough%29
32 |
33 | Here are finished application templates that are assembled from recipes:
34 |
35 | * "rails3-application-templates":https://github.com/fortuity/rails3-application-templates
36 |
37 | You can see an example application that was created from the recipes:
38 |
39 | * "rails3-mongoid-devise":http://github.com/fortuity/rails3-mongoid-devise/
40 |
41 | h2. A Little More Explanation
42 |
43 | Rails has a command that looks like this:
44 |
45 | @$ rails new app_name -m /path/to/application-template.rb@
46 |
47 | which generates a new Rails application and customizes it according to a script defined in the *application-template.rb* file.
48 |
49 | You can create an *application-template.rb* file yourself or use one that someone else has written. Or you can visit "http://railswizard.org/":http://railswizard.org/, select various ingredients from a menu, add recipes from this repository, and programmatically generate a new application template.
50 |
51 | h2. Recipes for General Use
52 |
53 | |_. File |_. |_. Dependencies |_. Authors |
54 | | "action_mailer.rb":https://github.com/fortuity/rails-template-recipes/blob/master/action_mailer.rb | Changes ActionMailer defaults | none | dkehoe |
55 | | "ban_spiders.rb":https://github.com/fortuity/rails-template-recipes/blob/master/ban_spiders.rb | Ban spiders from your site by changing robots.txt | none | dkehoe |
56 | | "cleanup.rb":https://github.com/fortuity/rails-template-recipes/blob/master/cleanup.rb | Remove unnecessary files, add READMEs | none | fnichol, dkehoe |
57 | | "git.rb":https://github.com/fortuity/rails-template-recipes/blob/master/git.rb | Add a gitignore file, initialize new Git repo | Git | fnichol, dkehoe |
58 | | "gitignore.txt":https://github.com/fortuity/rails-template-recipes/blob/master/gitignore.txt | The mother of all gitignore files | Git | various |
59 | | "irb.rb":https://github.com/fortuity/rails-template-recipes/blob/master/irb.rb | Add gems for wirble, awesome_print, interactive_editor | none | fnichol |
60 | | "rake_init_tasks.rb":https://github.com/fortuity/rails-template-recipes/blob/master/rake_init_tasks.rb | Adds rake init:* tasks | ActiveRecord | fnichol |
61 | | "rvm.rb":https://github.com/fortuity/rails-template-recipes/blob/master/rvm.rb | Sets up an rvm gemset | rvm | fnichol |
62 | | "sample_readme.textile":https://github.com/fortuity/rails-template-recipes/blob/master/sample_readme.textile | Placeholder text for a README file (textile markup) | none | dkehoe |
63 | | "sample_readme.txt":https://github.com/fortuity/rails-template-recipes/blob/master/sample_readme.txt | Placeholder text for a README file (ASCII) | none | dkehoe |
64 | | "yard.rb":https://github.com/fortuity/rails-template-recipes/blob/master/yard.rb | Replaces RDoc with Yard for documentation | none | rbrooker |
65 |
66 | h2. Recipes for Testing and BDD
67 |
68 | |_. File |_. |_. Dependencies |_. Authors |
69 | | "autotest.rb":https://github.com/fortuity/rails-template-recipes/blob/master/autotest.rb | Adds Autotest | none | fnichol |
70 | | "rspec.rb":https://github.com/fortuity/rails-template-recipes/blob/master/rspec.rb | Replacement for the RailsWizard RSpec recipe (adds extras) | none | rbrooker, dkehoe |
71 | | "rspec_extras.rb":https://github.com/fortuity/rails-template-recipes/blob/master/rspec_extras.rb | Changes .rspec file for customized formatting | RSpec | fnichol |
72 | | "cucumber.rb":https://github.com/fortuity/rails-template-recipes/blob/master/cucumber.rb | Replacement for the RailsWizard Cucumber recipe (adds extras) | none | rbrooker, dkehoe |
73 | | "cucumber_extras.rb":https://github.com/fortuity/rails-template-recipes/blob/master/cucumber_extras.rb | adds extras | Cucumber | fnichol |
74 |
75 | h2. Recipes for ActiveRecord
76 |
77 | |_. File |_. |_. Dependencies |_. Authors |
78 | | "activerecord_extras.rb":https://github.com/fortuity/rails-template-recipes/blob/master/activerecord_extras.rb | Adds gems for sqlite3, mysql, jruby | ActiveRecord | fnichol |
79 | | "exclude_database_yaml.rb":https://github.com/fortuity/rails-template-recipes/blob/master/exclude_database_yaml.rb | Exclude database.yml from version control | ActiveRecord | fnichol |
80 |
81 | h2. Recipes for Mongoid
82 |
83 | |_. File |_. |_. Dependencies |_. Authors |
84 | | "bson_ext.rb":https://github.com/fortuity/rails-template-recipes/blob/master/bson_ext.rb | Add bson_ext gem for use with Mongoid | Mongoid | dkehoe |
85 | | "mongoid_cleanup.rb":https://github.com/fortuity/rails-template-recipes/blob/master/mongoid_cleanup.rb | Updates the RailsWizard Mongoid recipe for a newer Mongoid, etc.| Mongoid | dkehoe |
86 |
87 | h2. Recipes to Fix RailsWizard
88 |
89 | |_. File |_. |_. Dependencies |_. Authors |
90 | | "devise.rb":https://github.com/fortuity/rails-template-recipes/blob/master/devise.rb | Replacement for the RailsWizard standard Devise recipe | none | dkehoe |
91 | | "jquery.rb":https://github.com/fortuity/rails-template-recipes/blob/master/jquery_fix.rb | Replacement for the RailsWizard jQuery recipe | none | dkehoe |
92 | | "jquery_fix.rb":https://github.com/fortuity/rails-template-recipes/blob/master/jquery_fix.rb | Repairs an error in the RailsWizard jQuery recipe | jQuery | dkehoe |
93 |
94 | h2. Recipes for Deployment
95 |
96 | |_. File |_. |_. Dependencies |_. Authors |
97 | | "capistrano_lastmile.rb":https://github.com/fortuity/rails-template-recipes/blob/master/capistrano_lastmile.rb | Adds gems for Capistrano and lastmile | none | fnichol |
98 | | "heroku.rb":https://github.com/fortuity/rails-template-recipes/blob/master/heroku.rb | Add a Heroku gem and ignore file | none | dkehoe |
99 |
100 | h2. Recipes for the Application Layout
101 |
102 | |_. File |_. |_. Dependencies |_. Authors |
103 | | "application_layout.rb":https://github.com/fortuity/rails-template-recipes/blob/master/application_layout.rb | Adds application layout with flash messages | ERB or Haml | dkehoe |
104 | | "css_setup.rb":https://github.com/fortuity/rails-template-recipes/blob/master/css_setup.rb | Add a stylesheet with styles for a horizontal menu and flash messages | none | dkehoe |
105 | | "flashes_partial.erb.rb":https://github.com/fortuity/rails-template-recipes/blob/master/flashes_partial.erb.rb | Add a flashes partial (for ERB) | ERB | fnichol |
106 | | "flashes_partial.haml.rb":https://github.com/fortuity/rails-template-recipes/blob/master/flashes_partial.haml.rb | Add a flashes partial (for Haml) | Haml | fnichol |
107 |
108 | h2. Recipes for the Rails3-Mongoid-Devise Example App
109 |
110 | |_. File |_. |_. Dependencies |_. Authors |
111 | | "add_user_name.rb":https://github.com/fortuity/rails-template-recipes/blob/master/add_user_name.rb | adds name to User, generates Devise views | User model, Devise | dkehoe |
112 | | "devise_navigation.rb":https://github.com/fortuity/rails-template-recipes/blob/master/devise_navigation.rb | Add navigation links to the default application layout | Devise | dkehoe |
113 | | "home_page.rb":https://github.com/fortuity/rails-template-recipes/blob/master/home_page.rb | Create a home controller, route, and simple view | ERB or Haml | dkehoe |
114 | | "home_page_users.rb":https://github.com/fortuity/rails-template-recipes/blob/master/home_page_users.rb | Modify a home page to display a list of users | Home controller, User model, ERB or Haml | dkehoe |
115 | | "seed_database.rb":https://github.com/fortuity/rails-template-recipes/blob/master/seed_database.rb | Adds a db/seeds.rb file with a default user | Mongoid, User model | dkehoe |
116 | | "users_page.rb":https://github.com/fortuity/rails-template-recipes/blob/master/users_page.rb | Add a home page containing links to User pages | User model, ERB or Haml | dkehoe |
117 |
118 | h2. Dependencies
119 |
120 | Before generating a new Rails app using an application template, you will need:
121 |
122 | * The Ruby language (version 1.8.7 or 1.9.2)
123 | * Rails (version 3.0.4 or newer)
124 |
125 | bq. You MUST be using Rails 3.0.4 or newer. Generating a Rails application from an "HTTPS" URL does not work in Rails 3.0.3 and earlier versions.
126 |
127 | I recommend installing rvm, the "Ruby Version Manager":http://rvm.beginrescueend.com/, to manage multiple versions of Rails.
128 |
129 | If you are using rvm, you can see a list of the Ruby versions currently installed:
130 | @$ rvm list@
131 |
132 | Check that appropriate versions of Ruby and Rails are installed in your development environment:
133 | @$ ruby -v@
134 | @$ rails -v@
135 |
136 | h2. RailsWizard Usage Examples
137 |
138 | Add the following to the *Customize Template* section at "http://railswizard.org/":http://railswizard.org/.
139 |
140 | The array @extra_recipes@ should be a list of filenames from this repository (without the *.rb* extension).
141 |
142 | h4. Simple Example
143 |
144 | Using the cleanup and ban_spiders recipes as a simple example.
145 |
146 |
147 | git_repo = "https://github.com/fortuity/rails-template-recipes"
148 | @recipe_list = recipes ; def recipe_list; @recipe_list end
149 | def extra_recipes; @extra_recipes end
150 | @extra_recipes = %w{ cleanup ban_spiders }
151 | @extra_recipes.each { |r| apply "#{git_repo}/raw/master/#{r}.rb" }
152 |
153 |
154 | h4. Rails3-Mongoid-Devise Example
155 |
156 | Here's a complex example that generates the complete "rails3-mongoid-devise":https://github.com/fortuity/rails3-mongoid-devise example application as described in the "tutorial":http://github.com/fortuity/rails3-mongoid-devise/wiki/Tutorial-%28Walkthrough%29.
157 |
158 | Use the RailsWizard graphical menu to select Mongoid, Haml, and a CSS framework. Do NOT select RSpec, Cucumber, jQuery, or Devise from the RailsWizard graphical menu.
159 |
160 |
161 | git_repo = "https://github.com/fortuity/rails-template-recipes"
162 | @recipe_list = recipes ; def recipe_list; @recipe_list end
163 | def extra_recipes; @extra_recipes end
164 | @extra_recipes = %w{ git rspec cucumber jquery devise
165 | bson_ext mongoid_cleanup
166 | action_mailer add_user_name
167 | home_page home_page_users seed_database users_page
168 | css_setup application_layout devise_navigation
169 | cleanup ban_spiders }
170 | @extra_recipes.each { |r| apply "#{git_repo}/raw/master/#{r}.rb" }
171 |
172 |
173 | h2. How It Works
174 |
175 | Rails generators can use any methods provided by the "Thor::Actions":http://rdoc.info/github/wycats/thor/master/Thor/Actions module. The flexibility of mixing "recipes" for application templates comes from use of the @apply@ method from the Thor::Actions module. Given a web address or a local filepath, the "apply method":http://rdoc.info/github/wycats/thor/master/Thor/Actions#apply-instance_method loads and executes a file within the context of the generator script.
176 |
177 | h2. Documentation and Support
178 |
179 | This is the only documentation.
180 |
181 | h4. Writing Recipes
182 |
183 | To understand the code in these templates, take a look at "Thor::Actions":http://rdoc.info/github/wycats/thor/master/Thor/Actions. Your recipes can use any methods provided by "Thor::Actions":http://rdoc.info/github/wycats/thor/master/Thor/Actions or "Rails::Generators::Actions":http://railsapi.com/doc/rails-v3.0.3/classes/Rails/Generators/Actions.html.
184 |
185 | Please send a message (via GitHub) or a "pull request" if you've written recipes you'd like to contribute.
186 |
187 | h4. About Rails Application Templates
188 |
189 | "Cooking Up A Custom Rails 3 Template (11 Oct 2010) by Andrea Singh":http://blog.madebydna.com/all/code/2010/10/11/cooking-up-a-custom-rails3-template.html
190 | "Rails Application Templates (16 Sept 2010) by Collin Schaafsma":http://quickleft.com/blog/rails-application-templates
191 | "Application templates in Rails 3 (18 Sept 2009) by Ben Scofield":http://benscofield.com/2009/09/application-templates-in-rails-3/
192 | "Railscasts: App Templates in Rails 2.3 (9 Feb 2009) by Ryan Bates":http://railscasts.com/episodes/148-app-templates-in-rails-2-3
193 | "Rails templates (4 Dec 2008) by Pratik Naik":http://m.onkey.org/rails-templates
194 |
195 | h4. Issues
196 |
197 | Any issues? Please create an "Issue":http://github.com/fortuity/rails3-application-templates/issues on GitHub.
198 |
199 | h2. Contributing
200 |
201 | If you make improvements to these templates, please share with others.
202 |
203 | * Fork the project on GitHub.
204 | * Make your feature addition or bug fix.
205 | * Commit with Git.
206 | * Send the author a pull request.
207 |
208 | If you start a project that is similar, please contact me and I'll add a note to the README so that others can find your work.
209 |
210 | h2. Credits
211 |
212 | Are the templates useful to you? Follow me on Twitter:
213 | "http://twitter.com/railsinit":http://twitter.com/railsinit
214 | and tweet some praise. I'd love to know you were helped out by what I've put together.
215 |
216 | This project was inspired by "Fletcher Nichol's":http://silversky.ca/ "fnichol/rails-template-recipes":https://github.com/fnichol/rails-template-recipes.
217 |
218 | Template recipes by Daniel Kehoe ("http://danielkehoe.com/":http://danielkehoe.com/) (some based on recipes by Fletcher Nichol).
219 |
220 | Additional recipes contributed by "Ramon Brooker":http://cogniton-mind.tumblr.com/ (RSpec, Cucumber, Yard).
221 |
222 | h2. License
223 |
224 | h4. Public Domain Dedication
225 |
226 | This work is a compilation and derivation from other previously released works. With the exception of various included works, which may be restricted by other licenses, the author or authors of this code dedicate any and all copyright interest in this code to the public domain. We make this dedication for the benefit of the public at large and to the detriment of our heirs and successors. We intend this dedication to be an overt act of relinquishment in perpetuity of all present and future rights to this code under copyright law.
227 |
--------------------------------------------------------------------------------