Skip to content
This repository has been archived by the owner on Dec 14, 2018. It is now read-only.

Commit

Permalink
Issue #5310 (#5334)
Browse files Browse the repository at this point in the history
* Issue #5310
  • Loading branch information
cjrosa authored and dougbu committed Sep 30, 2016
1 parent a04f5cb commit 60d600d
Show file tree
Hide file tree
Showing 10 changed files with 193 additions and 47 deletions.
27 changes: 1 addition & 26 deletions src/Microsoft.AspNetCore.Mvc.Razor.Host/MvcRazorParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ namespace Microsoft.AspNetCore.Mvc.Razor
public class MvcRazorParser : RazorParser
{
private readonly IEnumerable<TagHelperDirectiveDescriptor> _viewImportsDirectiveDescriptors;
private readonly string _modelExpressionTypeName;

/// <summary>
/// Initializes a new instance of <see cref="MvcRazorParser"/>.
Expand Down Expand Up @@ -63,8 +62,6 @@ public MvcRazorParser(
_viewImportsDirectiveDescriptors = GetTagHelperDirectiveDescriptors(
inheritedChunkTrees,
defaultInheritedChunks);

_modelExpressionTypeName = modelExpressionTypeName;
}

/// <inheritdoc />
Expand All @@ -87,29 +84,7 @@ protected override IEnumerable<TagHelperDescriptor> GetTagHelperDescriptors(
_viewImportsDirectiveDescriptors,
errorSink);

var descriptors = visitor.GetDescriptors(documentRoot);
foreach (var descriptor in descriptors)
{
foreach (var attributeDescriptor in descriptor.Attributes)
{
if (attributeDescriptor.IsIndexer &&
string.Equals(
attributeDescriptor.TypeName,
_modelExpressionTypeName,
StringComparison.Ordinal))
{
errorSink.OnError(
SourceLocation.Undefined,
Resources.FormatMvcRazorParser_InvalidPropertyType(
descriptor.TypeName,
attributeDescriptor.Name,
_modelExpressionTypeName),
length: 0);
}
}
}

return descriptors;
return visitor.GetDescriptors(documentRoot);
}

private static IEnumerable<TagHelperDirectiveDescriptor> GetTagHelperDirectiveDescriptors(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ <h3 style="font-family: cursive;">Current Tag Cloud from ViewComponentHelper:</h
<br /><p><em>Rendering Template:</em></p>
<div><h3 style="font-family: cursive;">Tag Cloud from Template: </h3>Lorem,ipsum,dolor,sit,amet,consectetur,adipisicing,elit,sed,do,eiusmod,tempor,incididunt,ut,labore,et,dolore,magna,aliquaUt,enim</div></div>

<div>
<h3 style="font-family: cursive;">Dictionary Valued Model Expression</h3>
<div><ul><li>TagsToShow</li><li>Version.Build</li></ul></div>
</div>


<hr />
<footer>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System.Collections.Generic;
using Microsoft.AspNetCore.Mvc.ViewFeatures;
using Microsoft.AspNetCore.Razor.TagHelpers;

namespace Microsoft.AspNetCore.Mvc.Razor
{
[HtmlTargetElement(Attributes = "prefix-*")]
public class DictionaryPrefixTestTagHelper : TagHelper
{
[HtmlAttributeName(DictionaryAttributePrefix = "prefix-")]
public IDictionary<string, ModelExpression> PrefixValues { get; set; } = new Dictionary<string, ModelExpression>();

public override void Process(TagHelperContext context, TagHelperOutput output)
{
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public void Accept_CorrectlyGeneratesCode(IList<Chunk> chunks)
var resultOutput = writer.GenerateCode();

#if GENERATE_BASELINES
if (!string.Equals(expectedOutput, resultOutput, StringComparison.Ordinal))
if (!string.Equals(expectedOutput, resultOutput, System.StringComparison.Ordinal))
{
ResourceFile.UpdateFile(assembly, path, expectedOutput, resultOutput);
}
Expand Down
52 changes: 42 additions & 10 deletions test/Microsoft.AspNetCore.Mvc.Razor.Host.Test/MvcRazorHostTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -142,30 +142,62 @@ public void MvcRazorHost_GeneratesTagHelperModelExpressionCode_DesignTime()
generatedLineIndex: 17,
generatedCharacterIndex: 48,
contentLength: 91),
BuildLineMapping(
documentAbsoluteIndex: 140,
documentLineIndex: 3,
documentCharacterIndex: 14,
generatedAbsoluteIndex: 797,
generatedLineIndex: 18,
generatedCharacterIndex: 48,
contentLength: 102),
BuildLineMapping(
documentAbsoluteIndex: 7,
documentLineIndex: 0,
documentCharacterIndex: 7,
generatedAbsoluteIndex: 836,
generatedLineIndex: 19,
generatedAbsoluteIndex: 990,
generatedLineIndex: 20,
generatedCharacterIndex: 28,
contentLength: 8),
BuildLineMapping(
documentAbsoluteIndex: 145,
documentLineIndex: 4,
documentAbsoluteIndex: 263,
documentLineIndex: 5,
documentCharacterIndex: 17,
generatedAbsoluteIndex: 2530,
generatedLineIndex: 50,
generatedAbsoluteIndex: 2841,
generatedLineIndex: 52,
generatedCharacterIndex: 133,
contentLength: 3),
BuildLineMapping(
documentAbsoluteIndex: 172,
documentLineIndex: 5,
documentAbsoluteIndex: 290,
documentLineIndex: 6,
documentCharacterIndex: 18,
generatedAbsoluteIndex: 2897,
generatedLineIndex: 56,
generatedAbsoluteIndex: 3208,
generatedLineIndex: 58,
generatedCharacterIndex: 125,
contentLength: 5),
BuildLineMapping(
documentAbsoluteIndex: 322,
documentLineIndex: 8,
documentCharacterIndex: 19,
generatedAbsoluteIndex: 3627,
generatedLineIndex: 64,
generatedCharacterIndex: 153,
contentLength: 5),
BuildLineMapping(
documentAbsoluteIndex: 357,
documentLineIndex: 9,
documentCharacterIndex: 19,
generatedAbsoluteIndex: 4055,
generatedLineIndex: 70,
generatedCharacterIndex: 161,
contentLength: 4),
BuildLineMapping(
documentAbsoluteIndex: 378,
documentLineIndex: 9,
documentCharacterIndex: 40,
generatedAbsoluteIndex: 4317,
generatedLineIndex: 75,
generatedCharacterIndex: 163,
contentLength: 6),
};

// Act and Assert
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
@model DateTime

@addTagHelper Microsoft.AspNetCore.Mvc.Razor.InputTestTagHelper, Microsoft.AspNetCore.Mvc.Razor.Host.Test
@addTagHelper Microsoft.AspNetCore.Mvc.Razor.DictionaryPrefixTestTagHelper, Microsoft.AspNetCore.Mvc.Razor.Host.Test

<input-test for="Now" />
<input-test for="@Model" />
<input-test for="@Model" />

<div prefix-test="@Model" ></div>
<span prefix-hour="Hour" prefix-minute="Minute"></span>
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ private void @__RazorDesignTimeHelpers__()
#pragma warning disable 219
string __tagHelperDirectiveSyntaxHelper = null;
__tagHelperDirectiveSyntaxHelper = "Microsoft.AspNetCore.Mvc.Razor.InputTestTagHelper, Microsoft.AspNetCore.Mvc.Razor.Host.Test";
__tagHelperDirectiveSyntaxHelper = "Microsoft.AspNetCore.Mvc.Razor.DictionaryPrefixTestTagHelper, Microsoft.AspNetCore.Mvc.Razor.Host.Test";
#line 1 "testfiles/input/modelexpressiontaghelper.cshtml"
var __modelHelper = default(DateTime);

Expand All @@ -25,6 +26,7 @@ private void @__RazorDesignTimeHelpers__()
}
#line hidden
private global::Microsoft.AspNetCore.Mvc.Razor.InputTestTagHelper __Microsoft_AspNetCore_Mvc_Razor_InputTestTagHelper = null;
private global::Microsoft.AspNetCore.Mvc.Razor.DictionaryPrefixTestTagHelper __Microsoft_AspNetCore_Mvc_Razor_DictionaryPrefixTestTagHelper = null;
#line hidden
public testfiles_input_modelexpressiontaghelper_cshtml()
{
Expand All @@ -47,15 +49,32 @@ public testfiles_input_modelexpressiontaghelper_cshtml()
public override async Task ExecuteAsync()
{
__Microsoft_AspNetCore_Mvc_Razor_InputTestTagHelper = CreateTagHelper<global::Microsoft.AspNetCore.Mvc.Razor.InputTestTagHelper>();
#line 5 "testfiles/input/modelexpressiontaghelper.cshtml"
#line 6 "testfiles/input/modelexpressiontaghelper.cshtml"
__Microsoft_AspNetCore_Mvc_Razor_InputTestTagHelper.For = ModelExpressionProvider.CreateModelExpression(ViewData, __model => __model.Now);

#line default
#line hidden
__Microsoft_AspNetCore_Mvc_Razor_InputTestTagHelper = CreateTagHelper<global::Microsoft.AspNetCore.Mvc.Razor.InputTestTagHelper>();
#line 6 "testfiles/input/modelexpressiontaghelper.cshtml"
#line 7 "testfiles/input/modelexpressiontaghelper.cshtml"
__Microsoft_AspNetCore_Mvc_Razor_InputTestTagHelper.For = ModelExpressionProvider.CreateModelExpression(ViewData, __model => Model);

#line default
#line hidden
__Microsoft_AspNetCore_Mvc_Razor_DictionaryPrefixTestTagHelper = CreateTagHelper<global::Microsoft.AspNetCore.Mvc.Razor.DictionaryPrefixTestTagHelper>();
#line 9 "testfiles/input/modelexpressiontaghelper.cshtml"
__Microsoft_AspNetCore_Mvc_Razor_DictionaryPrefixTestTagHelper.PrefixValues["test"] = ModelExpressionProvider.CreateModelExpression(ViewData, __model => Model);

#line default
#line hidden
__Microsoft_AspNetCore_Mvc_Razor_DictionaryPrefixTestTagHelper = CreateTagHelper<global::Microsoft.AspNetCore.Mvc.Razor.DictionaryPrefixTestTagHelper>();
#line 10 "testfiles/input/modelexpressiontaghelper.cshtml"
__Microsoft_AspNetCore_Mvc_Razor_DictionaryPrefixTestTagHelper.PrefixValues["hour"] = ModelExpressionProvider.CreateModelExpression(ViewData, __model => __model.Hour);

#line default
#line hidden
#line 10 "testfiles/input/modelexpressiontaghelper.cshtml"
__Microsoft_AspNetCore_Mvc_Razor_DictionaryPrefixTestTagHelper.PrefixValues["minute"] = ModelExpressionProvider.CreateModelExpression(ViewData, __model => __model.Minute);

#line default
#line hidden
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#pragma checksum "TestFiles/Input/ModelExpressionTagHelper.cshtml" "{ff1816ec-aa5e-4d10-87f7-6f4963833460}" "bb128a8b2ca348e77a9b5481e541b5a8bf82de0b"
#pragma checksum "TestFiles/Input/ModelExpressionTagHelper.cshtml" "{ff1816ec-aa5e-4d10-87f7-6f4963833460}" "faaab08eebb321aea098bd40df018e89cd247b6f"
namespace AspNetCore
{
using System;
Expand All @@ -19,6 +19,7 @@ public class TestFiles_Input_ModelExpressionTagHelper_cshtml : Microsoft.AspNetC
private global::Microsoft.AspNetCore.Razor.Runtime.TagHelpers.TagHelperRunner __tagHelperRunner = null;
private global::Microsoft.AspNetCore.Razor.Runtime.TagHelpers.TagHelperScopeManager __tagHelperScopeManager = null;
private global::Microsoft.AspNetCore.Mvc.Razor.InputTestTagHelper __Microsoft_AspNetCore_Mvc_Razor_InputTestTagHelper = null;
private global::Microsoft.AspNetCore.Mvc.Razor.DictionaryPrefixTestTagHelper __Microsoft_AspNetCore_Mvc_Razor_DictionaryPrefixTestTagHelper = null;
#line hidden
public TestFiles_Input_ModelExpressionTagHelper_cshtml()
{
Expand All @@ -42,41 +43,93 @@ public override async Task ExecuteAsync()
{
__tagHelperRunner = __tagHelperRunner ?? new global::Microsoft.AspNetCore.Razor.Runtime.TagHelpers.TagHelperRunner();
__tagHelperScopeManager = __tagHelperScopeManager ?? new global::Microsoft.AspNetCore.Razor.Runtime.TagHelpers.TagHelperScopeManager(StartTagHelperWritingScope, EndTagHelperWritingScope);
BeginContext(126, 2, true);
BeginContext(244, 2, true);
WriteLiteral("\r\n");
EndContext();
__tagHelperExecutionContext = __tagHelperScopeManager.Begin("input-test", global::Microsoft.AspNetCore.Razor.TagHelpers.TagMode.SelfClosing, "test", async() => {
}
);
__Microsoft_AspNetCore_Mvc_Razor_InputTestTagHelper = CreateTagHelper<global::Microsoft.AspNetCore.Mvc.Razor.InputTestTagHelper>();
__tagHelperExecutionContext.Add(__Microsoft_AspNetCore_Mvc_Razor_InputTestTagHelper);
#line 5 "TestFiles/Input/ModelExpressionTagHelper.cshtml"
#line 6 "TestFiles/Input/ModelExpressionTagHelper.cshtml"
__Microsoft_AspNetCore_Mvc_Razor_InputTestTagHelper.For = ModelExpressionProvider.CreateModelExpression(ViewData, __model => __model.Now);

#line default
#line hidden
__tagHelperExecutionContext.AddTagHelperAttribute("for", __Microsoft_AspNetCore_Mvc_Razor_InputTestTagHelper.For, global::Microsoft.AspNetCore.Razor.TagHelpers.HtmlAttributeValueStyle.DoubleQuotes);
await __tagHelperRunner.RunAsync(__tagHelperExecutionContext);
BeginContext(128, 24, false);
BeginContext(246, 24, false);
Write(__tagHelperExecutionContext.Output);
EndContext();
__tagHelperExecutionContext = __tagHelperScopeManager.End();
BeginContext(152, 2, true);
BeginContext(270, 2, true);
WriteLiteral("\r\n");
EndContext();
__tagHelperExecutionContext = __tagHelperScopeManager.Begin("input-test", global::Microsoft.AspNetCore.Razor.TagHelpers.TagMode.SelfClosing, "test", async() => {
}
);
__Microsoft_AspNetCore_Mvc_Razor_InputTestTagHelper = CreateTagHelper<global::Microsoft.AspNetCore.Mvc.Razor.InputTestTagHelper>();
__tagHelperExecutionContext.Add(__Microsoft_AspNetCore_Mvc_Razor_InputTestTagHelper);
#line 6 "TestFiles/Input/ModelExpressionTagHelper.cshtml"
#line 7 "TestFiles/Input/ModelExpressionTagHelper.cshtml"
__Microsoft_AspNetCore_Mvc_Razor_InputTestTagHelper.For = ModelExpressionProvider.CreateModelExpression(ViewData, __model => Model);

#line default
#line hidden
__tagHelperExecutionContext.AddTagHelperAttribute("for", __Microsoft_AspNetCore_Mvc_Razor_InputTestTagHelper.For, global::Microsoft.AspNetCore.Razor.TagHelpers.HtmlAttributeValueStyle.DoubleQuotes);
await __tagHelperRunner.RunAsync(__tagHelperExecutionContext);
BeginContext(154, 27, false);
BeginContext(272, 27, false);
Write(__tagHelperExecutionContext.Output);
EndContext();
__tagHelperExecutionContext = __tagHelperScopeManager.End();
BeginContext(299, 4, true);
WriteLiteral("\r\n\r\n");
EndContext();
__tagHelperExecutionContext = __tagHelperScopeManager.Begin("div", global::Microsoft.AspNetCore.Razor.TagHelpers.TagMode.StartTagAndEndTag, "test", async() => {
}
);
__Microsoft_AspNetCore_Mvc_Razor_DictionaryPrefixTestTagHelper = CreateTagHelper<global::Microsoft.AspNetCore.Mvc.Razor.DictionaryPrefixTestTagHelper>();
__tagHelperExecutionContext.Add(__Microsoft_AspNetCore_Mvc_Razor_DictionaryPrefixTestTagHelper);
if (__Microsoft_AspNetCore_Mvc_Razor_DictionaryPrefixTestTagHelper.PrefixValues == null)
{
throw new InvalidOperationException(InvalidTagHelperIndexerAssignment("prefix-test", "Microsoft.AspNetCore.Mvc.Razor.DictionaryPrefixTestTagHelper", "PrefixValues"));
}
#line 9 "TestFiles/Input/ModelExpressionTagHelper.cshtml"
__Microsoft_AspNetCore_Mvc_Razor_DictionaryPrefixTestTagHelper.PrefixValues["test"] = ModelExpressionProvider.CreateModelExpression(ViewData, __model => Model);

#line default
#line hidden
__tagHelperExecutionContext.AddTagHelperAttribute("prefix-test", __Microsoft_AspNetCore_Mvc_Razor_DictionaryPrefixTestTagHelper.PrefixValues["test"], global::Microsoft.AspNetCore.Razor.TagHelpers.HtmlAttributeValueStyle.DoubleQuotes);
await __tagHelperRunner.RunAsync(__tagHelperExecutionContext);
BeginContext(303, 33, false);
Write(__tagHelperExecutionContext.Output);
EndContext();
__tagHelperExecutionContext = __tagHelperScopeManager.End();
BeginContext(336, 2, true);
WriteLiteral("\r\n");
EndContext();
__tagHelperExecutionContext = __tagHelperScopeManager.Begin("span", global::Microsoft.AspNetCore.Razor.TagHelpers.TagMode.StartTagAndEndTag, "test", async() => {
}
);
__Microsoft_AspNetCore_Mvc_Razor_DictionaryPrefixTestTagHelper = CreateTagHelper<global::Microsoft.AspNetCore.Mvc.Razor.DictionaryPrefixTestTagHelper>();
__tagHelperExecutionContext.Add(__Microsoft_AspNetCore_Mvc_Razor_DictionaryPrefixTestTagHelper);
if (__Microsoft_AspNetCore_Mvc_Razor_DictionaryPrefixTestTagHelper.PrefixValues == null)
{
throw new InvalidOperationException(InvalidTagHelperIndexerAssignment("prefix-hour", "Microsoft.AspNetCore.Mvc.Razor.DictionaryPrefixTestTagHelper", "PrefixValues"));
}
#line 10 "TestFiles/Input/ModelExpressionTagHelper.cshtml"
__Microsoft_AspNetCore_Mvc_Razor_DictionaryPrefixTestTagHelper.PrefixValues["hour"] = ModelExpressionProvider.CreateModelExpression(ViewData, __model => __model.Hour);

#line default
#line hidden
__tagHelperExecutionContext.AddTagHelperAttribute("prefix-hour", __Microsoft_AspNetCore_Mvc_Razor_DictionaryPrefixTestTagHelper.PrefixValues["hour"], global::Microsoft.AspNetCore.Razor.TagHelpers.HtmlAttributeValueStyle.DoubleQuotes);
#line 10 "TestFiles/Input/ModelExpressionTagHelper.cshtml"
__Microsoft_AspNetCore_Mvc_Razor_DictionaryPrefixTestTagHelper.PrefixValues["minute"] = ModelExpressionProvider.CreateModelExpression(ViewData, __model => __model.Minute);

#line default
#line hidden
__tagHelperExecutionContext.AddTagHelperAttribute("prefix-minute", __Microsoft_AspNetCore_Mvc_Razor_DictionaryPrefixTestTagHelper.PrefixValues["minute"], global::Microsoft.AspNetCore.Razor.TagHelpers.HtmlAttributeValueStyle.DoubleQuotes);
await __tagHelperRunner.RunAsync(__tagHelperExecutionContext);
BeginContext(338, 55, false);
Write(__tagHelperExecutionContext.Output);
EndContext();
__tagHelperExecutionContext = __tagHelperScopeManager.End();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System.Collections.Generic;
using Microsoft.AspNetCore.Mvc.Rendering;
using Microsoft.AspNetCore.Mvc.ViewFeatures;
using Microsoft.AspNetCore.Razor.TagHelpers;

namespace TagHelpersWebSite.TagHelpers
{
[HtmlTargetElement(Attributes = "prefix-*")]
public class DictionaryPrefixTestTagHelper : TagHelper
{
[HtmlAttributeName(DictionaryAttributePrefix = "prefix-")]
public IDictionary<string, ModelExpression> PrefixValues { get; set; } = new Dictionary<string, ModelExpression>();

public override void Process(TagHelperContext context, TagHelperOutput output)
{
var ulTag = new TagBuilder("ul");

foreach (var item in PrefixValues)
{
var liTag = new TagBuilder("li");

liTag.InnerHtml.Append(item.Value.Name);

ulTag.InnerHtml.AppendHtml(liTag);
}

output.Content.SetHtmlContent(ulTag);
}
}
}
Loading

0 comments on commit 60d600d

Please sign in to comment.