This repository was archived by the owner on Dec 19, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 223
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Also added some infrastructure pieces for it such as the ITagHelperDescriptorResolver and the default implementation TagHelperDescriptorResolver which will be filled out in a later commit. - Reworked some extensibility points to allow accessibility of the descriptor resolvers per offline discussions. #111
- Loading branch information
1 parent
7399531
commit 6cb42ff
Showing
17 changed files
with
317 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
...Microsoft.AspNet.Razor/Generator/Compiler/CodeTree/Chunks/TagHelpers/AddTagHelperChunk.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
namespace Microsoft.AspNet.Razor.Generator.Compiler | ||
{ | ||
/// <summary> | ||
/// A <see cref="Chunk"/> that is used to lookup <see cref="TagHelpers.TagHelperDescriptor"/>s. | ||
/// </summary> | ||
public class AddTagHelperChunk : Chunk | ||
{ | ||
/// <summary> | ||
/// Arbitrary text used to lookup <see cref="TagHelpers.TagHelperDescriptor"/>s. | ||
/// </summary> | ||
public string LookupText { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
src/Microsoft.AspNet.Razor/Generator/TagHelpers/AddTagHelperCodeGenerator.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
using Microsoft.AspNet.Razor.Parser.SyntaxTree; | ||
|
||
namespace Microsoft.AspNet.Razor.Generator | ||
{ | ||
/// <summary> | ||
/// A <see cref="SpanCodeGenerator"/> that is responsible for generating <see cref="Compiler.AddTagHelperChunk"/>s. | ||
/// </summary> | ||
public class AddTagHelperCodeGenerator : SpanCodeGenerator | ||
{ | ||
/// <summary> | ||
/// Instantiates a new <see cref="AddTagHelperCodeGenerator"/>. | ||
/// </summary> | ||
/// <param name="lookupText"> | ||
/// Arbitrary text used to lookup <see cref="TagHelpers.TagHelperDescriptor"/>s. | ||
/// </param> | ||
public AddTagHelperCodeGenerator(string lookupText) | ||
{ | ||
LookupText = lookupText; | ||
} | ||
|
||
/// <summary> | ||
/// Arbitrary text used to lookup <see cref="TagHelpers.TagHelperDescriptor"/>s. | ||
/// </summary> | ||
public string LookupText { get; private set; } | ||
|
||
/// <summary> | ||
/// Generates a <see cref="Compiler.AddTagHelperChunk"/>. | ||
/// </summary> | ||
/// <param name="target"> | ||
/// The <see cref="Span"/> responsible for this <see cref="AddTagHelperCodeGenerator"/>. | ||
/// </param> | ||
/// <param name="context">A <see cref="CodeGeneratorContext"/> instance that contains information about | ||
/// the current code generation process.</param> | ||
public override void GenerateCode(Span target, CodeGeneratorContext context) | ||
{ | ||
context.CodeTreeBuilder.AddAddTagHelperChunk(LookupText, target); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
src/Microsoft.AspNet.Razor/Parser/TagHelpers/TagHelperRegistrationVisitor.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// Copyright (c) Microsoft Open Technologies, Inc. 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.AspNet.Razor.Generator; | ||
using Microsoft.AspNet.Razor.Parser.SyntaxTree; | ||
using Microsoft.AspNet.Razor.TagHelpers; | ||
|
||
namespace Microsoft.AspNet.Razor.Parser.TagHelpers.Internal | ||
{ | ||
public class TagHelperRegistrationVisitor : ParserVisitor | ||
{ | ||
private HashSet<TagHelperDescriptor> _descriptors; | ||
private ITagHelperDescriptorResolver _descriptorResolver; | ||
|
||
public TagHelperRegistrationVisitor(ITagHelperDescriptorResolver descriptorResolver) | ||
{ | ||
_descriptorResolver = descriptorResolver; | ||
} | ||
|
||
public TagHelperDescriptorProvider CreateProvider(Block root) | ||
{ | ||
_descriptors = new HashSet<TagHelperDescriptor>(TagHelperDescriptorComparer.Default); | ||
|
||
// This will recurse through the syntax tree. | ||
VisitBlock(root); | ||
|
||
return new TagHelperDescriptorProvider(_descriptors); | ||
} | ||
|
||
public override void VisitSpan(Span span) | ||
{ | ||
// We're only interested in spans with AddTagHelperCodeGenerator's. | ||
if (span.CodeGenerator is AddTagHelperCodeGenerator) | ||
{ | ||
var addGenerator = (AddTagHelperCodeGenerator)span.CodeGenerator; | ||
|
||
// Lookup all the descriptors associated with the "LookupText". | ||
var descriptors = _descriptorResolver.Resolve(addGenerator.LookupText); | ||
|
||
// Add all the found descriptors to our HashSet. Duplicates are handled by the HashSet. | ||
foreach (var descriptor in descriptors) | ||
{ | ||
_descriptors.Add(descriptor); | ||
} | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.