Created
October 21, 2011 19:24
-
-
Save wbzyl/1304698 to your computer and use it in GitHub Desktop.
Application template file for Rails 3.1+
This file contains hidden or 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
# Template file for Rails 3.1+ | |
# | |
# TODO: | |
# see README.md for additional information. | |
def ask_wizard(text) | |
ask "\033[36m" + "wizard".rjust(10) + "\033[0m" + " #{text}" | |
end | |
remove_file 'public/index.html' | |
remove_file 'README' | |
create_file 'README.md' do | |
'# My Awesome Rails 3.1 App\n\nTODO' | |
end | |
# Sass stuff | |
gem 'sass' | |
gem 'bourbon' # a set of Sass mixins using SCSS syntax, https://github.com/thoughtbot/bourbon | |
inside('app/assets/stylesheets/') do | |
remove_file 'application.css' | |
create_file 'layout.css.scss' do | |
color = ask_wizard("Gimme your preferred CSS background color: ") | |
<<-LAYOUT.gsub(/^\s{6}/, '') | |
$html-background-color: #{color}; | |
/* | |
==|== layout primary styles ================================================= | |
Author: | |
========================================================================== | |
*/ | |
html { | |
background: $html-background-color; | |
} | |
// http://www.smashingmagazine.com/2011/10/07/16-pixels-body-copy-anything-less-costly-mistake/ */ | |
body { | |
font-size: 18px; | |
line-height: 1.5; | |
} | |
// width 600px approx. 60 characters per line | |
div[role="main"] { | |
width: 598px; | |
margin: 0 auto 18px; | |
padding: 2px 18px 18px 18px; | |
border: 1px solid black; | |
background: white; | |
} | |
header { | |
width: 600px; | |
margin: 0 auto; | |
padding: 18px; | |
background-color: darken($html-background-color, 40%); | |
color: #FFF; | |
h1 { | |
font-size: 140%; | |
} | |
} | |
LAYOUT | |
end | |
get "https://github.com/paulirish/html5-boilerplate/raw/master/css/style.css", "preamble.css.scss" | |
gsub_file "preamble.css.scss", /\n\/\* ==\|== primary styles.*/m, "" | |
get "https://github.com/paulirish/html5-boilerplate/raw/master/css/style.css", "postamble.css.scss" | |
gsub_file "postamble.css.scss", /\A.*\/* ==\|== media queries/m, "/* ==|== media queries" | |
create_file 'application.css.scss' do | |
<<-APP.gsub(/^\s{6}/, '') | |
/* | |
*= require_self | |
*/ | |
@import "bourbon"; | |
@import "preamble.css.scss"; | |
@import "layout.css.scss"; | |
@import "postamble.css.scss"; | |
APP | |
end | |
end | |
# Create application.html.erb with content of the HTML5 Boilerplate index.html | |
inside('app/views/layouts') do | |
remove_file 'application.html.erb' | |
get "https://raw.github.com/paulirish/html5-boilerplate/master/index.html", "application.html.erb" | |
# TODO: ask_wizard for app name | |
gsub_file 'application.html.erb', /<title>/ do | |
"<title><%= content_for?(:title) ? yield(:title) : \"Rails 3.1 App\" %>" | |
end | |
gsub_file 'application.html.erb', /<link rel="stylesheet" href="css\/style.css">/ do | |
"<%= stylesheet_link_tag \"application\" %>" | |
end | |
gsub_file 'application.html.erb', /<script src=.*<\/script>/ do | |
"<%= javascript_include_tag \"application\" %>" + "\n <%= csrf_meta_tags %>" | |
end | |
gsub_file 'application.html.erb', /<header>/ do | |
"<header>\n <%= content_tag :h1, \"Rails 3.1 App\" %>" | |
end | |
gsub_file 'application.html.erb', /role=\"main\">/ do | |
"role=\"main\">\n" + | |
" <%= content_tag :h1, yield(:title) if show_title? %>" + | |
" <%= yield %>\n" | |
end | |
gsub_file 'application.html.erb', /<\/footer>.*<!-- Asynchronous Google/m do | |
"</footer>\n\n <!-- Asynchronous Google" | |
end | |
end | |
# Layout helpers form 'nifty-generators' | |
inside('app/helpers') do | |
create_file 'layout_helper.rb' do | |
<<-LAYOUT_HELPER.gsub(/^\s{4}/, "") | |
# This module should be included in all views globally, | |
# to do so you may need to add this line to your ApplicationController | |
# helper :layout | |
module LayoutHelper | |
def title(page_title, show_title = true) | |
content_for(:title) { page_title.to_s } | |
@show_title = show_title | |
end | |
def show_title? | |
@show_title | |
end | |
end | |
LAYOUT_HELPER | |
end | |
end | |
# TODO: | |
# save modernizr.js in vendor/assets/javascripts | |
# https://raw.github.com/Modernizr/Modernizr/master/modernizr.js | |
# then add the following to your application.js manifest: | |
# //= require modernizr | |
# CoffeeScript | |
gem 'coffee-script' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage: