Skip to content

Instantly share code, notes, and snippets.

@liammclennan
Created March 5, 2012 09:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save liammclennan/1977676 to your computer and use it in GitHub Desktop.
Save liammclennan/1977676 to your computer and use it in GitHub Desktop.
A file system watching template compiler for packaging client-side templates (uses underscore.js templates)
require 'fileutils'
watch( '.*\.*tmpl.html' ) do |md|
puts "detected change to #{md[0]}"
compile_html '*tmpl.html', 'App.Templates', 'src/client/js/lib/templates.coffee'
end
def compile_html(file_pattern, namespace, output_file)
markup = ''
Dir["**/#{file_pattern}"].each do |file|
markup += "#{namespace}.#{File.basename(file, '.html')} = _.template(\"\"\"\n" + IO.read(file) + "\n\"\"\")\n\n"
end
File.open(output_file, "w") { |f| f << markup }
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment