Enabled `LinkTagHelper` to be written in the void format.

- Updated existing tests to showcase it can be written as just the start tag.
This commit is contained in:
N. Taylor Mullen 2015-08-13 10:47:51 -07:00
parent e1572f98ce
commit 21d96eb16a
4 changed files with 26 additions and 26 deletions

View File

@ -21,15 +21,15 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
/// <remarks>
/// The tag helper won't process for cases with just the 'href' attribute.
/// </remarks>
[TargetElement("link", Attributes = HrefIncludeAttributeName)]
[TargetElement("link", Attributes = HrefExcludeAttributeName)]
[TargetElement("link", Attributes = FallbackHrefAttributeName)]
[TargetElement("link", Attributes = FallbackHrefIncludeAttributeName)]
[TargetElement("link", Attributes = FallbackHrefExcludeAttributeName)]
[TargetElement("link", Attributes = FallbackTestClassAttributeName)]
[TargetElement("link", Attributes = FallbackTestPropertyAttributeName)]
[TargetElement("link", Attributes = FallbackTestValueAttributeName)]
[TargetElement("link", Attributes = AppendVersionAttributeName)]
[TargetElement("link", Attributes = HrefIncludeAttributeName, TagStructure = TagStructure.WithoutEndTag)]
[TargetElement("link", Attributes = HrefExcludeAttributeName, TagStructure = TagStructure.WithoutEndTag)]
[TargetElement("link", Attributes = FallbackHrefAttributeName, TagStructure = TagStructure.WithoutEndTag)]
[TargetElement("link", Attributes = FallbackHrefIncludeAttributeName, TagStructure = TagStructure.WithoutEndTag)]
[TargetElement("link", Attributes = FallbackHrefExcludeAttributeName, TagStructure = TagStructure.WithoutEndTag)]
[TargetElement("link", Attributes = FallbackTestClassAttributeName, TagStructure = TagStructure.WithoutEndTag)]
[TargetElement("link", Attributes = FallbackTestPropertyAttributeName, TagStructure = TagStructure.WithoutEndTag)]
[TargetElement("link", Attributes = FallbackTestValueAttributeName, TagStructure = TagStructure.WithoutEndTag)]
[TargetElement("link", Attributes = AppendVersionAttributeName, TagStructure = TagStructure.WithoutEndTag)]
public class LinkTagHelper : UrlResolutionTagHelper
{
private static readonly string Namespace = typeof(LinkTagHelper).Namespace;

View File

@ -17,7 +17,7 @@
<link rel="stylesheet" title="&quot;the&quot; title" href="HtmlEncode[[/site.css]]" /><link rel="stylesheet" title="&quot;the&quot; title" href="HtmlEncode[[/sub/site2.css]]" />
<!-- Globbed link tag missing include -->
<link rel="stylesheet" />
<link rel="stylesheet">
<!-- Globbed link tag missing include but with static href -->
<link rel="stylesheet" href="HtmlEncode[[/site.css]]" />
@ -58,7 +58,7 @@
<meta name="x-stylesheet-fallback-test" class="HtmlEncode[[hidden]]" /><script>!function(a,b,c){var d,e=document,f=e.getElementsByTagName("SCRIPT"),g=f[f.length-1].previousElementSibling,h=e.defaultView&&e.defaultView.getComputedStyle?e.defaultView.getComputedStyle(g):g.currentStyle;if(h&&h[a]!==b)for(d=0;d<c.length;d++)e.write('<link rel="stylesheet" href="'+c[d]+'"/>')}("JavaScriptEncode[[visibility]]","JavaScriptEncode[[hidden]]",["JavaScriptEncode[[/site.css]]"]);</script>
<!-- Fallback to static href with no primary href -->
<link rel="stylesheet" data-extra="test" />
<link rel="stylesheet" data-extra="test">
<meta name="x-stylesheet-fallback-test" class="HtmlEncode[[hidden]]" /><script>!function(a,b,c){var d,e=document,f=e.getElementsByTagName("SCRIPT"),g=f[f.length-1].previousElementSibling,h=e.defaultView&&e.defaultView.getComputedStyle?e.defaultView.getComputedStyle(g):g.currentStyle;if(h&&h[a]!==b)for(d=0;d<c.length;d++)e.write('<link rel="stylesheet" href="'+c[d]+'"/>')}("JavaScriptEncode[[visibility]]","JavaScriptEncode[[hidden]]",["JavaScriptEncode[[/site.css]]"]);</script>
<!-- Fallback to globbed href -->
@ -90,7 +90,7 @@
<meta name="x-stylesheet-fallback-test" class="HtmlEncode[[hidden]]" /><script>!function(a,b,c){var d,e=document,f=e.getElementsByTagName("SCRIPT"),g=f[f.length-1].previousElementSibling,h=e.defaultView&&e.defaultView.getComputedStyle?e.defaultView.getComputedStyle(g):g.currentStyle;if(h&&h[a]!==b)for(d=0;d<c.length;d++)e.write('<link rel="stylesheet" href="'+c[d]+'"/>')}("JavaScriptEncode[[visibility]]","JavaScriptEncode[[hidden]]",["JavaScriptEncode[[/site.css]]"]);</script>
<!-- Fallback from globbed and static href with exclude to globbed href -->
<link rel="stylesheet" data-extra="test" href="HtmlEncode[[site.min.css]]" />
<link rel="stylesheet" data-extra="test" href="HtmlEncode[[site.min.css]]">
<meta name="x-stylesheet-fallback-test" class="HtmlEncode[[hidden]]" /><script>!function(a,b,c){var d,e=document,f=e.getElementsByTagName("SCRIPT"),g=f[f.length-1].previousElementSibling,h=e.defaultView&&e.defaultView.getComputedStyle?e.defaultView.getComputedStyle(g):g.currentStyle;if(h&&h[a]!==b)for(d=0;d<c.length;d++)e.write('<link rel="stylesheet" href="'+c[d]+'"/>')}("JavaScriptEncode[[visibility]]","JavaScriptEncode[[hidden]]",["JavaScriptEncode[[/site.css]]"]);</script>
<!-- Kitchen sink, all the attributes -->
@ -119,7 +119,7 @@
<link rel="stylesheet" href="HtmlEncode[[/site.css?v=XY7YsMemPf8AGU4SIX9ED9eOjK1LOQWu2dmCNmh-pQc]]" />
<!-- Fallback with file version -->
<link rel="stylesheet" data-extra="test" href="HtmlEncode[[/site.min.css]]" />
<link rel="stylesheet" data-extra="test" href="HtmlEncode[[/site.min.css]]">
<meta name="x-stylesheet-fallback-test" class="HtmlEncode[[hidden]]" /><script>!function(a,b,c){var d,e=document,f=e.getElementsByTagName("SCRIPT"),g=f[f.length-1].previousElementSibling,h=e.defaultView&&e.defaultView.getComputedStyle?e.defaultView.getComputedStyle(g):g.currentStyle;if(h&&h[a]!==b)for(d=0;d<c.length;d++)e.write('<link rel="stylesheet" href="'+c[d]+'"/>')}("JavaScriptEncode[[visibility]]","JavaScriptEncode[[hidden]]",["JavaScriptEncode[[/site.css?v=XY7YsMemPf8AGU4SIX9ED9eOjK1LOQWu2dmCNmh-pQc]]"]);</script>
<!-- Globbed link tag with existing file, static href and file version -->
@ -128,6 +128,6 @@
<body>
<h2>Link Tag Helper Test</h2>
</body>
</html>

View File

@ -17,7 +17,7 @@
<link rel="stylesheet" title="&quot;the&quot; title" href="/site.css" /><link rel="stylesheet" title="&quot;the&quot; title" href="/sub/site2.css" />
<!-- Globbed link tag missing include -->
<link rel="stylesheet" />
<link rel="stylesheet">
<!-- Globbed link tag missing include but with static href -->
<link rel="stylesheet" href="/site.css" />
@ -58,7 +58,7 @@
<meta name="x-stylesheet-fallback-test" class="hidden" /><script>!function(a,b,c){var d,e=document,f=e.getElementsByTagName("SCRIPT"),g=f[f.length-1].previousElementSibling,h=e.defaultView&&e.defaultView.getComputedStyle?e.defaultView.getComputedStyle(g):g.currentStyle;if(h&&h[a]!==b)for(d=0;d<c.length;d++)e.write('<link rel="stylesheet" href="'+c[d]+'"/>')}("visibility","hidden",["\/site.css"]);</script>
<!-- Fallback to static href with no primary href -->
<link rel="stylesheet" data-extra="test" />
<link rel="stylesheet" data-extra="test">
<meta name="x-stylesheet-fallback-test" class="hidden" /><script>!function(a,b,c){var d,e=document,f=e.getElementsByTagName("SCRIPT"),g=f[f.length-1].previousElementSibling,h=e.defaultView&&e.defaultView.getComputedStyle?e.defaultView.getComputedStyle(g):g.currentStyle;if(h&&h[a]!==b)for(d=0;d<c.length;d++)e.write('<link rel="stylesheet" href="'+c[d]+'"/>')}("visibility","hidden",["\/site.css"]);</script>
<!-- Fallback to globbed href -->
@ -90,7 +90,7 @@
<meta name="x-stylesheet-fallback-test" class="hidden" /><script>!function(a,b,c){var d,e=document,f=e.getElementsByTagName("SCRIPT"),g=f[f.length-1].previousElementSibling,h=e.defaultView&&e.defaultView.getComputedStyle?e.defaultView.getComputedStyle(g):g.currentStyle;if(h&&h[a]!==b)for(d=0;d<c.length;d++)e.write('<link rel="stylesheet" href="'+c[d]+'"/>')}("visibility","hidden",["\/site.css"]);</script>
<!-- Fallback from globbed and static href with exclude to globbed href -->
<link rel="stylesheet" data-extra="test" href="site.min.css" />
<link rel="stylesheet" data-extra="test" href="site.min.css">
<meta name="x-stylesheet-fallback-test" class="hidden" /><script>!function(a,b,c){var d,e=document,f=e.getElementsByTagName("SCRIPT"),g=f[f.length-1].previousElementSibling,h=e.defaultView&&e.defaultView.getComputedStyle?e.defaultView.getComputedStyle(g):g.currentStyle;if(h&&h[a]!==b)for(d=0;d<c.length;d++)e.write('<link rel="stylesheet" href="'+c[d]+'"/>')}("visibility","hidden",["\/site.css"]);</script>
<!-- Kitchen sink, all the attributes -->
@ -119,7 +119,7 @@
<link rel="stylesheet" href="/site.css?v=XY7YsMemPf8AGU4SIX9ED9eOjK1LOQWu2dmCNmh-pQc" />
<!-- Fallback with file version -->
<link rel="stylesheet" data-extra="test" href="/site.min.css" />
<link rel="stylesheet" data-extra="test" href="/site.min.css">
<meta name="x-stylesheet-fallback-test" class="hidden" /><script>!function(a,b,c){var d,e=document,f=e.getElementsByTagName("SCRIPT"),g=f[f.length-1].previousElementSibling,h=e.defaultView&&e.defaultView.getComputedStyle?e.defaultView.getComputedStyle(g):g.currentStyle;if(h&&h[a]!==b)for(d=0;d<c.length;d++)e.write('<link rel="stylesheet" href="'+c[d]+'"/>')}("visibility","hidden",["\/site.css?v=XY7YsMemPf8AGU4SIX9ED9eOjK1LOQWu2dmCNmh-pQc"]);</script>
<!-- Globbed link tag with existing file, static href and file version -->
@ -128,6 +128,6 @@
<body>
<h2>Link Tag Helper Test</h2>
</body>
</html>

View File

@ -19,7 +19,7 @@
<link asp-href-include=" **/*.css" asp-href-exclude="**/site3*.css" rel="stylesheet" title='"the" title' />
<!-- Globbed link tag missing include -->
<link asp-href-exclude="**/site2.css" rel="stylesheet" />
<link asp-href-exclude="**/site2.css" rel="stylesheet">
<!-- Globbed link tag missing include but with static href -->
<link href="~/site.css" asp-href-exclude="**/site2.css" rel="stylesheet" />
@ -31,7 +31,7 @@
<link asp-href-include="../**/appRoot.css" rel="stylesheet" />
<!-- Globbed link tag with file outside of webroot -->
<link asp-href-include="**/appRoot.css" rel="stylesheet" />
<link asp-href-include="**/appRoot.css" rel="stylesheet">
<!-- Globbed link tag with existing file and static href -->
<link href="~/site.css" asp-href-include="**/site2.css" rel="stylesheet" />
@ -58,7 +58,7 @@
asp-fallback-href="~/site.css"
asp-fallback-test-class="hidden"
asp-fallback-test-property="visibility"
asp-fallback-test-value="hidden" />
asp-fallback-test-value="hidden">
<!-- Fallback from globbed and static href to static href -->
<link href="site.min.css" asp-href-include="site.css" rel="stylesheet" data-extra="test"
@ -80,7 +80,7 @@
asp-fallback-href="~/site.css"
asp-fallback-test-class="hidden"
asp-fallback-test-property="visibility"
asp-fallback-test-value="hidden" />
asp-fallback-test-value="hidden">
<!-- Fallback to globbed href -->
<link href="~/site.min.css" rel="stylesheet" data-extra="test"
@ -141,7 +141,7 @@
asp-fallback-href-include="**/site.css"
asp-fallback-test-class="hidden"
asp-fallback-test-property="visibility"
asp-fallback-test-value="hidden" />
asp-fallback-test-value="hidden">
<!-- Kitchen sink, all the attributes -->
<link href="site.min.css" asp-href-include="**/*.min.css" asp-href-exclude="**/site3.min.css"
@ -197,7 +197,7 @@
asp-fallback-test-class="hidden"
asp-fallback-test-property="visibility"
asp-fallback-test-value="hidden"
asp-append-version="true" />
asp-append-version="true">
<!-- Globbed link tag with existing file, static href and file version -->
<link href="~/site.css" asp-href-include="**/*.css" rel="stylesheet" asp-append-version="true" />
@ -205,6 +205,6 @@
<body>
<h2>Link Tag Helper Test</h2>
</body>
</html>