Skip to content

Instantly share code, notes, and snippets.

@okkez
Created January 6, 2012 07:42
Show Gist options
  • Save okkez/1569552 to your computer and use it in GitHub Desktop.
Save okkez/1569552 to your computer and use it in GitHub Desktop.
A sample of generating HTML with haml.
require 'haml'
require 'rake/clean'
SRC = FileList["haml/*.haml"].exclude("haml/layout.haml")
TARGET = SRC.ext(".html")
CLEAN.push(TARGET.sub("haml/", "html/"))
rule ".html" => ".haml" do |t|
engine = Haml::Engine.new(File.read('haml/layout.haml'))
scope = Object.new
output = engine.render(scope, :title => t.source.ext("")){
e = Haml::Engine.new(File.read(t.source))
e.render(scope)
}
File.open(t.name, "w+") do |file|
file.puts output
end
end
desc "generate html files"
task :html => TARGET do |t|
mkdir_p "html"
mv t.prerequisites, "html/"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment