Skip to content

Instantly share code, notes, and snippets.

@znake
Created April 1, 2012 09:31
Show Gist options
  • Save znake/2274099 to your computer and use it in GitHub Desktop.
Save znake/2274099 to your computer and use it in GitHub Desktop.
Watch Rakefile for HAML
# Save this file as rakefile.rb in your folder
# within your .haml files.
# Start watching with
# $ rake
include Rake::DSL
require 'rake/clean'
task :default => [:watch]
desc 'Watches all the .haml files in your directory and changes them to html'
task :watch do
puts "HAML is watchin you!"
require 'fssm'
FSSM.monitor do
path "#{File.dirname(__FILE__)}" do
glob '**/*.{haml}'
update {|base, relative| rebuild_haml(relative)}
delete {|base, relative| rebuild_haml(relative)}
create {|base, relative| rebuild_haml(relative)}
end
end
end
def rebuild_haml(relative)
puts "HAML changes found in: #{relative}! Invoking HAML --->"
html = relative.sub( "haml", "html")
sh "haml #{relative} #{html}"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment