mirror of https://github.com/abpframework/abp.git
10 changed files with 189 additions and 244 deletions
@ -1,19 +0,0 @@ |
|||
using System; |
|||
using Microsoft.AspNetCore.Razor.TagHelpers; |
|||
using Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers; |
|||
|
|||
namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling.TagHelpers |
|||
{ |
|||
[HtmlTargetElement("abp-bundle-contributor", TagStructure = TagStructure.NormalOrSelfClosing, ParentTag = "abp-style-bundle")] |
|||
[HtmlTargetElement("abp-bundle-contributor", TagStructure = TagStructure.NormalOrSelfClosing, ParentTag = "abp-script-bundle")] |
|||
public class AbpBundleContributorTagHelper : AbpTagHelper<AbpBundleContributorTagHelper, AbpBundleContributorTagHelperService> |
|||
{ |
|||
public Type Type { get; set; } |
|||
|
|||
public AbpBundleContributorTagHelper(AbpBundleContributorTagHelperService service) |
|||
: base(service) |
|||
{ |
|||
|
|||
} |
|||
} |
|||
} |
|||
@ -1,17 +0,0 @@ |
|||
using System.Collections.Generic; |
|||
using Microsoft.AspNetCore.Razor.TagHelpers; |
|||
using Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers; |
|||
|
|||
namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling.TagHelpers |
|||
{ |
|||
public class AbpBundleContributorTagHelperService : AbpTagHelperService<AbpBundleContributorTagHelper> |
|||
{ |
|||
public override void Process(TagHelperContext context, TagHelperOutput output) |
|||
{ |
|||
output.SuppressOutput(); |
|||
|
|||
var files = (List<BundleTagHelperItem>)context.Items[AbpTagHelperConsts.ContextBundleItemListKey]; |
|||
files.Add(new BundleTagHelperItem(TagHelper.Type)); |
|||
} |
|||
} |
|||
} |
|||
@ -1,18 +0,0 @@ |
|||
using Microsoft.AspNetCore.Razor.TagHelpers; |
|||
using Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers; |
|||
|
|||
namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling.TagHelpers |
|||
{ |
|||
[HtmlTargetElement("abp-bundle-file", TagStructure = TagStructure.NormalOrSelfClosing, ParentTag = "abp-style-bundle")] |
|||
[HtmlTargetElement("abp-bundle-file", TagStructure = TagStructure.NormalOrSelfClosing, ParentTag = "abp-script-bundle")] |
|||
public class AbpBundleFileTagHelper : AbpTagHelper<AbpBundleFileTagHelper, AbpBundleFileTagHelperService> |
|||
{ |
|||
public string Src { get; set; } |
|||
|
|||
public AbpBundleFileTagHelper(AbpBundleFileTagHelperService service) |
|||
: base(service) |
|||
{ |
|||
|
|||
} |
|||
} |
|||
} |
|||
@ -1,17 +0,0 @@ |
|||
using System.Collections.Generic; |
|||
using Microsoft.AspNetCore.Razor.TagHelpers; |
|||
using Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers; |
|||
|
|||
namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling.TagHelpers |
|||
{ |
|||
public class AbpBundleFileTagHelperService : AbpTagHelperService<AbpBundleFileTagHelper> |
|||
{ |
|||
public override void Process(TagHelperContext context, TagHelperOutput output) |
|||
{ |
|||
output.SuppressOutput(); |
|||
|
|||
var files = (List<BundleTagHelperItem>)context.Items[AbpTagHelperConsts.ContextBundleItemListKey]; |
|||
files.Add(new BundleTagHelperItem(TagHelper.Src)); |
|||
} |
|||
} |
|||
} |
|||
@ -1,38 +1,10 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using Microsoft.AspNetCore.Razor.TagHelpers; |
|||
using Volo.Abp.AspNetCore.VirtualFileSystem; |
|||
|
|||
namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling.TagHelpers |
|||
namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling.TagHelpers |
|||
{ |
|||
public class AbpScriptBundleTagHelperService : AbpBundleTagHelperServiceBase<AbpScriptBundleTagHelper> |
|||
{ |
|||
public AbpScriptBundleTagHelperService( |
|||
IBundleManager bundleManager, |
|||
IHybridWebRootFileProvider webRootFileProvider) |
|||
: base( |
|||
bundleManager, |
|||
webRootFileProvider) |
|||
public AbpScriptBundleTagHelperService(AbpTagHelperScriptHelper resourceHelper) |
|||
: base(resourceHelper) |
|||
{ |
|||
|
|||
} |
|||
|
|||
protected override void CreateBundle(string bundleName, List<BundleTagHelperItem> bundleItems) |
|||
{ |
|||
BundleManager.CreateScriptBundle( |
|||
bundleName, |
|||
configuration => bundleItems.ForEach(bi => bi.AddToConfiguration(configuration)) |
|||
); |
|||
} |
|||
|
|||
protected override IReadOnlyList<string> GetBundleFiles(string bundleName) |
|||
{ |
|||
return BundleManager.GetScriptBundleFiles(bundleName); |
|||
} |
|||
|
|||
protected override void AddHtmlTag(TagHelperContext context, TagHelperOutput output, string file) |
|||
{ |
|||
output.Content.AppendHtml($"<script src=\"{file}\" type=\"text/javascript\"></script>{Environment.NewLine}"); |
|||
} |
|||
} |
|||
} |
|||
@ -1,48 +1,39 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Collections.Generic; |
|||
using System.Threading.Tasks; |
|||
using Microsoft.AspNetCore.Razor.TagHelpers; |
|||
using Volo.Abp.AspNetCore.VirtualFileSystem; |
|||
using Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers; |
|||
|
|||
namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling.TagHelpers |
|||
{ |
|||
public class AbpScriptTagHelperService : AbpBundleTagHelperServiceBase<AbpScriptTagHelper> |
|||
public class AbpScriptTagHelperService : AbpTagHelperService<AbpScriptTagHelper> |
|||
{ |
|||
public AbpScriptTagHelperService( |
|||
IBundleManager bundleManager, |
|||
IHybridWebRootFileProvider webRootFileProvider) |
|||
: base( |
|||
bundleManager, |
|||
webRootFileProvider) |
|||
{ |
|||
} |
|||
|
|||
//TODO: CreateBundle, GetBundleFiles & AddHtmlTag are identical with the AbpScriptBundleTagHelperService. Try to remove duplication!
|
|||
|
|||
protected override void CreateBundle(string bundleName, List<BundleTagHelperItem> bundleItems) |
|||
{ |
|||
BundleManager.CreateScriptBundle( |
|||
bundleName, |
|||
configuration => bundleItems.ForEach(bi => bi.AddToConfiguration(configuration)) |
|||
); |
|||
} |
|||
protected AbpTagHelperScriptHelper ResourceHelper { get; } |
|||
|
|||
protected override IReadOnlyList<string> GetBundleFiles(string bundleName) |
|||
public AbpScriptTagHelperService(AbpTagHelperScriptHelper resourceHelper) |
|||
{ |
|||
return BundleManager.GetScriptBundleFiles(bundleName); |
|||
ResourceHelper = resourceHelper; |
|||
} |
|||
|
|||
protected override void AddHtmlTag(TagHelperContext context, TagHelperOutput output, string file) |
|||
public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output) |
|||
{ |
|||
output.Content.AppendHtml($"<script src=\"{file}\" type=\"text/javascript\"></script>{Environment.NewLine}"); |
|||
} |
|||
|
|||
protected override Task<List<BundleTagHelperItem>> GetBundleItems(TagHelperContext context, TagHelperOutput output) |
|||
{ |
|||
return Task.FromResult(new List<BundleTagHelperItem> |
|||
var tagHelperItems = context.Items.GetOrDefault(AbpTagHelperConsts.ContextBundleItemListKey) as List<BundleTagHelperItem>; |
|||
if (tagHelperItems != null) |
|||
{ |
|||
output.SuppressOutput(); |
|||
tagHelperItems.Add(TagHelper.CreateBundleTagHelperItem()); |
|||
} |
|||
else |
|||
{ |
|||
TagHelper.CreateBundleTagHelperItem() |
|||
}); |
|||
await ResourceHelper.ProcessAsync( |
|||
context, |
|||
output, |
|||
TagHelper.GetNameOrNull(), |
|||
new List<BundleTagHelperItem> |
|||
{ |
|||
TagHelper.CreateBundleTagHelperItem() |
|||
} |
|||
); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -1,38 +1,10 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using Microsoft.AspNetCore.Razor.TagHelpers; |
|||
using Volo.Abp.AspNetCore.VirtualFileSystem; |
|||
|
|||
namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling.TagHelpers |
|||
namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling.TagHelpers |
|||
{ |
|||
public class AbpStyleBundleTagHelperService : AbpBundleTagHelperServiceBase<AbpStyleBundleTagHelper> |
|||
{ |
|||
public AbpStyleBundleTagHelperService( |
|||
IBundleManager bundleManager, |
|||
IHybridWebRootFileProvider webRootFileProvider) |
|||
: base( |
|||
bundleManager, |
|||
webRootFileProvider) |
|||
public AbpStyleBundleTagHelperService(AbpTagHelperStyleHelper resourceHelper) |
|||
: base(resourceHelper) |
|||
{ |
|||
|
|||
} |
|||
|
|||
protected override void CreateBundle(string bundleName, List<BundleTagHelperItem> bundleItems) |
|||
{ |
|||
BundleManager.CreateStyleBundle( |
|||
bundleName, |
|||
configuration => bundleItems.ForEach(bi => bi.AddToConfiguration(configuration)) |
|||
); |
|||
} |
|||
|
|||
protected override IReadOnlyList<string> GetBundleFiles(string bundleName) |
|||
{ |
|||
return BundleManager.GetStyleBundleFiles(bundleName); |
|||
} |
|||
|
|||
protected override void AddHtmlTag(TagHelperContext context, TagHelperOutput output, string file) |
|||
{ |
|||
output.Content.AppendHtml($"<link rel=\"stylesheet\" type=\"text/css\" href=\"{file}\" />{Environment.NewLine}"); |
|||
} |
|||
} |
|||
} |
|||
@ -1,48 +1,39 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Collections.Generic; |
|||
using System.Threading.Tasks; |
|||
using Microsoft.AspNetCore.Razor.TagHelpers; |
|||
using Volo.Abp.AspNetCore.VirtualFileSystem; |
|||
using Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers; |
|||
|
|||
namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling.TagHelpers |
|||
{ |
|||
public class AbpStyleTagHelperService : AbpBundleTagHelperServiceBase<AbpStyleTagHelper> |
|||
public class AbpStyleTagHelperService : AbpTagHelperService<AbpStyleTagHelper> |
|||
{ |
|||
public AbpStyleTagHelperService( |
|||
IBundleManager bundleManager, |
|||
IHybridWebRootFileProvider webRootFileProvider) |
|||
: base( |
|||
bundleManager, |
|||
webRootFileProvider) |
|||
{ |
|||
} |
|||
|
|||
//TODO: CreateBundle, GetBundleFiles & AddHtmlTag are identical with the AbpStyleBundleTagHelperService. Try to remove duplication!
|
|||
|
|||
protected override void CreateBundle(string bundleName, List<BundleTagHelperItem> bundleItems) |
|||
{ |
|||
BundleManager.CreateStyleBundle( |
|||
bundleName, |
|||
configuration => bundleItems.ForEach(bi => bi.AddToConfiguration(configuration)) |
|||
); |
|||
} |
|||
protected AbpTagHelperStyleHelper ResourceHelper { get; } |
|||
|
|||
protected override IReadOnlyList<string> GetBundleFiles(string bundleName) |
|||
public AbpStyleTagHelperService(AbpTagHelperStyleHelper resourceHelper) |
|||
{ |
|||
return BundleManager.GetStyleBundleFiles(bundleName); |
|||
ResourceHelper = resourceHelper; |
|||
} |
|||
|
|||
protected override void AddHtmlTag(TagHelperContext context, TagHelperOutput output, string file) |
|||
public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output) |
|||
{ |
|||
output.Content.AppendHtml($"<link rel=\"stylesheet\" type=\"text/css\" href=\"{file}\" />{Environment.NewLine}"); |
|||
} |
|||
|
|||
protected override Task<List<BundleTagHelperItem>> GetBundleItems(TagHelperContext context, TagHelperOutput output) |
|||
{ |
|||
return Task.FromResult(new List<BundleTagHelperItem> |
|||
var tagHelperItems = context.Items.GetOrDefault(AbpTagHelperConsts.ContextBundleItemListKey) as List<BundleTagHelperItem>; |
|||
if (tagHelperItems != null) |
|||
{ |
|||
output.SuppressOutput(); |
|||
tagHelperItems.Add(TagHelper.CreateBundleTagHelperItem()); |
|||
} |
|||
else |
|||
{ |
|||
TagHelper.CreateBundleTagHelperItem() |
|||
}); |
|||
await ResourceHelper.ProcessAsync( |
|||
context, |
|||
output, |
|||
TagHelper.GetNameOrNull(), |
|||
new List<BundleTagHelperItem> |
|||
{ |
|||
TagHelper.CreateBundleTagHelperItem() |
|||
} |
|||
); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,125 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Threading.Tasks; |
|||
using Microsoft.AspNetCore.Razor.TagHelpers; |
|||
using Volo.Abp.AspNetCore.VirtualFileSystem; |
|||
using Volo.Abp.DependencyInjection; |
|||
|
|||
namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling.TagHelpers |
|||
{ |
|||
public abstract class AbpTagHelperResourceHelper : ITransientDependency |
|||
{ |
|||
protected IBundleManager BundleManager { get; } |
|||
protected IHybridWebRootFileProvider WebRootFileProvider { get; } |
|||
|
|||
protected AbpTagHelperResourceHelper( |
|||
IBundleManager bundleManager, |
|||
IHybridWebRootFileProvider webRootFileProvider) |
|||
{ |
|||
BundleManager = bundleManager; |
|||
WebRootFileProvider = webRootFileProvider; |
|||
} |
|||
|
|||
public virtual async Task ProcessAsync( |
|||
TagHelperContext context, |
|||
TagHelperOutput output, |
|||
string bundleName, |
|||
List<BundleTagHelperItem> files) |
|||
{ |
|||
output.TagName = null; |
|||
|
|||
if (bundleName.IsNullOrEmpty()) |
|||
{ |
|||
bundleName = GenerateBundleName(files); |
|||
} |
|||
|
|||
CreateBundle(bundleName, files); |
|||
|
|||
var bundleFiles = GetBundleFiles(bundleName); |
|||
|
|||
output.Content.Clear(); |
|||
|
|||
foreach (var bundleFile in bundleFiles) |
|||
{ |
|||
var file = WebRootFileProvider.GetFileInfo(bundleFile); |
|||
if (file == null) |
|||
{ |
|||
throw new AbpException($"Could not find the bundle file from {nameof(IHybridWebRootFileProvider)}"); |
|||
} |
|||
|
|||
AddHtmlTag(context, output, bundleFile + "?_v=" + file.LastModified.UtcTicks); |
|||
} |
|||
} |
|||
|
|||
protected abstract void CreateBundle(string bundleName, List<BundleTagHelperItem> bundleItems); |
|||
|
|||
protected abstract IReadOnlyList<string> GetBundleFiles(string bundleName); |
|||
|
|||
protected abstract void AddHtmlTag(TagHelperContext context, TagHelperOutput output, string file); |
|||
|
|||
protected virtual string GenerateBundleName(List<BundleTagHelperItem> bundleItems) |
|||
{ |
|||
return bundleItems.JoinAsString("|").ToMd5(); |
|||
} |
|||
} |
|||
|
|||
public class AbpTagHelperScriptHelper : AbpTagHelperResourceHelper |
|||
{ |
|||
public AbpTagHelperScriptHelper( |
|||
IBundleManager bundleManager, |
|||
IHybridWebRootFileProvider webRootFileProvider |
|||
) : base( |
|||
bundleManager, |
|||
webRootFileProvider) |
|||
{ |
|||
} |
|||
|
|||
protected override void CreateBundle(string bundleName, List<BundleTagHelperItem> bundleItems) |
|||
{ |
|||
BundleManager.CreateScriptBundle( |
|||
bundleName, |
|||
configuration => bundleItems.ForEach(bi => bi.AddToConfiguration(configuration)) |
|||
); |
|||
} |
|||
|
|||
protected override IReadOnlyList<string> GetBundleFiles(string bundleName) |
|||
{ |
|||
return BundleManager.GetScriptBundleFiles(bundleName); |
|||
} |
|||
|
|||
protected override void AddHtmlTag(TagHelperContext context, TagHelperOutput output, string file) |
|||
{ |
|||
output.Content.AppendHtml($"<script src=\"{file}\" type=\"text/javascript\"></script>{Environment.NewLine}"); |
|||
} |
|||
} |
|||
|
|||
public class AbpTagHelperStyleHelper : AbpTagHelperResourceHelper |
|||
{ |
|||
public AbpTagHelperStyleHelper( |
|||
IBundleManager bundleManager, |
|||
IHybridWebRootFileProvider webRootFileProvider |
|||
) : base( |
|||
bundleManager, |
|||
webRootFileProvider) |
|||
{ |
|||
} |
|||
|
|||
protected override void CreateBundle(string bundleName, List<BundleTagHelperItem> bundleItems) |
|||
{ |
|||
BundleManager.CreateStyleBundle( |
|||
bundleName, |
|||
configuration => bundleItems.ForEach(bi => bi.AddToConfiguration(configuration)) |
|||
); |
|||
} |
|||
|
|||
protected override IReadOnlyList<string> GetBundleFiles(string bundleName) |
|||
{ |
|||
return BundleManager.GetStyleBundleFiles(bundleName); |
|||
} |
|||
|
|||
protected override void AddHtmlTag(TagHelperContext context, TagHelperOutput output, string file) |
|||
{ |
|||
output.Content.AppendHtml($"<link rel=\"stylesheet\" type=\"text/css\" href=\"{file}\" />{Environment.NewLine}"); |
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue