Browse Source

Added abp-script and abp-style tag helpers.

pull/301/head
Halil ibrahim Kalkan 8 years ago
parent
commit
d06712a3a2
  1. 3
      src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/TagHelpers/AbpBundleTagHelperServiceBase.cs
  2. 5
      src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/TagHelpers/AbpScriptBundleTagHelper.cs
  3. 59
      src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/TagHelpers/AbpScriptTagHelper.cs
  4. 48
      src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/TagHelpers/AbpScriptTagHelperService.cs
  5. 5
      src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/TagHelpers/AbpStyleBundleTagHelper.cs
  6. 59
      src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/TagHelpers/AbpStyleTagHelper.cs
  7. 48
      src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/TagHelpers/AbpStyleTagHelperService.cs
  8. 2
      src/Volo.Abp.AspNetCore.Mvc.UI.Bundling/Volo/Abp/AspNetCore/Mvc/UI/Bundling/TagHelpers/IBundleTagHelper.cs

3
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);

5
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;
}
}
}

59
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<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!");
}
}
}

48
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<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()
});
}
}
}

5
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;
}
}
}

59
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<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!");
}
}
}

48
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<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()
});
}
}
}

2
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();
}
}
Loading…
Cancel
Save