Skip to content

Instantly share code, notes, and snippets.

@royratcliffe
Created March 18, 2011 11:36
Show Gist options
  • Save royratcliffe/875920 to your computer and use it in GitHub Desktop.
Save royratcliffe/875920 to your computer and use it in GitHub Desktop.
namespace :haml do
# Monitor the current directory looking for changes to Haml source files and
# compile on updates. Defaults to watching the current directory. You can
# override by specifying another directory in square brackets immediately
# after the watch target, e.g.
#
# rake haml:watch[/tmp]
#
# Note, you need the FSSM gem installing, i.e. gem install fssm. Of course,
# you also need Haml itself.
desc "Look for changes to Haml source files and compile on update"
task :watch, [:directory] do |t, args|
args.with_defaults(:directory => Dir.getwd)
puts "Watching #{args.directory}"
require 'fssm'
FSSM.monitor do
path args.directory do
glob '**/*.haml'
update do |base, relative|
relative_base = Pathname.new(base).relative_path_from(Pathname.new(Dir.getwd)).to_s
sh "haml \"#{File.join(relative_base, relative)}\" \"#{File.join(relative_base, relative.chomp(File.extname(relative)))}\""
end
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment