public void Process(BundleContext context, BundleResponse response) { var compiler = new HandlebarsCompiler(); var templates = new Dictionary<string, string>(); var server = context.HttpContext.Server; foreach (var bundleFile in response.Files) { var filePath = server.MapPath(bundleFile.VirtualFile.VirtualPath); var bundleRelativePath = GetRelativePath(server, bundleFile, filePath); var templateName = namer.GenerateName(bundleRelativePath, bundleFile.VirtualFile.Name); var template = File.ReadAllText(filePath); var compiled = compiler.Precompile(template, false); templates[templateName] = compiled; } StringBuilder javascript = new StringBuilder(); foreach (var templateName in templates.Keys) { javascript.AppendFormat("Ember.TEMPLATES['{0}']=", templateName); javascript.AppendFormat("Ember.Handlebars.template({0});", templates[templateName]); } var Compressor = new JavaScriptCompressor(); var compressed = Compressor.Compress(javascript.ToString()); response.ContentType = "text/javascript"; response.Cacheability = HttpCacheability.Public; response.Content = compressed; }
public void Process(BundleContext context, BundleResponse response) { var compiler = new HandlebarsCompiler(); var templates = new Dictionary <string, string>(); var server = context.HttpContext.Server; foreach (var bundleFile in response.Files) { var filePath = server.MapPath(bundleFile.VirtualFile.VirtualPath); var bundleRelativePath = GetRelativePath(server, bundleFile, filePath); var templateName = namer.GenerateName(bundleRelativePath, bundleFile.VirtualFile.Name); var template = File.ReadAllText(filePath); var compiled = compiler.Precompile(template, false); templates[templateName] = compiled; } StringBuilder javascript = new StringBuilder(); foreach (var templateName in templates.Keys) { javascript.AppendFormat("Ember.TEMPLATES['{0}']=", templateName); javascript.AppendFormat("Ember.Handlebars.template({0});", templates[templateName]); } var Compressor = new JavaScriptCompressor(); var compressed = Compressor.Compress(javascript.ToString()); response.ContentType = "text/javascript"; response.Cacheability = HttpCacheability.Public; response.Content = compressed; }
public void TestCompiler() { //lazy test var hc = new HandlebarsCompiler(); var template = hc.Precompile("asdf {{asdf}}", false); Assert.IsNotNull(template); Assert.IsTrue(template.IndexOf("asdf") > 0); }