C# Class WebApp.ASPNETCore1.B4BFiles.BowerBundlerHelperDnx

This class contains extention methods to provide a the inclusings of CSS and JavaScript files in your views 1) @Html.HtmlCssCached("bundleName") is equivalent to @Styles.Render("~/Content/bundleName") 2) @Html.HtmlScriptsCached("bundleName") is equivalent to @Scripts.Render("~/bundles/bundleName") Whether it delivers individual files or the single minfied file that Grunt produced is defined by whether the code was compiled in DEBUG mode or not. This can be overridden on each method by the optional 'forceState' parameter. Both these methods have some small limitations: 1. These methods can do searches for files, e.g. ~/Scripts/*.js, or ~/Scripts/*/*.js However it does not support Grunt/Gulp's /**/ search all directories and subdirectories feature. It is something that could be implemented, but I left it out for now. It throws an NotImplementedException if found 2. I suspect that the .NET search and the Grunt/Gulp search might have slightly different rules. see the Note under Remarks about a search like *.js https://msdn.microsoft.com/en-us/library/wz42302f%28v=vs.110%29.aspx 3. BundlerHelper has the same problem (feature) as BundleConfig. If you change or add files to the settings.json file then you need to rebuild your application because HtmlCssCached and HtmlCssCached deliver from a static cache. You can turn off caching by setting the forceState parameter in each methods to true. Finally it is very tempting to add comments to the settings.json file. While Json.Net handles comments Grunt doesn't, and fails silently!
Show file Open project: JonPSmith/MvcUsingBower

Public Methods

Method Description
HtmlCssCached ( this urlHelper, string bundleName, bool forceState = null ) : HtmlString

This returns the CSS links using caching if forceState is null Note: this assumes that the CSS minified file is in the directory "~/css/"

HtmlScriptsCached ( this urlHelper, string bundleName, bool forceState = null ) : HtmlString

This returns the script includes for a specific group using caching if forceState is null Note: this assumes that the JavaScript minified file is in the directory "~/js/"

Private Methods

Method Description
CreateHtmlIncludes ( this urlHelper, string bundleName, CssOrJs cssOrJs, bool forceState = null ) : HtmlString

This returns the html to include either CSS or JavaScript files

GetAbsDataDirectory ( ) : string

This is equivalent to MVC5's AppDomain.CurrentDomain.GetData("DataDirectory").ToString() This gets the absolute path to the directory containing the B4B files

Method Details

HtmlCssCached() public static method

This returns the CSS links using caching if forceState is null Note: this assumes that the CSS minified file is in the directory "~/css/"
public static HtmlCssCached ( this urlHelper, string bundleName, bool forceState = null ) : HtmlString
urlHelper this
bundleName string The name of the setting.json property containing the list of Css file to include. /// defaults to main Css file
forceState bool if not null then true forces into debug state and false forces production state
return HtmlString

HtmlScriptsCached() public static method

This returns the script includes for a specific group using caching if forceState is null Note: this assumes that the JavaScript minified file is in the directory "~/js/"
public static HtmlScriptsCached ( this urlHelper, string bundleName, bool forceState = null ) : HtmlString
urlHelper this
bundleName string The name of the setting.json property containing the list of JavaScript file to include. /// defaults to main js file
forceState bool if not null then true forces into debug state and false forces production state
return HtmlString