Created
July 17, 2011 23:02
-
-
Save fin/1088202 to your computer and use it in GitHub Desktop.
haml directory watcher
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
#!/usr/bin/ruby1.8 | |
# Script to watch a directory for any changes to a haml file | |
# and compile it. | |
# | |
# USAGE: ruby haml_watch.rb <directory_to_watch> | |
# | |
# Original by Blake Smith / http://blakesmith.github.com/2010/09/05/haml-directory-watcher.html | |
# Modifications by fin / http://fin.io | |
# | |
require 'rubygems' | |
require 'fssm' | |
require 'haml' | |
directory = ARGV.first | |
FSSM.monitor(directory, '**/*.haml') do | |
update do |base, relative| | |
input = open("#{base}/#{relative}").read | |
output = open("#{base}/#{relative.gsub!('.haml', '.html')}", 'w') | |
output.write(Haml::Engine.new(input).render) | |
output.close | |
puts "Regenerated #{input} to #{output}" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment