Skip to content

Commit

Permalink
Add "property" attribute to the meta tag helper. (#3211)
Browse files Browse the repository at this point in the history
  • Loading branch information
scleaver authored and sebastienros committed Feb 28, 2019
1 parent eb39bbd commit 3032e20
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using Microsoft.AspNetCore.Html;
using Microsoft.AspNetCore.Mvc.Rendering;
Expand All @@ -14,13 +14,16 @@ public MetaEntry()
_builder.TagRenderMode = TagRenderMode.SelfClosing;
}

public MetaEntry(string name = null, string content = null, string httpEquiv = null, string charset = null) : this()
public MetaEntry(string name = null, string property = null, string content = null, string httpEquiv = null, string charset = null) : this()
{
if (!String.IsNullOrEmpty(name))
{
Name = name;
}

if (!String.IsNullOrEmpty(property))
{
Property = property;
}
if (!String.IsNullOrEmpty(content))
{
Content = content;
Expand All @@ -35,7 +38,6 @@ public MetaEntry(string name = null, string content = null, string httpEquiv = n
{
Charset = charset;
}

}

public static MetaEntry Combine(MetaEntry meta1, MetaEntry meta2, string contentSeparator)
Expand Down Expand Up @@ -82,6 +84,17 @@ public string Name
set { SetAttribute("name", value); }
}

public string Property
{
get
{
string value;
_builder.Attributes.TryGetValue("property", out value);
return value;
}
set { SetAttribute("property", value); }
}

public string Content
{
get
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ public void RegisterMeta(MetaEntry meta)
_metas = new Dictionary<string, MetaEntry>();
}

var index = meta.Name ?? meta.HttpEquiv ?? "charset";
var index = meta.Name ?? meta.Property ?? meta.HttpEquiv ?? "charset";

_metas[index] = meta;
}
Expand All @@ -444,7 +444,7 @@ public void AppendMeta(MetaEntry meta, string contentSeparator)
return;
}

var index = meta.Name ?? meta.HttpEquiv;
var index = meta.Name ?? meta.Property ?? meta.HttpEquiv;

if (String.IsNullOrEmpty(index))
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
using System;
using System;
using Microsoft.AspNetCore.Razor.TagHelpers;

namespace OrchardCore.ResourceManagement.TagHelpers
{

[HtmlTargetElement("meta", Attributes = NameAttributeName)]
[HtmlTargetElement("meta", Attributes = PropertyAttributeName)]
public class MetaTagHelper : TagHelper
{
private const string NameAttributeName = "asp-name";
private const string PropertyAttributeName = "asp-property";

[HtmlAttributeName(NameAttributeName)]
public string Name { get; set; }

[HtmlAttributeName(PropertyAttributeName)]
public string Property { get; set; }

public string Content { get; set; }

public string HttpEquiv { get; set; }
Expand All @@ -29,11 +34,11 @@ public MetaTagHelper(IResourceManager resourceManager)

public override void Process(TagHelperContext context, TagHelperOutput output)
{
var metaEntry = new MetaEntry(Name, Content, HttpEquiv, Charset);
var metaEntry = new MetaEntry(Name, Property, Content, HttpEquiv, Charset);

foreach (var attribute in output.Attributes)
{
if (String.Equals(attribute.Name, "name", StringComparison.OrdinalIgnoreCase))
if (String.Equals(attribute.Name, "name", StringComparison.OrdinalIgnoreCase) || String.Equals(attribute.Name, "property", StringComparison.OrdinalIgnoreCase))
{
continue;
}
Expand Down

0 comments on commit 3032e20

Please sign in to comment.