Skip to content

Instantly share code, notes, and snippets.

@sofer
Created July 1, 2010 16:43
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sofer/460217 to your computer and use it in GitHub Desktop.
Save sofer/460217 to your computer and use it in GitHub Desktop.
# Rails 3 application template
# Usage: rails new app -JOT -m http://gist.github.com/460217.txt
# where J=no Prototype, O=no ActiveRecord, T=no TestUnit
# see http://mongoid.org/docs/installation/
# see also http://asciicasts.com/episodes/201-bundler
# see also http://github.com/josevalim/inherited_resources
# see also http://github.com/plataformatec/devise
# see also http://github.com/indirect/rails3-generators
mongo = yes? "Run MongoDB?"
haml = yes? "Use haml?"
jqtouch = yes? "Install jQTouch files?"
#devise = yes? "Install devise?"
devise = false # broken under rails 3.0.0.beta4
app = yes? "Create outline app"
# remove unwanted files
remove_file "public/index.html"
remove_file "public/images/rails.png"
# add config.generators block
inject_into_class "config/application.rb", "Application" do <<GEN
config.generators do |g|
end
GEN
end
if mongo
gem "mongoid", ">=2.0.0.beta7"
gem "bson_ext", "1.0.1"
inject_into_file "config/application.rb", "\n g.orm :mongoid", :after => " config.generators do |g|"
end
if jqtouch
# add minimal jQTouch files
git :clone => "https://sofer@github.com/sofer/jqtouch-files.git"
run "cp -r jqtouch-files/* ."
run "rm -rf jqtouch-files"
# add Safari-specific metatag
inject_into_file "app/views/layouts/application.html.erb", :after => "<html>" do
%Q|\n<meta name = "viewport" content = "width=device-width; initial-scale=1.0; maximum-scale=1.0; user-scalable=no;">|
end
# add manifest directive
inject_into_file "app/views/layouts/application.html.erb", ' manifest = "cache.manifest"', :after => "<html"
# change javascript
js_files = %Q|"jquery.js", "jqtouch.js", "data.js", "application.js", "jqt-init.js"|
gsub_file "app/views/layouts/application.html.erb", ":defaults", js_files
inject_into_file "app/views/layouts/application.html.erb", ' manifest = "cache.manifest"', :after => "<html"
# create initializer
create_file "config/initializers/html5_cache.rb" do <<CODE
# turn off asset caching, to allow files to be cached
ENV['RAILS_ASSET_ID'] = ''
CODE
end
end
if haml
gem "haml"
# add the generator
inject_into_file "config/application.rb", "\n g.template_engine :haml", :after => " config.generators do |g|"
end
if app
# outline studylists app
generate "controller Home index"
route "root :to => 'home#index'"
# create home/index
create_file "app/views/home/index.html.haml" do <<VIEW
nothing here yet
VIEW
end
# copy the application files
end
gem "inherited_resources"
gem "rails3-generators", :git => "http://github.com/indirect/rails3-generators.git"
gem "devise", "1.1.rc1" if devise
apply "~/code/rails_templates/end.rb"
run "bundle install --relock"
generate "mongoid:config" if mongo
if haml
run "html2haml app/views/layouts/application.html.erb >> app/views/layouts/application.html.haml"
remove_file "app/views/layouts/application.html.erb"
end
if devise
generate :devise_install
generate :devise, "User"
end
say "I still need to copy the home/index files and the application.js file as well as adding the application data (currently in data.js). Vary this according to need." if app
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment