Created
March 9, 2011 23:56
-
-
Save clm-a/863277 to your computer and use it in GitHub Desktop.
rails new myapp -J -m https://gist.github.com/raw/863277/rails3-template-with-devise-compass-and-friends.rb
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
# Find me at https://gist.github.com/863277 | |
# Run me with "rails new myapp -J -m https://gist.github.com/raw/863277/rails3-template-with-devise-compass-and-friends.rb" | |
# You should visit | |
# http://everydayrails.com/2011/02/28/rails-3-application-templates.html | |
# http://railswizard.org | |
# http://stackoverflow.com/questions/4999207/rails-3-application-templates | |
# https://github.com/fnichol/rails-template-recipes | |
# for some inspiration about application templates. | |
# twitter.com/@clmntlxndr | |
# create rvmrc file | |
run "gem install rvm --no-ri --no-rdoc" | |
require 'rvm' | |
create_file ".rvmrc", "rvm 1.9.2@#{app_name}" | |
RVM.gemset_create "#{app_name}" | |
RVM.gemset_use! app_name | |
run "rvm rvmrc trust" | |
run "gem install bundler --no-ri --no-rdoc" | |
gem "jquery-rails" | |
gem "simple_form" | |
gem "nifty-generators", :group => :development | |
gem "compass", :group => :development | |
def bundle_install | |
if yes?("Local bundle install?") | |
run "bundle install --local" | |
else | |
run "bundle install" | |
end | |
end | |
if yes?("Install Devise?") | |
gem("devise") | |
bundle_install | |
model_name = ask("Model name? [user]") | |
model_name = "user" if model_name.blank? | |
generate("devise:install") | |
generate("devise", model_name) | |
inject_into_file 'config/environments/development.rb', :before => "# Only use best-standards-support built into browsers" do | |
"config.action_mailer.default_url_options = { :host => 'localhost:3000' }" | |
end | |
else | |
bundle_install | |
end | |
rake "db:create", :env => 'development' | |
rake "db:sessions:create", :env => 'development' | |
gsub_file "config/initializers/session_store.rb", /Application\.config\.session_store :cookie_store, :key => '_.*_session'/, "Application.config.session_store :active_record_store" | |
remove_file 'app/views/layouts/application.html.erb' # use nifty layout instead | |
generate 'nifty:layout' | |
inject_into_file 'app/views/layouts/application.html.erb', :before => "<%= javascript_include_tag :defaults %>" do | |
<<-COMPASS | |
<%= stylesheet_link_tag 'compiled/screen.css', :media => 'screen, projection' %> | |
<%= stylesheet_link_tag 'compiled/print.css', :media => 'print' %> | |
<!--[if IE]> | |
<link rel="stylesheet" href="compiled/ie.css" media="screen, projection" /> | |
<![endif]--> | |
COMPASS | |
end | |
generate 'nifty:config' | |
generate 'simple_form:install' | |
run "compass init rails ." | |
require 'compass' | |
require 'compass/exec' | |
command_line_class = Compass::Exec::Helpers.select_appropriate_command_line_ui(%w{init rails .}) | |
command_line_class.new(%w{init rails .}).run! | |
inject_into_file 'config/initializers/compass.rb', :before => %Q|require 'compass'| do | |
%Q|if Rails.env.development? | |
| | |
end | |
inject_into_file 'config/initializers/compass.rb', :after => %Q|Compass::AppIntegration::Rails.initialize!| do | |
%Q| | |
end | |
| | |
end | |
inject_into_file 'app/stylesheets/screen.scss', :after => %Q|@import "compass/reset";| do | |
%Q|\n@import "/stylesheets/application.css"; | |
@import "/stylesheets/simple_form.css" | |
| | |
end | |
gsub_file "app/views/layouts/application.html.erb", /<%= stylesheet_link_tag "application" %>/, "" | |
generate 'jquery:install' | |
gsub_file "config/application.rb", /# JavaScript.*\n/, "" | |
gsub_file "config/application.rb", /#?\s?config\.action_view\.javascript.*\n/, "" | |
application do | |
"\nconfig.action_view.javascript_expansions[:defaults] = %w{jquery rails}" | |
end | |
inject_into_file 'config/application.rb', :after => "config.filter_parameters += [:password]" do | |
<<-eos | |
# Customize generators | |
config.generators do |g| | |
g.stylesheets false | |
g.form_builder :simple_form | |
end | |
eos | |
end | |
inject_into_file 'app/controllers/application_controller.rb', :after => "protect_from_forgery" do | |
<<-eos | |
def home | |
render :text => "Welcome home!", :layout => "application" | |
end | |
eos | |
end | |
create_file "public/stylesheets/simple_form.css" do | |
<<-eos | |
.simple_form label { | |
float: left; | |
width: 100px; | |
text-align: right; | |
margin: 2px 10px; | |
} | |
.simple_form div.input { | |
margin-bottom: 10px; | |
} | |
.simple_form div.boolean, .simple_form input[type='submit'] { | |
margin-left: 120px; | |
} | |
.simple_form div.boolean label { | |
float: none; | |
margin: 0; | |
} | |
eos | |
end | |
gsub_file "config/routes.rb", /# root :to => "welcome#index"/, %Q|root :to => "application#home"| | |
gsub_file "app/stylesheets/screen.scss", /@import "compass\/reset";/, %Q|// @import "compass/reset";| | |
# clean up rails defaults | |
remove_file 'public/index.html' | |
remove_file 'public/images/rails.png' | |
if yes?("Migrate now ?") | |
rake "db:migrate" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment