-
-
Save CosAnca/7d1544fa44c24c709728f6856b700963 to your computer and use it in GitHub Desktop.
Revisions
-
mariusschulz revised this gist
Oct 25, 2015 . 1 changed file with 3 additions and 4 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -17,20 +17,19 @@ public static IHtmlString InlineStyles(this HtmlHelper htmlHelper, string bundle private static IHtmlString InlineBundle(this HtmlHelper htmlHelper, string bundleVirtualPath, string htmlTagName) { string bundleContent = LoadBundleContent(htmlHelper.ViewContext.HttpContext, bundleVirtualPath); string htmlTag = string.Format("<{0}>{1}</{0}>", htmlTagName, bundleContent); return new HtmlString(htmlTag); } private static string LoadBundleContent(HttpContextBase httpContext, string bundleVirtualPath) { var bundleContext = new BundleContext(httpContext, BundleTable.Bundles, bundleVirtualPath); var bundle = BundleTable.Bundles.Single(b => b.Path == bundleVirtualPath); var bundleResponse = bundle.GenerateBundleResponse(bundleContext); return bundleResponse.Content; } } -
mariusschulz revised this gist
Oct 25, 2015 . No changes.There are no files selected for viewing
-
mariusschulz revised this gist
Oct 25, 2015 . No changes.There are no files selected for viewing
-
mariusschulz renamed this gist
Oct 25, 2015 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
mariusschulz revised this gist
Oct 25, 2015 . 1 changed file with 12 additions and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,12 @@ <!doctype html> <html lang="en"> <head> <title>Title</title> @Html.InlineStyles("~/some/path/to/a/bundle.css") </head> <body> @RenderBody() @Html.InlineScripts("~/some/path/to/a/bundle.js") </body> </html> -
mariusschulz created this gist
Oct 25, 2015 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,36 @@ using System.Linq; using System.Web; using System.Web.Mvc; using System.Web.Optimization; public static class HtmlHelperExtensions { public static IHtmlString InlineScripts(this HtmlHelper htmlHelper, string bundleVirtualPath) { return htmlHelper.InlineBundle(bundleVirtualPath, htmlTagName: "script"); } public static IHtmlString InlineStyles(this HtmlHelper htmlHelper, string bundleVirtualPath) { return htmlHelper.InlineBundle(bundleVirtualPath, htmlTagName: "style"); } private static IHtmlString InlineBundle(this HtmlHelper htmlHelper, string bundleVirtualPath, string htmlTagName) { string bundleContent = htmlHelper.LoadBundleContent(bundleVirtualPath); string htmlTag = string.Format("<{0}>{1}</{0}>", htmlTagName, bundleContent); return new HtmlString(htmlTag); } private static string LoadBundleContent(this HtmlHelper htmlHelper, string bundleVirtualPath) { var httpContext = htmlHelper.ViewContext.HttpContext; var bundleContext = new BundleContext(httpContext, BundleTable.Bundles, bundleVirtualPath); var bundle = BundleTable.Bundles.Single(b => b.Path == bundleVirtualPath); var bundleResponse = bundle.GenerateBundleResponse(bundleContext); return bundleResponse.Content; } }