/// <summary> /// Prepares an HTML element that's designed to retrieve a StyleSheet file from an assembly's embedded resources /// </summary> /// <param name="viewPage">The view being generated in the .cshtml file</param> /// <param name="assemblyName">the name of the assembly module</param> /// <param name="resourcePath">The name of the style sheets file</param> /// <returns>The raw html element</returns> public static IHtmlString StyleSheet(WebViewPage viewPage, string assemblyName, string resourcePath) { Guid guid = IncludeHelper.ExtractResourceInfo(assemblyName, resourcePath, out string assembly, out string resource, out string encoding); if (guid.Equals(Guid.Empty)) { string error = $"<link data-type='stylesheet' data-module-error='Unknown module name: {assembly}' />"; return(viewPage.Html.Raw(error)); } //------------------------------------------------------------------------------------- // Example of usage in a .cshtml file: // @this.StyleSheet( "Nexlend.Platform.DecisionLogic", "Styles/CssClasses.css" ) // // Here is an example of a processed uri: // "/Resource/StyleSheet/Nexlend.Platform.DecisionLogic/Styles.CssClasses.css/" // // Here is what the final HTML tag will look like: // <link data-file='Styles.CssClasses.css' href='/Resource/StyleSheet/{guid}/Nexlend.Platform.DecisionLogic/encoded_string/' rel='stylesheet' type='text/css' /> //------------------------------------------------------------------------------------- string html = FormattableString.Invariant($"<link data-file='{resource}' href='/Resource/StyleSheet/{guid}/{assembly}/{encoding}/' rel='stylesheet' type='text/css' />"); return(viewPage.Html.Raw(html)); }
/// <summary> /// Prepares an HTML element that's designed to retrieve a Javascript file from an assembly's embedded resources /// </summary> /// <param name="viewPage">The view being generated in the .cshtml file</param> /// <param name="assemblyName">the name of the assembly module</param> /// <param name="resourcePath">The name of the javascript file</param> /// <returns>The raw html element</returns> public static IHtmlString JavaScript(WebViewPage viewPage, string assemblyName, string resourcePath) { Guid guid = IncludeHelper.ExtractResourceInfo(assemblyName, resourcePath, out string assembly, out string resource, out string encoding); if (guid.Equals(Guid.Empty)) { string error = $"<link data-type='javascript' data-module-error='Unknown module name: {assembly}' />"; return(viewPage.Html.Raw(error)); } //------------------------------------------------------------------------------------- // Example of usage in a .cshtml file: // @this.JavaScript( "Nexlend.Platform.DecisionLogic", "Scripts/ValidationFormFields.js" ) // // Here is an example of a processed uri: // "/Resource/JavaScript/Nexlend.Platform.DecisionLogic/Scripts.ValidationFormFields.js/" // // Here is what the final HTML tag will look like: // <script data-file='Scripts.ValidationFormFields.js' src='/Resource/JavaScript/{guid}/Nexlend.Platform.DecisionLogic/encoded_string/' type='text/javascript' ></script> //------------------------------------------------------------------------------------- var html = FormattableString.Invariant($"<script data-file='{resource}' src='/Resource/JavaScript/{guid}/{assembly}/{encoding}/' type='text/javascript'></script>"); return(viewPage.Html.Raw(html)); }