Skip to content

Commit

Permalink
Refactor.
Browse files Browse the repository at this point in the history
  • Loading branch information
maliming committed Oct 25, 2021
1 parent 11ceecf commit 7daaeeb
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,23 @@ public class AbpBundlingOptions
/// </summary>
public BundlingMode Mode { get; set; } = BundlingMode.Auto;

public bool DeferScriptsByDefault { get; set; }

public List<string> DeferScripts { get; }

public bool PreloadStylesByDefault { get; set; }

public List<string> PreloadStyles { get; }

public AbpBundlingOptions()
{
StyleBundles = new BundleConfigurationCollection();
ScriptBundles = new BundleConfigurationCollection();
MinificationIgnoredFiles = new HashSet<string>();
DeferScriptsByDefault = false;
DeferScripts = new List<string>();
PreloadStylesByDefault = false;
PreloadStyles = new List<string>();
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,14 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling.TagHelpers
{
public class AbpTagHelperScriptService : AbpTagHelperResourceService
{
protected AbpTagHelperScriptStyleLoadingOptions LoadingOptions { get; }

public AbpTagHelperScriptService(
IBundleManager bundleManager,
IOptions<AbpBundlingOptions> options,
IWebHostEnvironment hostingEnvironment,
IOptions<AbpTagHelperScriptStyleLoadingOptions> loadingOptions) : base(
IWebHostEnvironment hostingEnvironment) : base(
bundleManager,
options,
hostingEnvironment)
{
LoadingOptions = loadingOptions.Value;
}

protected override void CreateBundle(string bundleName, List<BundleTagHelperItem> bundleItems)
Expand All @@ -50,7 +46,7 @@ protected override void AddHtmlTag(ViewContext viewContext, TagHelper tagHelper,
_ => false
};

var deferText = (defer || LoadingOptions.GlobalDeferScript || LoadingOptions.DeferScripts.Any(x => file.StartsWith(x, StringComparison.OrdinalIgnoreCase)))
var deferText = (defer || Options.DeferScriptsByDefault || Options.DeferScripts.Any(x => file.StartsWith(x, StringComparison.OrdinalIgnoreCase)))
? "defer"
: string.Empty;
output.Content.AppendHtml($"<script {deferText} src=\"{viewContext.GetUrlHelper().Content(file.EnsureStartsWith('~'))}\"></script>{Environment.NewLine}");
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,14 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling.TagHelpers
{
public class AbpTagHelperStyleService : AbpTagHelperResourceService
{
protected AbpTagHelperScriptStyleLoadingOptions LoadingOptions { get; }

public AbpTagHelperStyleService(
IBundleManager bundleManager,
IOptions<AbpBundlingOptions> options,
IWebHostEnvironment hostingEnvironment,
IOptions<AbpTagHelperScriptStyleLoadingOptions> loadingOptions) : base(
IWebHostEnvironment hostingEnvironment) : base(
bundleManager,
options,
hostingEnvironment)
{
LoadingOptions = loadingOptions.Value;
}

protected override void CreateBundle(string bundleName, List<BundleTagHelperItem> bundleItems)
Expand All @@ -50,7 +46,7 @@ protected override void AddHtmlTag(ViewContext viewContext, TagHelper tagHelper,
_ => false
};

if (preload || LoadingOptions.GlobalPreloadStyle || LoadingOptions.PreloadStyles.Any(x => file.StartsWith(x, StringComparison.OrdinalIgnoreCase)))
if (preload || Options.PreloadStylesByDefault || Options.PreloadStyles.Any(x => file.StartsWith(x, StringComparison.OrdinalIgnoreCase)))
{
output.Content.AppendHtml($"<link rel=\"preload\" href=\"{viewContext.GetUrlHelper().Content(file.EnsureStartsWith('~'))}\" as=\"style\" onload=\"this.rel='stylesheet'\" />{Environment.NewLine}");
}
Expand Down

0 comments on commit 7daaeeb

Please sign in to comment.