Created
May 19, 2015 17:03
-
-
Save ahmetkizilay/d0564351f91a0af08ff6 to your computer and use it in GitHub Desktop.
compiling handlebars with rake
This file contains hidden or 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
task :handlebars => :environment do | |
puts "Compiling Handlebars templates" | |
files = Rake::FileList["app/assets/javascripts/templates/**/*.hbs"] | |
compiled_js = "" | |
files.each do |file| | |
openFile = File.open(file) | |
pathName = openFile.to_path.sub("app/assets/javascripts/templates/", "")[0...-4] | |
content = openFile.read | |
compiled = HandlebarsAssets::Handlebars.precompile(content, HandlebarsAssets::Config.options) | |
compiled_js += "(function() {\nthis.HandlebarsTemplates || (this.HandlebarsTemplates = {});\nthis.HandlebarsTemplates[\"" + pathName + "\"] = Handlebars.template(" + compiled + ");\n}).call(this);\n\n\n" | |
end | |
output = File.new("app/assets/javascripts/templates/compiled.js", "w") | |
output.puts(compiled_js) | |
output.close | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment