Created
December 27, 2011 14:08
-
-
Save matenia/1523761 to your computer and use it in GitHub Desktop.
Rails 3.1 template
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Standard Init Script for New Custom Rails 3.1.3 app | |
RailsVersion = "3.1.3" | |
instructions =<<-END | |
Running Standard Init Script for Rails 3.1.3 | |
-------------------------------------------------- | |
During installation a number of questions will arise and | |
some other information is required such as: | |
- Google Analytics tracking code e.g UA-XXXXXX-XX | |
This can be found on your Google Analytics settings page. | |
-------------------------------------------------- | |
END | |
say(instructions) | |
############################################################ | |
# Remove unnecessary Rails files and improve gitignore | |
# | |
# ReadME first development :) | |
run 'rm README' | |
file "README.md", <<-END | |
#{app_name.titleize} | |
=========================== | |
END | |
git :init | |
git :add => "README.md" | |
git :commit => "-m 'Fix up the README'" | |
# Improve the Gitignore | |
append_file ".gitignore", "\nconfig/database.yml" | |
append_file ".gitignore", "\n.rvmrc" | |
append_file ".gitignore", "\n.rspec" | |
append_file ".gitignore", "\nvendor/bundle" | |
append_file ".gitignore", "\n.DS_Store" | |
git :add => ".gitignore" | |
git :commit => "-m 'Ignore a few more files'" | |
# Remove the other static files | |
run 'rm Gemfile' | |
run 'rm public/index.html' | |
run 'rm app/assets/images/rails.png' | |
# Add the base system | |
git :add => "." | |
git :commit => "-a -m 'Initial commit of custom Rails #{RailsVersion} App'" | |
############################################################ | |
# Setup Gemfile and RVM | |
# | |
file "Gemfile", <<-END | |
source :rubygems | |
gem "rails", "#{RailsVersion}" | |
gem 'sqlite3', :group => :development | |
gem 'mysql2', :group => :production | |
gem 'json' | |
# Gems used only for assets and not required | |
# in production environments by default. | |
group :assets do | |
gem 'sass-rails', '~> 3.1.5' | |
gem 'coffee-rails', '~> 3.1.1' | |
gem 'uglifier', '>= 1.0.3' | |
gem 'compass', '~> 0.12.alpha.3' | |
gem 'compass_twitter_bootstrap' | |
end | |
gem 'jquery-rails' | |
gem 'haml-rails' | |
gem 'sitemap_generator' | |
gem 'simple-navigation' | |
gem 'capistrano' | |
gem 'capistrano-ext' | |
gem 'carrierwave' | |
gem 'therubyracer' | |
gem 'friendly_id' | |
gem 'yaml_db' | |
gem 'devise' | |
gem 'kaminari' | |
gem 'rmagick', :require => false | |
gem 'mercury-rails', :git => 'git://github.com/jejacks0n/mercury.git' | |
group :test,:development do | |
gem 'rspec-rails' | |
end | |
group :test do | |
gem 'factory_girl_rails' | |
gem 'capybara' | |
gem 'guard-rspec' | |
end | |
group :production do | |
gem 'hoptoad_notifier' | |
gem 'newrelic_rpm' | |
end | |
END | |
run 'echo "rvm use 1.8.7-p174" > .rvmrc' | |
# Bundle install | |
say("gemfile generation complete - now installing stuff") | |
run "bundle install" | |
git :add => "." | |
git :commit => "-a -m 'Gemset created and bundle installed'" | |
# Create the DB for sqlite3 | |
rake("db:migrate") | |
git :add => "." | |
git :commit => "-a -m 'Setup Database'" | |
# Remove test folder | |
# | |
git :rm => "-rf test" | |
git :commit => "-am 'Removing test folder'" | |
############################################################ | |
# Generate RSpec and Cucumber | |
# | |
# Setup RSpec and Cucumber | |
generate "rspec:install" | |
git :add => "." | |
git :commit => "-a -m 'Installed RSpec'" | |
############################################################ | |
# Setup base home controller and my/dashboard | |
# | |
# Setup home and dashboard | |
generate 'controller', 'welcome' | |
route("root :to => 'welcome#index'") | |
file 'app/views/welcome/index.html.haml', <<-END | |
= content_for :title, "#{app_name.titleize}" | |
%p dummy home page | |
END | |
git :add => "." | |
git :commit => "-a -m 'Setup home controller and mapped root'" | |
# get modernizr javascript | |
run 'curl https://raw.github.com/Modernizr/Modernizr/master/modernizr.js > app/assets/javascripts/modernizr.js' | |
say('adding layout helper ... ') | |
file 'app/helpers/layout_helper.rb' <<-END | |
module LayoutHelper | |
def flash_classes(c) | |
{ | |
:warning => 'warning', | |
:alert => 'error', | |
:notice => 'success', | |
:message => 'info' | |
}[c.try(:to_sym) || :message] | |
end | |
end | |
END | |
# replace html page with haml | |
run 'rm app/views/layouts/application.html.erb' | |
file 'app/views/layouts/application.html.haml', <<-END | |
!!! | |
%html | |
%head | |
%title= yield(:title).present? ? yield(:title) : '#{app_name.titleize}' | |
= stylesheet_link_tag '#{app_name.underscore.dasherize}' | |
= javascript_include_tag 'modernizr' | |
= javascript_include_tag '#{app_name.underscore.dasherize}' | |
= yield(:domready) | |
= csrf_meta_tags | |
%body{:class => controller_name} | |
.topbar | |
.fill | |
.container | |
= link_to #{app_name.titleize}, root_url, :class => 'brand' | |
%ul.nav | |
%li= link_to "Home" | |
%li= link_to "About" | |
%li= link_to "Contact" | |
%form{ :action=>'', :class => 'pull-right'} | |
%input{:class => 'input small', :type => 'text', :placeholder => 'search site'} | |
%button{:class => 'btn', :type=>'submit'} Search | |
.container | |
.row | |
.span12 | |
%h2= yield(:title).present? ? yield(:title) : '#{app_name.titleize}' | |
.row | |
.span12 | |
- flash.each do |name,msg| | |
= content_tag :div, :id => "flash_\#{name}", :class => "alert-message \#{flash_classes(name)}", :data => {:alert => 'alert'} do | |
= link_to 'x', '#', :class => 'close' | |
= msg | |
= yield | |
.span4 | |
%h3 Sidebar | |
%p Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. | |
%footer | |
%p © #{app_name.titleize} 2011 | |
END | |
### set up javascript and stylesheets | |
say("Setting up Javascripts and Stylesheets") | |
file "app/assets/stylesheets/#{app_name.underscore.dasherize}.css.scss", <<-END | |
@import 'compass'; | |
@import 'compass_twitter_bootstrap'; | |
body {padding-top:60px;} | |
END | |
file "app/assets/javascripts/#{app_name.underscore.dasherize}.js", <<-END | |
//= require jquery | |
//= require jquery_ujs | |
//= require bootstrap-buttons | |
//= require bootstrap-alerts | |
//= require bootstrap-dropdown | |
//= require bootstrap-modal | |
//= require bootstrap-twipsy | |
//= require bootstrap-popover | |
//= require bootstrap-scrollspy | |
//= require bootstrap-tabs | |
END | |
############################################################ | |
# Setup Additional Gems | |
# | |
say('setting up additional gems ...') | |
#setup friendly_id | |
if ask("Setup Friendly_ID? (N/y)").upcase == 'Y' | |
generate "friendly_id" | |
git :add => "." | |
git :commit => "-a -m 'Setup friendly_id'" | |
else | |
say "=> Skipping Friendly_ID setup" | |
end | |
# install compass | |
run 'compass init rails .' | |
file 'config/compass.rb', <<-END | |
# This configuration file works with both the Compass command line tool and within Rails. | |
# Require any additional compass plugins here. | |
project_type = :rails | |
# Set this to the root of your project when deployed: | |
http_path = "/" | |
require 'compass_twitter_bootstrap' | |
# You can select your preferred output style here (can be overridden via the command line): | |
# output_style = :expanded or :nested or :compact or :compressed | |
# To enable relative paths to assets via compass helper functions. Uncomment: | |
# relative_assets = true | |
# To disable debugging comments that display the original location of your selectors. Uncomment: | |
if Rails.env.production? | |
output_style = :compressed | |
line_comments = false | |
end | |
# line_comments = false | |
# If you prefer the indented syntax, you might want to regenerate this | |
# project again passing --syntax sass, or you can uncomment this: | |
# preferred_syntax = :sass | |
# and then run: | |
# sass-convert -R --from scss --to sass app/stylesheets scss && rm -rf sass && mv scss sass | |
END | |
#setup mercury-rails | |
generate 'mercury:install' | |
rake 'mercury_engine:install:migrations' | |
rake "db:migrate" | |
############################################################ | |
# Setup Google Analytics | |
if ask("Do you have Google Analytics key? (N/y)").upcase == 'Y' | |
ga_key = ask("Please provide your Google Analytics tracking key: (e.g UA-XXXXXX-XX)") | |
else | |
ga_key = nil | |
end | |
file "app/views/shared/_google_analytics.html.erb", <<-CODE | |
<script type="text/javascript" charset="utf-8"> | |
var _gaq = _gaq || []; | |
_gaq.push(['_setAccount', '#{ga_key || "INSERT-URCHIN-CODE"}']); | |
_gaq.push(['_trackPageview']); | |
(function() { | |
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; | |
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; | |
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); | |
})(); | |
</script> | |
CODE | |
if ga_key | |
append_file "app/views/layouts/application.html.haml", <<-CODE | |
= render :partial => 'shared/google_analytics' | |
CODE | |
else | |
append_file "app/views/layouts/application.html.haml", <<-CODE | |
-#= render :partial => 'shared/google_analytics' | |
CODE | |
end | |
git :add => "." | |
git :commit => "-am 'Added Google Analytics tracking code'" | |
# kaminari | |
say('Install Kaminari') | |
generate 'kaminari:config' | |
# navigation | |
say('Setting up simple-navigation') | |
generate 'navigation_config' | |
# capistrano | |
say('Lets setup Capistrano for awesome deployment!') | |
if ask('Setup Capistrano? (N/y)').upcase == 'Y' | |
run 'capify .' | |
if ask('With asset pipeline? (N/y)').upcase == 'Y' | |
gsub_file 'Capfile', "# load 'deploy/assets'", "load 'deploy/assets'" | |
else | |
say('Asset pipeline not configured') | |
end | |
else | |
say "Skipping Capistrano - bummer!" | |
end | |
# Setup Devise | |
if ask("Setup Devise for Admin? (N/y)").upcase == 'Y' | |
generate "devise:install" | |
model_name = ask("What model name should devise use? (default: admin)?") | |
model_name = 'admin' if model_name.blank? | |
generate "devise", model_name | |
generate 'devise:views' | |
file Dir.glob('db/migrate/*').last, <<-END | |
class Dir.glob('db/migrate/*.rb').last.split('/').last.gsub(/\d|.rb/,'').gsub('_',' ').strip.titleize.gsub(' ','') < ActiveRecord::Migration | |
def self.up | |
create_table(:#{model_name.tableize}) do |t| | |
t.database_authenticatable :null => false | |
t.rememberable | |
t.trackable | |
t.timestamps | |
end | |
add_index :#{model_name.tableize}, :email, :unique => true | |
end | |
def self.down | |
drop_table :#{model_name.tableize} | |
end | |
end | |
END | |
run "rm app/models/#{model_name}.rb" | |
file "app/models/#{model_name}.rb" <<-END | |
class #{model_name.classify} < ActiveRecord::Base | |
devise :database_authenticatable, :rememberable, :trackable, :timeoutable | |
attr_accessible :email, :password, :remember_me | |
end | |
END | |
git :add => "." | |
git :commit => "-a -m 'Setup devise'" | |
else | |
say "=> Skipping Devise setup" | |
end | |
instructions =<<-END | |
Rails Template Install Complete | |
-------------------------------- | |
All complete, please configure: | |
initializers/devise.rb | |
Also setup actionmailer in your production and development environments. | |
config.action_mailer.default_url_options = { :host => 'localhost:3000' } # dev + test | |
config.action_mailer.default_url_options = { :host => '#{app_name}.com' } # production | |
If capistrano was set up, please update the following file with your settings | |
config/deploy.rb | |
END | |
say(instructions) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Still a work in progress, but this gets me started on a fresh rails 3.1.3 app with twitter bootstrap! (Saves about an hour of stuffing around :D )