Skip to content

Instantly share code, notes, and snippets.

@eivindingebrigtsen
Created April 11, 2011 07:22
Show Gist options
  • Save eivindingebrigtsen/913185 to your computer and use it in GitHub Desktop.
Save eivindingebrigtsen/913185 to your computer and use it in GitHub Desktop.
make mustache templates into a javascript object
desc "make mustache templates"
task :mustache do
src = 'window.templates = {';
length = Dir[PATH+'/*.mustache'].length;
Dir[PATH+'/*.mustache'].each do |f|
file = File.open(f, 'rb').read();
file.gsub!(/\n|\r|\t|\s\s/, '')
src += '"'+File.basename(f).gsub(/\.mustache/, '')+ '"' + " : '" + file + "',";
end
src += '"done":true};';
File.open('js/src/templates.js', 'wb'){|io| io.write(src) }
puts "Saved " + length.to_s + ' templates'
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment