Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added media parameter for css bundling in html link creation

  • Loading branch information...
commit 5391f7f3c940123323a8ce5808a59ba7100aac7e 1 parent cda7ac6
@phillip-haydon phillip-haydon authored
View
51 NuGet/content/Mvc.Bundler.cs
@@ -252,38 +252,39 @@ public static MvcHtmlString RenderJsBundle(this HtmlHelper html, string bundlePa
});
}
- public static MvcHtmlString RenderCssBundle(this HtmlHelper html, string bundlePath, BundleOptions options = BundleOptions.Minified)
- {
- if (string.IsNullOrEmpty(bundlePath))
- return MvcHtmlString.Empty;
+ public static MvcHtmlString RenderCssBundle(this HtmlHelper html, string bundlePath, BundleOptions options = BundleOptions.Minified, string media = null)
+ {
+ if (string.IsNullOrEmpty(bundlePath))
+ return MvcHtmlString.Empty;
- if (!CachePaths()) BundleCache.SafeClear();
+ if (!CachePaths()) BundleCache.SafeClear();
- return BundleCache.GetOrAdd(bundlePath, str => {
- var filePath = HostingEnvironment.MapPath(bundlePath);
+ return BundleCache.GetOrAdd(bundlePath, str =>
+ {
+ var filePath = HostingEnvironment.MapPath(bundlePath);
- var baseUrl = VirtualPathUtility.GetDirectory(bundlePath);
+ var baseUrl = VirtualPathUtility.GetDirectory(bundlePath);
- if (options == BundleOptions.Combined)
- return html.Css(bundlePath.Replace(".bundle", ""), null, options);
- if (options == BundleOptions.MinifiedAndCombined)
- return html.Css(bundlePath.Replace(".css.bundle", ".min.css"), null, options);
+ if (options == BundleOptions.Combined)
+ return html.Css(bundlePath.Replace(".bundle", ""), media, options);
+ if (options == BundleOptions.MinifiedAndCombined)
+ return html.Css(bundlePath.Replace(".css.bundle", ".min.css"), media, options);
- var cssFiles = File.ReadAllLines(filePath);
+ var cssFiles = File.ReadAllLines(filePath);
- var styles = new StringBuilder();
- foreach (var file in cssFiles)
- {
- var cssFile = file.Trim().Replace(".less", ".css");
- var cssSrc = Path.Combine(baseUrl, cssFile);
+ var styles = new StringBuilder();
+ foreach (var file in cssFiles)
+ {
+ var cssFile = file.Trim().Replace(".less", ".css");
+ var cssSrc = Path.Combine(baseUrl, cssFile);
- styles.AppendLine(
- html.Css(cssSrc, null, options).ToString()
- );
- }
+ styles.AppendLine(
+ html.Css(cssSrc, media, options).ToString()
+ );
+ }
- return styles.ToString().ToMvcHtmlString();
- });
- }
+ return styles.ToString().ToMvcHtmlString();
+ });
+ }
}
}
View
8 tests/Bootstrap.Mvc/Mvc.Bundler.cs
@@ -252,7 +252,7 @@ public static MvcHtmlString RenderJsBundle(this HtmlHelper html, string bundlePa
});
}
- public static MvcHtmlString RenderCssBundle(this HtmlHelper html, string bundlePath, BundleOptions options = BundleOptions.Minified)
+ public static MvcHtmlString RenderCssBundle(this HtmlHelper html, string bundlePath, BundleOptions options = BundleOptions.Minified, string media = null)
{
if (string.IsNullOrEmpty(bundlePath))
return MvcHtmlString.Empty;
@@ -265,9 +265,9 @@ public static MvcHtmlString RenderCssBundle(this HtmlHelper html, string bundleP
var baseUrl = VirtualPathUtility.GetDirectory(bundlePath);
if (options == BundleOptions.Combined)
- return html.Css(bundlePath.Replace(".bundle", ""), null, options);
+ return html.Css(bundlePath.Replace(".bundle", ""), media, options);
if (options == BundleOptions.MinifiedAndCombined)
- return html.Css(bundlePath.Replace(".css.bundle", ".min.css"), null, options);
+ return html.Css(bundlePath.Replace(".css.bundle", ".min.css"), media, options);
var cssFiles = File.ReadAllLines(filePath);
@@ -278,7 +278,7 @@ public static MvcHtmlString RenderCssBundle(this HtmlHelper html, string bundleP
var cssSrc = Path.Combine(baseUrl, cssFile);
styles.AppendLine(
- html.Css(cssSrc, null, options).ToString()
+ html.Css(cssSrc, media, options).ToString()
);
}
View
3  tests/Bootstrap.Mvc/Views/Shared/_Layout.cshtml
@@ -10,6 +10,9 @@
<!-- Le styles -->
@Html.RenderCssBundle("~/Content/app.css.bundle", BundleOptions.MinifiedAndCombined)
+
+ <!-- Print StyleSheet (should include media="print" -->
+ @Html.RenderCssBundle("~/Content/app.css.bundle", BundleOptions.MinifiedAndCombined, "print")
<!-- Le HTML5 shim, for IE6-8 support of HTML5 elements -->
<!--[if lt IE 9]>
View
BIN  tests/Bootstrap.Mvc/bin/Bootstrap.Mvc.dll
Binary file not shown
Please sign in to comment.
Something went wrong with that request. Please try again.