Created
October 3, 2012 00:51
-
-
Save prabirshrestha/3824265 to your computer and use it in GitHub Desktop.
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
| public static void RegisterBundles(BundleCollection bundles) | |
| { | |
| bundles.Add(new ScriptBundle("~/Scripts/jquery") | |
| .Include("~/assets/javascripts/vendors/jquery-{version}.js")); | |
| bundles.Add(new ScriptBundle("~/Scripts/app") | |
| .IncludeFromSprocketFile("~/assets/javascripts/main.js")); | |
| var templateBundle = new Bundle("~/Scripts/templates").IncludeDirectory("~/assets/templates", "*.html"); | |
| templateBundle.Transforms.Add(new HtmlBundleTransform()); | |
| bundles.Add(templateBundle); | |
| } |
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
| public class Global : System.Web.HttpApplication | |
| { | |
| protected void Application_Start(object sender, EventArgs e) | |
| { | |
| BundleConfig.RegisterBundles(BundleTable.Bundles); | |
| } | |
| } |
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
| public class HtmlBundleTransform : IBundleTransform | |
| { | |
| private readonly string javascriptVariableName; | |
| public HtmlBundleTransform() | |
| : this("JST") | |
| { | |
| } | |
| public HtmlBundleTransform(string javascriptVariableName) | |
| { | |
| this.javascriptVariableName = javascriptVariableName; | |
| } | |
| public void Process(BundleContext context, BundleResponse response) | |
| { | |
| var sb = new StringBuilder(); | |
| sb.AppendFormat("window.{0} = window.{0} || {{}};", this.javascriptVariableName); | |
| foreach (var file in response.Files) | |
| sb.AppendFormat("{0}['{1}'] = \"{2}\";", this.javascriptVariableName, Path.GetFileName(file.FullName), File.ReadAllText(file.FullName)); | |
| response.Content = sb.ToString(); | |
| response.ContentType = "text/javascript"; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment