From 41ea2d625ec354dab4462735242b7a96f204e117 Mon Sep 17 00:00:00 2001 From: Yunus Emre Kalkan Date: Mon, 18 Feb 2019 15:36:47 +0300 Subject: [PATCH 1/2] Create TagHelperAttributeExtensions.cs --- .../TagHelperAttributeExtensions.cs | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/TagHelpers/Extensions/TagHelperAttributeExtensions.cs diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/TagHelpers/Extensions/TagHelperAttributeExtensions.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/TagHelpers/Extensions/TagHelperAttributeExtensions.cs new file mode 100644 index 0000000000..ef581529a6 --- /dev/null +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/TagHelpers/Extensions/TagHelperAttributeExtensions.cs @@ -0,0 +1,25 @@ +using Microsoft.AspNetCore.Razor.TagHelpers; +using System.Collections.Generic; + +namespace Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Extensions +{ + public static class TagHelperAttributeExtensions + { + public static string ToHtmlAttributeAsString(this TagHelperAttribute attribute) + { + return attribute.Name + "=\"" + attribute.Value + "\""; + } + + public static string ToHtmlAttributesAsString(this List attributes) + { + var attributesAsString = ""; + + foreach (var attribute in attributes) + { + attributesAsString += attribute.ToHtmlAttributeAsString() + " "; + } + + return attributesAsString; + } + } +} From 734534052af99df735a83efad320721e636aba03 Mon Sep 17 00:00:00 2001 From: Yunus Emre Kalkan Date: Mon, 18 Feb 2019 15:37:24 +0300 Subject: [PATCH 2/2] Tab tag helpers: content and header attributes --- .../TagHelpers/Tab/AbpTabTagHelperService.cs | 34 ++++++++++++++++--- 1 file changed, 29 insertions(+), 5 deletions(-) diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/TagHelpers/Tab/AbpTabTagHelperService.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/TagHelpers/Tab/AbpTabTagHelperService.cs index ee90724c1a..2de18d0592 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/TagHelpers/Tab/AbpTabTagHelperService.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/TagHelpers/Tab/AbpTabTagHelperService.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using System.Linq; using System.Threading.Tasks; using Microsoft.AspNetCore.Razor.TagHelpers; using Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Extensions; @@ -13,7 +14,7 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Tab var innerContent = await output.GetChildContentAsync(); var tabHeader = GetTabHeaderItem(context, output); - var tabContent = GetTabContentItem(innerContent.GetContent()); + var tabContent = GetTabContentItem(context, output, innerContent.GetContent()); var tabHeaderItems = context.GetValue>(TabItems); @@ -30,23 +31,31 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Tab var link = TagHelper.Name; var control = TagHelper.Name; var title = TagHelper.Title; + var attributes = GetTabHeaderAttributes(context, output); + + var classAttributesAsString = attributes.Where(a=>a.Name == "class").ToList().Select(a=>a.Value).JoinAsString(" "); + var otherAttributesAsString = attributes.Where(a => a.Name != "class").ToList().ToHtmlAttributesAsString(); if (!string.IsNullOrWhiteSpace(TagHelper.ParentDropdownName)) { - return "" + title + ""; + return "" + title + ""; } - return "
  • " + + return "
  • " + title + "
  • "; } - protected virtual string GetTabContentItem(string content) + protected virtual string GetTabContentItem(TagHelperContext context, TagHelperOutput output, string content) { var headerId = TagHelper.Name + "-tab"; var id = TagHelper.Name; + var attributes = GetTabContentAttributes(context, output); + + var classAttributesAsString = attributes.Where(a => a.Name == "class").ToList().Select(a => a.Name).JoinAsString(" "); + var otherAttributesAsString = attributes.Where(a => a.Name != "class").ToList().ToHtmlAttributesAsString(); - return "
    " + + return "
    " + content + "
    "; } @@ -58,5 +67,20 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Tab TagHelper.Name = TabItemNamePlaceHolder; } } + + protected virtual List GetTabContentAttributes(TagHelperContext context, TagHelperOutput output) { + var contentprefix = "content-"; + return GetTabAttributesByPrefix(output.Attributes, contentprefix); + } + + protected virtual List GetTabHeaderAttributes(TagHelperContext context, TagHelperOutput output) { + var headerprefix = "header-"; + return GetTabAttributesByPrefix(output.Attributes, headerprefix); + } + + private List GetTabAttributesByPrefix(TagHelperAttributeList attributes, string prefix) { + return attributes.Where(a=>a.Name.StartsWith(prefix)) + .Select(a=> new TagHelperAttribute(a.Name.Substring(prefix.Length), a.Value)).ToList(); + } } } \ No newline at end of file