Skip to content

Instantly share code, notes, and snippets.

@krutten
Forked from ilpoldo/templator.rb
Created January 7, 2011 18:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save krutten/769930 to your computer and use it in GitHub Desktop.
Save krutten/769930 to your computer and use it in GitHub Desktop.
# Cleaning up and extending the Gemfile
remove_file 'Gemfile'
create_file 'Gemfile', <<-GEMFILE
source 'http://rubygems.org'
gem 'rails', '3.0.0'
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
gem 'sqlite3-ruby', :require => 'sqlite3'
gem 'pg', :group => :production
gem 'haml', '~> 3.0.12'
gem 'compass', '~> 0.10.4'
gem 'jsmin'
gem 'warden'
group :production, :test, :cucumber, :development do
# gem 'aws-s3'
# gem 'paperclip'
gem 'cancan'
end
group :test, :cucumber, :development do
gem 'factory_girl_rails', '~> 1.0.0'
gem 'factory_girl_generator'
gem 'haml-rails'
gem 'connie'
end
group :test, :cucumber do
gem 'capybara', '>= 0.3.8'
gem 'capybara-envjs'
gem 'cucumber-rails', '>= 0.3.2'
gem 'pickle', '>= 0.3.4'
gem 'database_cleaner', '>= 0.5.2'
gem 'launchy', '~> 0.3.5'
gem 'rspec-rails', '~> 2.0.0.beta.12'
gem 'fredo'
gem 'ruby-debug'
# gem 'spork', '>= 0.8.4'
end
group :development do
gem 'wirble'
gem 'awesome_print'
# gem 'slowgrowl'
end
GEMFILE
# Initializers and loading
application 'config.autoload_paths += %W(#{config.root}/lib)'
create_file 'config/secrets.yml', <<-SECRETS
# Environment secrets
S3_KEY: somekey
S3_SECRET: somesecret
S3_BUCKET: my-own-bucket
SECRETS
File.open('config/environment.rb', 'r+') do |env|
environment = env.read
env.pos = 0
secrets = <<-ENVIRONMENT
# Load the environment variables
unless ENV['RACK_ENV'] == 'production'
begin
YAML.load_file(File.expand_path('secrets.yml', File.dirname(__FILE__))).each do |key, value|
ENV[key] = value
end
rescue
raise "Error loading secrets configuration, please edit config/secrets.yml"
end
end
ENVIRONMENT
env << secrets
env << environment
end
# Routes
route "get '/javascripts/:bundle.js' => JavascriptMinifier"
route "get '/stylesheets/:media.:ext' => SassCompiler"
# Generators
application <<-GENERATORS
config.generators do |g|
g.template_engine :haml
g.test_framework :rspec, :fixture => true, :views => false
g.integration_tool :cucumber
g.fixture_replacement :factory_girl, :dir => "spec/factories"
end
GENERATORS
# A good way to reach your own generators
# empty_directory 'lib/generators'
# git :clone => "--depth 0 http://github.com/leshill/rails3-app.git lib/generators"
# remove_dir 'lib/generators/.git'
# remove_file 'lib/generators/app.rb'
# Middleware
application <<-MIDDLEWARE
# config.middleware.use Warden::Manager do |manager|
# manager.default_strategies :sign_in
# manager.failure_app = SessionsController.action(:unauthorized)
# manager.serialize_into_session {|user| user.id}
# manager.serialize_from_session {|id| User.find(id)}
# end
# config.middleware.delete 'Sass::Plugin::Rack'
MIDDLEWARE
# Javascript
get "http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js", "public/javascripts/common/base/jquery.js"
get "http://github.com/DmitryBaranovskiy/raphael/raw/master/raphael-min.js", "public/javascripts/common/base/raphael.js"
get "http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.1/jquery-ui.min.js", "public/javascripts/common/plugins/jquery-ui.js"
get "http://github.com/rails/jquery-ujs/raw/master/src/rails.js", "public/javascripts/common/plugins/rails.js"
get "http://github.com/ilpoldo/goverlay/raw/master/goverlay.js", "public/javascripts/common/plugins/goverlay.js"
remove_file 'public/javascripts/application.js'
create_file "public/javascripts/common/application.js", <<-APPLICATIONJS
var app = {
setupAjaxCallbacks: function () {
$('body').ajaxStart(function () {
});
$('body').ajaxStop(function () {
});
$('body').ajaxError(function (event, xhr, ajaxOptions, thrownError) {
console.log({event:event,response:xhr});
});
}
};
$(document).ready(function(){
jQuery.goverlay(30,10,18);
// Just to warm up my js:
(function(test_paragraph){
test_paragraph.append(test_paragraph.attr("data-message"));
})($('p[data-function=jstest]'));
});
APPLICATIONJS
# Css
create_file 'public/stylesheets/ie.scss', <<-IECSS
@import "blueprint";
// To generate css equivalent to the blueprint css but with your configuration applied, uncomment:
// +blueprint-ie
//Recommended Blueprint configuration with scoping and semantic layout:
body.bp {
@include blueprint-ie(true);
// Note: Blueprint centers text to fix IE6 container centering.
// This means all your texts will be centered under all version of IE by default.
// If your container does not have the .container class, don't forget to restore
// the correct behavior to your main container (but not the body tag!)
// Example:
// .my-container
// text-align: left
}
IECSS
create_file 'public/stylesheets/print.scss', <<-PRINTCSS
@import "blueprint";
//Recommended Blueprint configuration with scoping and semantic layout:
body.bp {
@include blueprint-print(true); }
PRINTCSS
create_file 'public/stylesheets/screen.scss', <<-SCREENCSS
// This import applies a global reset to any page that imports this stylesheet.
@import "blueprint/reset";
// To configure blueprint, edit the partials/base.sass file.
@import "partials/base";
// Import all the default blueprint modules so that we can access their mixins.
@import "blueprint";
// Combine the partials into a single screen stylesheet.
@import "partials/page";
@import "compass/css3";
body{
margin: 0;
#container{
@include container;
}
}
SCREENCSS
create_file 'public/stylesheets/partials/_page.scss', <<-PAGECSS
// Import the non-default scaffolding module to help us get started.
@import "blueprint/scaffolding";
// This configuration will only apply the
// blueprint styles to pages with a body class of "bp"
// This makes it easier to have pages without blueprint styles
// when you're using a single/combined stylesheet.
body {
@include blueprint-typography(true);
@include blueprint-utilities;
@include blueprint-debug;
@include blueprint-interaction; }
// Remove the scaffolding when you're ready to start doing visual design.
// Or leave it in if you're happy with how blueprint looks out-of-the-box
@include blueprint-scaffolding("#container");
form {
@include blueprint-form; }
PAGECSS
create_file 'public/stylesheets/partials/_base.scss', <<-BASECSS
// Here is where you can define your constants for your application and to configure the blueprint framework.
// Feel free to delete these if you want keep the defaults:
$blueprint-grid-columns: 24;
$blueprint-container-size: 950px;
$blueprint-grid-margin: 10px;
$separator-witdh: 1px;
// Use this to calculate the width based on the total width.
// Or you can set !blueprint_grid_width to a fixed value and unset !blueprint_container_size -- it will be calculated for you.
$blueprint-grid-width: ($blueprint-container-size + $blueprint-grid-margin) / $blueprint-grid-columns - $blueprint-grid-margin;
BASECSS
#Asset Packagers
get "http://gist.github.com/raw/326616/javascript_minifier.rb", "lib/javascript_minifier.rb"
get "http://gist.github.com/raw/326616/sass_compiler.rb", "lib/sass_compiler.rb"
# Haml
remove_file "app/views/layouts/application.html.erb"
create_file "app/views/layouts/application.html.haml", <<-LAYOUT
!!!
%html
%head
%title== #{yield :title}#{app_name.humanize}
%meta{:"http-equiv" => "Content-Type", :content => "text/html;charset=utf-8" }/
%meta{:name => "description", :content => "#{app_name.humanize}" }
= stylesheet_link_tag 'screen.css', :media => 'screen, projection'
/[if lt IE 8]
= stylesheet_link_tag 'ie.css', :media => 'screen, projection'
= javascript_include_tag 'common.js'
= csrf_meta_tag
%body
= yield
LAYOUT
# Assets cleanup
remove_file "README"
remove_file "LICENSE"
remove_file "public/index.html"
remove_file "public/favicon.ico"
remove_file "public/robots.txt"
remove_file "public/images/rails.png"
readme = <<-README
=#{app_name.humanize}
=== A Rails 3 application
== Copyright
Copyright (c) #{Time.now.year} Leandro Pedroni. See LICENSE for details.
README
create_file "README.md", readme
# how do I output errors from the bundle install??
run 'bundle install --without production'
# After the app responds
rake "db:migrate"
rake "secret"
generate "rspec:install"
generate "cucumber:install --rspec --capybara"
generate "pickle --paths --email"
# Git
gitignore = <<-GITIGNORE
.bundle
db/*.sqlite3
log/*.log
tmp/**/*
.DS_Store
**/.DS_Store
db/schema.rb
config/secrets.yml
vendor/cache/*
GITIGNORE
remove_file '.gitignore'
create_file '.gitignore', gitignore
git :init
git :add => "."
git :commit => "-a -m 'Initial Commit'"
# Print documentation
docs = <<-DOCS
Good luck developing #{app_name.humanize}!
DOCS
log docs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment