Skip to content

Instantly share code, notes, and snippets.

@RickCarlino
Forked from gcorreaq/haml-watch.rb
Created September 21, 2012 15:47
Show Gist options
  • Save RickCarlino/3762267 to your computer and use it in GitHub Desktop.
Save RickCarlino/3762267 to your computer and use it in GitHub Desktop.
Watch and compile all haml files on a directory, like sass --watch
#!/usr/bin/env ruby
# Script to watch a directory for any changes to a haml file
# and compile it.
#
# USAGE: ruby haml_watch.rb <directory_to_watch> [output_directory]
#
# Blake Smith / http://blakesmith.github.com/2010/09/05/haml-directory-watcher.html
#
require 'rubygems'
require 'fssm'
from_path = ARGV[0] || "src"
to_path = ARGV[1] || "bin"
dir = File.join(File.dirname(__FILE__), from_path)
FSSM.monitor(dir, '**/*.haml') do
update do |base, relative|
input = File.join(base, relative)
output = File.join(File.dirname(base), to_path, relative.gsub!('.haml', '.html'))
command = "haml #{input} #{output} -f xhtml -t ugly -q --no-escape-attrs"
%x{#{command}}
puts <<-eos
HTML gerado #{Time.now.strftime("%Y/%m/%d %H:%M")}:
- from: #{input}
- to: #{output}
eos
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment