maintenance: plugin refactoring

This commit is contained in:
Gary Sharp
2022-12-04 13:40:16 +11:00
parent 05593a1466
commit 4f9f0fd0a8
12 changed files with 402 additions and 129 deletions
@@ -8,20 +8,24 @@ namespace Disco.Services.Web
{
public static class BundleExtensions
{
public static void BundleDeferred(this HtmlHelper htmlHelper, string BundleUrl)
public static void BundleDeferred(this HttpContextBase httpContext, string BundleUrl)
{
// Ensure 'App-Relative' Url:
BundleUrl = BundleUrl.StartsWith("~/") ? BundleUrl : (BundleUrl.StartsWith("/") ? string.Concat("~", BundleUrl) : string.Concat("~/", BundleUrl));
var deferredBundles = htmlHelper.ViewContext.HttpContext.Items[BundleTable.DeferredKey] as List<string>;
var deferredBundles = httpContext.Items[BundleTable.DeferredKey] as List<string>;
if (deferredBundles == null)
{
deferredBundles = new List<string>();
htmlHelper.ViewContext.HttpContext.Items[BundleTable.DeferredKey] = deferredBundles;
httpContext.Items[BundleTable.DeferredKey] = deferredBundles;
}
if (!deferredBundles.Contains(BundleUrl))
deferredBundles.Add(BundleUrl);
}
public static void BundleDeferred(this HtmlHelper htmlHelper, string BundleUrl)
=> htmlHelper.ViewContext.HttpContext.BundleDeferred(BundleUrl);
public static HtmlString BundleRenderDeferred(this HtmlHelper htmlHelper)
{
var deferredBundles = htmlHelper.ViewContext.HttpContext.Items[BundleTable.DeferredKey] as List<string>;