Browse Source

Refactor bundling.

pull/301/head
Halil ibrahim Kalkan 8 years ago
parent
commit
32fc06b22e
  1. 9
      src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/BundleManager.cs
  2. 4
      src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/IBundleManager.cs
  3. 10
      src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/TagHelpers/AbpBundleTagHelperServiceBase.cs
  4. 10
      src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/TagHelpers/AbpScriptBundleTagHelperService.cs
  5. 10
      src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/TagHelpers/AbpStyleBundleTagHelperService.cs

9
src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/BundleManager.cs

@ -1,5 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Hosting;
@ -46,17 +47,17 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling
_options = options.Value; _options = options.Value;
} }
public virtual List<string> GetStyleBundleFiles(string bundleName) public virtual IReadOnlyList<string> GetStyleBundleFiles(string bundleName)
{ {
return GetBundleFiles(_options.StyleBundles, bundleName, _styleBundler); return GetBundleFiles(_options.StyleBundles, bundleName, _styleBundler);
} }
public virtual List<string> GetScriptBundleFiles(string bundleName) public virtual IReadOnlyList<string> GetScriptBundleFiles(string bundleName)
{ {
return GetBundleFiles(_options.ScriptBundles, bundleName, _scriptBundler); return GetBundleFiles(_options.ScriptBundles, bundleName, _scriptBundler);
} }
protected virtual List<string> GetBundleFiles(BundleConfigurationCollection bundles, string bundleName, IBundler bundler) protected virtual IReadOnlyList<string> GetBundleFiles(BundleConfigurationCollection bundles, string bundleName, IBundler bundler)
{ {
var bundleRelativePath = _options.BundleFolderName.EnsureEndsWith('/') + bundleName + "." + bundler.FileExtension; var bundleRelativePath = _options.BundleFolderName.EnsureEndsWith('/') + bundleName + "." + bundler.FileExtension;
@ -91,7 +92,7 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling
return cacheValue; return cacheValue;
}); });
return cacheItem.Files; return cacheItem.Files.ToImmutableList();
} }
private void WatchChanges(BundleCacheItem cacheValue, List<string> files, string bundleRelativePath) private void WatchChanges(BundleCacheItem cacheValue, List<string> files, string bundleRelativePath)

4
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 public interface IBundleManager
{ {
List<string> GetStyleBundleFiles(string bundleName); IReadOnlyList<string> GetStyleBundleFiles(string bundleName);
List<string> GetScriptBundleFiles(string bundleName); IReadOnlyList<string> GetScriptBundleFiles(string bundleName);
void CreateStyleBundle(string bundleName, Action<BundleConfiguration> configureAction); void CreateStyleBundle(string bundleName, Action<BundleConfiguration> configureAction);

10
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); var bundleFiles = GetBundleFiles(bundleName);
output.Content.Clear(); output.Content.Clear();
AddHtmlTags(context, output, bundleFiles);
foreach (var bundleFile in bundleFiles)
{
AddHtmlTag(context, output, bundleFile + "_");
}
} }
protected abstract void CreateBundle(string bundleName, List<string> files); protected abstract void CreateBundle(string bundleName, List<string> files);
protected abstract List<string> GetBundleFiles(string bundleName); protected abstract IReadOnlyList<string> GetBundleFiles(string bundleName);
protected abstract void AddHtmlTags(TagHelperContext context, TagHelperOutput output, List<string> files); protected abstract void AddHtmlTag(TagHelperContext context, TagHelperOutput output, string file);
protected virtual string GenerateBundleName(TagHelperContext context, TagHelperOutput output, List<string> fileList) protected virtual string GenerateBundleName(TagHelperContext context, TagHelperOutput output, List<string> fileList)
{ {

10
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<string> GetBundleFiles(string bundleName) protected override IReadOnlyList<string> GetBundleFiles(string bundleName)
{ {
return BundleManager.GetScriptBundleFiles(bundleName); return BundleManager.GetScriptBundleFiles(bundleName);
} }
protected override void AddHtmlTags(TagHelperContext context, TagHelperOutput output, List<string> files) protected override void AddHtmlTag(TagHelperContext context, TagHelperOutput output, string file)
{ {
foreach (var file in files) output.Content.AppendHtml($"<script src=\"{file}\" type=\"text/javascript\"></script>{Environment.NewLine}");
{
output.Content.AppendHtml($"<script src=\"{file}\" type=\"text/javascript\"></script>{Environment.NewLine}");
}
} }
} }
} }

10
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<string> GetBundleFiles(string bundleName) protected override IReadOnlyList<string> GetBundleFiles(string bundleName)
{ {
return BundleManager.GetStyleBundleFiles(bundleName); return BundleManager.GetStyleBundleFiles(bundleName);
} }
protected override void AddHtmlTags(TagHelperContext context, TagHelperOutput output, List<string> files) protected override void AddHtmlTag(TagHelperContext context, TagHelperOutput output, string file)
{ {
foreach (var file in files) output.Content.AppendHtml($"<link rel=\"stylesheet\" type=\"text/css\" href=\"{file}\" />{Environment.NewLine}");
{
output.Content.AppendHtml(
$"<link rel=\"stylesheet\" type=\"text/css\" href=\"{file}\" />{Environment.NewLine}");
}
} }
} }
} }
Loading…
Cancel
Save