Haml and Sass Rakefile

Here is a rakefile I cooked up for generating a website form static haml and sass files.

require 'haml/engine'
require 'sass/engine'

task :default => [:web]
task :web => [:haml,:sass]

desc 'Compile haml templates to html'
task :haml do
dirs = Dir['**/*.haml']
dirs.each do |f|
File.open(f, 'r') do |fi|
File.open(f.gsub('haml','html'),'w') do |d|
d << Haml::Engine.new(fi.read).to_html
end
end
end
end

desc 'Compile sass templates to css'
task :sass do
dirs = Dir['**/*.sass']
dirs.each do |f|
File.open(f, 'r') do |fi|
File.open(f.gsub('sass','css'),'w') do |d|
d << Sass::Engine.new(fi.read).to_css
end
end
end
end

published 2007-05-27

Questions or Feedback? Email ryan@ryantm.com or tweet @ryantm.