Created
January 21, 2013 19:57
-
-
Save listrophy/4588790 to your computer and use it in GitHub Desktop.
Rakefile + watchr script for asset compilation (kinda specialized for http://restaurantweekmap.com)
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
watch( '(data|haml|sass|coffee|js)/*' ) {|md| puts 'running `rake compile`...'; system('rake compile') } |
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
require 'yaml' | |
require 'active_support/core_ext/object' | |
desc 'Compile all the things' | |
task :compile => 'compile:all' | |
SASS_FILES = FileList['sass/*.{sass,scss}'] | |
COFFEE_FILES = FileList['coffee/*.coffee'] | |
JS_FILES = COFFEE_FILES.pathmap('tmp/js/%n.js') | |
ALL_JS = %w(js/strict.js | |
js/zepto.js | |
js/doT.js | |
js/restaurants.js | |
tmp/js/infoWindow.js | |
tmp/js/app.js | |
) | |
HAML_FILES = FileList['haml/*.haml'] | |
HTML_FILES = HAML_FILES.pathmap('%n.html') | |
RESTAURANT_FILES = FileList['data/restaurants/*.yml'] | |
directory 'tmp/js' | |
namespace :compile do | |
task :all => ['site.css', 'site.js', :html] | |
file 'site.css' => SASS_FILES do | |
sh 'sass sass/application.scss site.css' | |
end | |
file 'site.js' => ['js/semicolon.js'] + ALL_JS do | |
sh "cat #{ALL_JS.join(' js/semicolon.js ')} > site.js" | |
end | |
file 'js/restaurants.js' => RESTAURANT_FILES do | |
yml = RESTAURANT_FILES.to_a.map do |fname| | |
{ | |
basename: File.basename(fname, '.yml'), | |
data: YAML::load_file(fname) | |
} | |
end | |
puts 'compiling restaurants' | |
File.open('js/restaurants.js', 'w') do |f| | |
f.puts "window.restaurants = #{yml.to_json};" | |
end | |
end | |
file 'js/zepto.js' => 'vendor/zepto/dist/zepto.js' do | |
FileUtils.cp('vendor/zepto/dist/zepto.js', 'js/zepto.js') | |
end | |
namespace :zepto do | |
file 'vendor/zepto/dist/zepto.js' => 'vendor/zepto/.git' do | |
sh 'cd vendor/zepto; rake concat[-ajax:-form:selector:touch]' | |
end | |
file 'vendor/zepto/.git' do | |
sh 'cd vendor; git clone git://github.com/madrobby/zepto' | |
end | |
end | |
JS_FILES.zip(COFFEE_FILES).each do |target, source| | |
file target => ['tmp/js', source] do | |
sh "coffee -b -p -c #{source} > #{target}" | |
end | |
end | |
task :coffee => JS_FILES | |
HTML_FILES.zip(HAML_FILES).each do |target, source| | |
file target => source do | |
sh "haml #{source} #{target}" | |
end | |
end | |
task :html => HTML_FILES | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment