Skip to content

Instantly share code, notes, and snippets.

@RickCarlino
Created September 21, 2012 15:49
Show Gist options
  • Save RickCarlino/3762274 to your computer and use it in GitHub Desktop.
Save RickCarlino/3762274 to your computer and use it in GitHub Desktop.
inline coffeescript in HAML with :coffee and on-the-fly compilation
# inline coffeescript for haml with on-the-fly compilation
# run this script in the directory of your project
require 'fssm'
#required for using inline :coffee tag with HAML-
require 'coffee-filter'
directory = File.dirname(__FILE__)
FSSM.monitor(directory, '**/*') do
update do |base, relative|
if relative.match(/.coffee\z/)
input = "#{base}/#{relative}"
output = "#{base}/#{relative.gsub!('.coffee', '.js')}"
command = "coffee -c #{input}"
%x{#{command}}
puts "[COFFEE] Regenerated #{input} to #{output}"
elsif relative.match(/.haml\z/)
input = "#{base}/#{relative}"
output = "#{base}/#{relative.gsub!('.haml', '')}"
command = "haml -r coffee-filter #{input} #{output}"
%x{#{command}}
puts "[HAML] Regenerated #{input} to #{output}"
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment