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 6dc089c4c6..c2a5cc48d2 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 @@ -23,8 +23,9 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling.TagHelpers { output.TagName = null; - var bundleName = TagHelper.Name; var files = await GetBundleItems(context, output); + + var bundleName = TagHelper.GetNameOrNull(); if (bundleName.IsNullOrEmpty()) { bundleName = GenerateBundleName(files); diff --git a/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/TagHelpers/AbpScriptBundleTagHelper.cs b/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/TagHelpers/AbpScriptBundleTagHelper.cs index efb7c67ded..d225ecb946 100644 --- a/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/TagHelpers/AbpScriptBundleTagHelper.cs +++ b/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/TagHelpers/AbpScriptBundleTagHelper.cs @@ -12,5 +12,10 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling.TagHelpers : base(service) { } + + public string GetNameOrNull() + { + return Name; + } } } \ No newline at end of file diff --git a/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/TagHelpers/AbpScriptTagHelper.cs b/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/TagHelpers/AbpScriptTagHelper.cs new file mode 100644 index 0000000000..d1681441a6 --- /dev/null +++ b/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/TagHelpers/AbpScriptTagHelper.cs @@ -0,0 +1,59 @@ +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-script", TagStructure = TagStructure.NormalOrSelfClosing)] + public class AbpScriptTagHelper : AbpTagHelper, IBundleTagHelper + { + /// + /// A file path. + /// + public string Src { get; set; } + + /// + /// A bundle contributor type. + /// + public Type Type { get; set; } + + public AbpScriptTagHelper(AbpScriptTagHelperService service) + : base(service) + { + + } + + public string GetNameOrNull() + { + if (Type != null) + { + return Type.FullName; + } + + if (Src != null) + { + return Src + .RemovePreFix("/") + .RemovePostFix(StringComparison.OrdinalIgnoreCase, ".js") + .Replace("/", "."); + } + + throw new AbpException("abp-script tag helper requires to set either src or type!"); + } + + public BundleTagHelperItem CreateBundleTagHelperItem() + { + if (Type != null) + { + return new BundleTagHelperItem(Type); + } + + if (Src != null) + { + return new BundleTagHelperItem(Src); + } + + throw new AbpException("abp-script tag helper requires to set either src or type!"); + } + } +} \ No newline at end of file diff --git a/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/TagHelpers/AbpScriptTagHelperService.cs b/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/TagHelpers/AbpScriptTagHelperService.cs new file mode 100644 index 0000000000..e6b947ada0 --- /dev/null +++ b/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/TagHelpers/AbpScriptTagHelperService.cs @@ -0,0 +1,48 @@ +using System; +using System.Collections.Generic; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Razor.TagHelpers; +using Volo.Abp.AspNetCore.VirtualFileSystem; + +namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling.TagHelpers +{ + public class AbpScriptTagHelperService : AbpBundleTagHelperServiceBase + { + 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 bundleItems) + { + BundleManager.CreateScriptBundle( + bundleName, + configuration => bundleItems.ForEach(bi => bi.AddToConfiguration(configuration)) + ); + } + + protected override IReadOnlyList GetBundleFiles(string bundleName) + { + return BundleManager.GetScriptBundleFiles(bundleName); + } + + protected override void AddHtmlTag(TagHelperContext context, TagHelperOutput output, string file) + { + output.Content.AppendHtml($"{Environment.NewLine}"); + } + + protected override Task> GetBundleItems(TagHelperContext context, TagHelperOutput output) + { + return Task.FromResult(new List + { + TagHelper.CreateBundleTagHelperItem() + }); + } + } +} \ No newline at end of file diff --git a/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/TagHelpers/AbpStyleBundleTagHelper.cs b/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/TagHelpers/AbpStyleBundleTagHelper.cs index 8d0fdde1d5..7216df490c 100644 --- a/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/TagHelpers/AbpStyleBundleTagHelper.cs +++ b/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/TagHelpers/AbpStyleBundleTagHelper.cs @@ -14,5 +14,10 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling.TagHelpers : base(service) { } + + public string GetNameOrNull() + { + return Name; + } } } diff --git a/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/TagHelpers/AbpStyleTagHelper.cs b/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/TagHelpers/AbpStyleTagHelper.cs new file mode 100644 index 0000000000..9b27edfa26 --- /dev/null +++ b/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/TagHelpers/AbpStyleTagHelper.cs @@ -0,0 +1,59 @@ +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-style", TagStructure = TagStructure.NormalOrSelfClosing)] + public class AbpStyleTagHelper : AbpTagHelper, IBundleTagHelper + { + /// + /// A file path. + /// + public string Src { get; set; } + + /// + /// A bundle contributor type. + /// + public Type Type { get; set; } + + public AbpStyleTagHelper(AbpStyleTagHelperService service) + : base(service) + { + + } + + public string GetNameOrNull() + { + if (Type != null) + { + return Type.FullName; + } + + if (Src != null) + { + return Src + .RemovePreFix("/") + .RemovePostFix(StringComparison.OrdinalIgnoreCase, ".css") + .Replace("/", "."); + } + + throw new AbpException("abp-style tag helper requires to set either src or type!"); + } + + public BundleTagHelperItem CreateBundleTagHelperItem() + { + if (Type != null) + { + return new BundleTagHelperItem(Type); + } + + if (Src != null) + { + return new BundleTagHelperItem(Src); + } + + throw new AbpException("abp-style tag helper requires to set either src or type!"); + } + } +} \ No newline at end of file diff --git a/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/TagHelpers/AbpStyleTagHelperService.cs b/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/TagHelpers/AbpStyleTagHelperService.cs new file mode 100644 index 0000000000..4755c41231 --- /dev/null +++ b/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/TagHelpers/AbpStyleTagHelperService.cs @@ -0,0 +1,48 @@ +using System; +using System.Collections.Generic; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Razor.TagHelpers; +using Volo.Abp.AspNetCore.VirtualFileSystem; + +namespace Volo.Abp.AspNetCore.Mvc.UI.Bundling.TagHelpers +{ + public class AbpStyleTagHelperService : AbpBundleTagHelperServiceBase + { + 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 bundleItems) + { + BundleManager.CreateStyleBundle( + bundleName, + configuration => bundleItems.ForEach(bi => bi.AddToConfiguration(configuration)) + ); + } + + protected override IReadOnlyList GetBundleFiles(string bundleName) + { + return BundleManager.GetStyleBundleFiles(bundleName); + } + + protected override void AddHtmlTag(TagHelperContext context, TagHelperOutput output, string file) + { + output.Content.AppendHtml($"{Environment.NewLine}"); + } + + protected override Task> GetBundleItems(TagHelperContext context, TagHelperOutput output) + { + return Task.FromResult(new List + { + TagHelper.CreateBundleTagHelperItem() + }); + } + } +} \ No newline at end of file diff --git a/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/TagHelpers/IBundleTagHelper.cs b/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/TagHelpers/IBundleTagHelper.cs index c502523e1d..fce43070ae 100644 --- a/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/TagHelpers/IBundleTagHelper.cs +++ b/src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/TagHelpers/IBundleTagHelper.cs @@ -2,6 +2,6 @@ { public interface IBundleTagHelper { - string Name { get; } + string GetNameOrNull(); } } \ No newline at end of file