Skip to content

Commit

Permalink
Issue aspnet#5310
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris Rosa authored and Chris Rosa committed Sep 28, 2016
1 parent 0a4c06e commit ac744ca
Show file tree
Hide file tree
Showing 12 changed files with 123 additions and 44 deletions.
24 changes: 1 addition & 23 deletions src/Microsoft.AspNetCore.Mvc.Razor.Host/MvcRazorParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,29 +87,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,17 @@
using Microsoft.AspNetCore.Mvc.ViewFeatures;
using Microsoft.AspNetCore.Razor.TagHelpers;
using System.Collections.Generic;

namespace Microsoft.AspNetCore.Mvc.Razor.Host.Test
{
[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 @@ -7,6 +7,7 @@
using Microsoft.AspNetCore.Razor.Chunks;
using Microsoft.AspNetCore.Razor.CodeGenerators;
using Xunit;
using System;

namespace Microsoft.AspNetCore.Mvc.Razor.Host.Test.Internal
{
Expand Down
37 changes: 27 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,32 +142,49 @@ 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: 2684,
generatedLineIndex: 51,
generatedCharacterIndex: 133,
contentLength: 3),
BuildLineMapping(
documentAbsoluteIndex: 172,
documentLineIndex: 5,
documentAbsoluteIndex: 290,
documentLineIndex: 6,
documentCharacterIndex: 18,
generatedAbsoluteIndex: 2897,
generatedLineIndex: 56,
generatedAbsoluteIndex: 3051,
generatedLineIndex: 57,
generatedCharacterIndex: 125,
contentLength: 5),
BuildLineMapping(
documentAbsoluteIndex: 322,
documentLineIndex: 8,
documentCharacterIndex: 19,
generatedAbsoluteIndex: 3169,
generatedLineIndex: 62,
generatedCharacterIndex: 19,
contentLength: 5),
};


// Act and Assert
RunDesignTimeTest(
host,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
@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>
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 Down Expand Up @@ -47,15 +48,20 @@ 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
#line 9 "testfiles/input/modelexpressiontaghelper.cshtml"
__o = Model;

#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}" "9e4cf6e4030f5e9e62458b1f7608e7a70cfaa4e0"
namespace AspNetCore
{
using System;
Expand Down Expand Up @@ -42,44 +42,57 @@ 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, 8, true);
WriteLiteral("\r\n\r\n<div");
EndContext();
BeginWriteAttribute("prefix-test", " prefix-test=\"", 307, "\"", 327, 1);
#line 9 "TestFiles/Input/ModelExpressionTagHelper.cshtml"
WriteAttributeValue("", 321, Model, 321, 6, false);

#line default
#line hidden
EndWriteAttribute();
BeginContext(328, 8, true);
WriteLiteral(" ></div>");
EndContext();
}
#pragma warning restore 1998
}
Expand Down
2 changes: 2 additions & 0 deletions test/WebSites/TagHelpersWebSite/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ public void Configure(IApplicationBuilder app)
{
app.UseCultureReplacer();

app.UseDeveloperExceptionPage();

app.UseMvcWithDefaultRoute();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using Microsoft.AspNetCore.Mvc.ViewFeatures;
using Microsoft.AspNetCore.Razor.TagHelpers;
using System.Linq;
using System.Collections.Generic;
using Microsoft.AspNetCore.Mvc.Rendering;

namespace Microsoft.AspNetCore.Mvc.Razor.Host.Test
{
[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);
}
}
}
5 changes: 5 additions & 0 deletions test/WebSites/TagHelpersWebSite/Views/Home/Index.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@
}
</div>

<div>
<h3>Dictionary Valued Model Expression</h3>
<div prefix-test1="@Model.TagsToShow" prefix-test2="@Model.Version.Build"></div>
</div>

@section footerContent {
<p condition="Model.Approved" bold surround="section">&copy; @Model.CopyrightYear - My ASP.NET Application</p>
}
3 changes: 2 additions & 1 deletion test/WebSites/TagHelpersWebSite/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"preserveCompilationContext": true
},
"dependencies": {
"Microsoft.AspNetCore.Diagnostics": "1.1.0-alpha1-22244",
"Microsoft.AspNetCore.Mvc": "1.1.0-*",
"Microsoft.AspNetCore.Mvc.TestConfiguration": "1.0.0",
"Microsoft.AspNetCore.Razor.Tools": {
Expand All @@ -19,7 +20,7 @@
"frameworks": {
"net451": {},
"netcoreapp1.0": {
"dependencies": {
"dependencies": {
"Microsoft.NETCore.App": {
"version": "1.0.0-*",
"type": "platform"
Expand Down

0 comments on commit ac744ca

Please sign in to comment.