Skip to content

Instantly share code, notes, and snippets.

@fin
Created July 17, 2011 23:02
Show Gist options
  • Save fin/1088202 to your computer and use it in GitHub Desktop.
Save fin/1088202 to your computer and use it in GitHub Desktop.
haml directory watcher
#!/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