mirror of https://github.com/abpframework/abp.git
8 changed files with 227 additions and 2 deletions
@ -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<AbpScriptTagHelper, AbpScriptTagHelperService>, IBundleTagHelper |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// A file path.
|
||||
|
/// </summary>
|
||||
|
public string Src { get; set; } |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// A bundle contributor type.
|
||||
|
/// </summary>
|
||||
|
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!"); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -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<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 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}"); |
||||
|
} |
||||
|
|
||||
|
protected override Task<List<BundleTagHelperItem>> GetBundleItems(TagHelperContext context, TagHelperOutput output) |
||||
|
{ |
||||
|
return Task.FromResult(new List<BundleTagHelperItem> |
||||
|
{ |
||||
|
TagHelper.CreateBundleTagHelperItem() |
||||
|
}); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -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<AbpStyleTagHelper, AbpStyleTagHelperService>, IBundleTagHelper |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// A file path.
|
||||
|
/// </summary>
|
||||
|
public string Src { get; set; } |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// A bundle contributor type.
|
||||
|
/// </summary>
|
||||
|
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!"); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -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<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 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}"); |
||||
|
} |
||||
|
|
||||
|
protected override Task<List<BundleTagHelperItem>> GetBundleItems(TagHelperContext context, TagHelperOutput output) |
||||
|
{ |
||||
|
return Task.FromResult(new List<BundleTagHelperItem> |
||||
|
{ |
||||
|
TagHelper.CreateBundleTagHelperItem() |
||||
|
}); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue