Created
March 5, 2012 09:52
-
-
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)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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