From 32fc06b22e212a2d246f28d05a82d86fa32b9ec3 Mon Sep 17 00:00:00 2001 From: Halil ibrahim Kalkan Date: Thu, 14 Jun 2018 01:21:11 +0300 Subject: [PATCH] Refactor bundling. --- .../Abp/AspNetCore/Mvc/UI/Bundling/BundleManager.cs | 9 +++++---- .../Abp/AspNetCore/Mvc/UI/Bundling/IBundleManager.cs | 4 ++-- .../TagHelpers/AbpBundleTagHelperServiceBase.cs | 10 +++++++--- .../TagHelpers/AbpScriptBundleTagHelperService.cs | 10 +++------- .../TagHelpers/AbpStyleBundleTagHelperService.cs | 10 +++------- 5 files changed, 20 insertions(+), 23 deletions(-) diff --git a/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/BundleManager.cs b/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/BundleManager.cs index 43c3740279..dc3cc27d4c 100644 --- a/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/BundleManager.cs +++ b/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/BundleManager.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Collections.Immutable; using System.Linq; using System.Text; using Microsoft.AspNetCore.Hosting; @@ -46,17 +47,17 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling _options = options.Value; } - public virtual List GetStyleBundleFiles(string bundleName) + public virtual IReadOnlyList GetStyleBundleFiles(string bundleName) { return GetBundleFiles(_options.StyleBundles, bundleName, _styleBundler); } - public virtual List GetScriptBundleFiles(string bundleName) + public virtual IReadOnlyList GetScriptBundleFiles(string bundleName) { return GetBundleFiles(_options.ScriptBundles, bundleName, _scriptBundler); } - protected virtual List GetBundleFiles(BundleConfigurationCollection bundles, string bundleName, IBundler bundler) + protected virtual IReadOnlyList GetBundleFiles(BundleConfigurationCollection bundles, string bundleName, IBundler bundler) { var bundleRelativePath = _options.BundleFolderName.EnsureEndsWith('/') + bundleName + "." + bundler.FileExtension; @@ -91,7 +92,7 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling return cacheValue; }); - return cacheItem.Files; + return cacheItem.Files.ToImmutableList(); } private void WatchChanges(BundleCacheItem cacheValue, List files, string bundleRelativePath) diff --git a/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/IBundleManager.cs b/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/IBundleManager.cs index 0e0f9989a3..eb02eb27c9 100644 --- a/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/IBundleManager.cs +++ b/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/IBundleManager.cs @@ -7,9 +7,9 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling public interface IBundleManager { - List GetStyleBundleFiles(string bundleName); + IReadOnlyList GetStyleBundleFiles(string bundleName); - List GetScriptBundleFiles(string bundleName); + IReadOnlyList GetScriptBundleFiles(string bundleName); void CreateStyleBundle(string bundleName, Action configureAction); diff --git a/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/TagHelpers/AbpBundleTagHelperServiceBase.cs b/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/TagHelpers/AbpBundleTagHelperServiceBase.cs index b6ad5dbab6..860a4f939e 100644 --- a/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/TagHelpers/AbpBundleTagHelperServiceBase.cs +++ b/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/TagHelpers/AbpBundleTagHelperServiceBase.cs @@ -32,14 +32,18 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling.TagHelpers var bundleFiles = GetBundleFiles(bundleName); output.Content.Clear(); - AddHtmlTags(context, output, bundleFiles); + + foreach (var bundleFile in bundleFiles) + { + AddHtmlTag(context, output, bundleFile + "_"); + } } protected abstract void CreateBundle(string bundleName, List files); - protected abstract List GetBundleFiles(string bundleName); + protected abstract IReadOnlyList GetBundleFiles(string bundleName); - protected abstract void AddHtmlTags(TagHelperContext context, TagHelperOutput output, List files); + protected abstract void AddHtmlTag(TagHelperContext context, TagHelperOutput output, string file); protected virtual string GenerateBundleName(TagHelperContext context, TagHelperOutput output, List fileList) { diff --git a/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/TagHelpers/AbpScriptBundleTagHelperService.cs b/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/TagHelpers/AbpScriptBundleTagHelperService.cs index c487a4a878..125719e60d 100644 --- a/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/TagHelpers/AbpScriptBundleTagHelperService.cs +++ b/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/TagHelpers/AbpScriptBundleTagHelperService.cs @@ -20,18 +20,14 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling.TagHelpers ); } - protected override List GetBundleFiles(string bundleName) + protected override IReadOnlyList GetBundleFiles(string bundleName) { return BundleManager.GetScriptBundleFiles(bundleName); } - protected override void AddHtmlTags(TagHelperContext context, TagHelperOutput output, List files) + protected override void AddHtmlTag(TagHelperContext context, TagHelperOutput output, string file) { - foreach (var file in files) - { - output.Content.AppendHtml($"{Environment.NewLine}"); - } + output.Content.AppendHtml($"{Environment.NewLine}"); } - } } \ No newline at end of file diff --git a/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/TagHelpers/AbpStyleBundleTagHelperService.cs b/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/TagHelpers/AbpStyleBundleTagHelperService.cs index 5dc1aa46d8..72da7547e1 100644 --- a/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/TagHelpers/AbpStyleBundleTagHelperService.cs +++ b/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/TagHelpers/AbpStyleBundleTagHelperService.cs @@ -20,18 +20,14 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling.TagHelpers ); } - protected override List GetBundleFiles(string bundleName) + protected override IReadOnlyList GetBundleFiles(string bundleName) { return BundleManager.GetStyleBundleFiles(bundleName); } - protected override void AddHtmlTags(TagHelperContext context, TagHelperOutput output, List files) + protected override void AddHtmlTag(TagHelperContext context, TagHelperOutput output, string file) { - foreach (var file in files) - { - output.Content.AppendHtml( - $"{Environment.NewLine}"); - } + output.Content.AppendHtml($"{Environment.NewLine}"); } } } \ No newline at end of file