This repository has been archived by the owner on Dec 19, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 224
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Addresses aspnet/Mvc#5728
- Loading branch information
Showing
5 changed files
with
100 additions
and
34 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
32 changes: 2 additions & 30 deletions
32
src/Microsoft.AspNetCore.Razor.Runtime/TagHelpers/ITagHelper.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 |
---|---|---|
@@ -1,41 +1,13 @@ | ||
// 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.Threading.Tasks; | ||
|
||
namespace Microsoft.AspNetCore.Razor.TagHelpers | ||
{ | ||
/// <summary> | ||
/// Contract used to filter matching HTML elements. | ||
/// Marker interface for <see cref="TagHelper"/>s. | ||
/// </summary> | ||
public interface ITagHelper | ||
public interface ITagHelper : ITagHelperComponent | ||
{ | ||
/// <summary> | ||
/// When a set of<see cref= "ITagHelper" /> s are executed, their<see cref="Init(TagHelperContext)"/>'s | ||
/// are first invoked in the specified <see cref="Order"/>; then their | ||
/// <see cref="ProcessAsync(TagHelperContext, TagHelperOutput)"/>'s are invoked in the specified | ||
/// <see cref="Order"/>. Lower values are executed first. | ||
/// </summary> | ||
int Order { get; } | ||
|
||
/// <summary> | ||
/// Initializes the <see cref="ITagHelper"/> with the given <paramref name="context"/>. Additions to | ||
/// <see cref="TagHelperContext.Items"/> should be done within this method to ensure they're added prior to | ||
/// executing the children. | ||
/// </summary> | ||
/// <param name="context">Contains information associated with the current HTML tag.</param> | ||
/// <remarks>When more than one <see cref="ITagHelper"/> runs on the same element, | ||
/// <see cref="M:TagHelperOutput.GetChildContentAsync"/> may be invoked prior to <see cref="ProcessAsync"/>. | ||
/// </remarks> | ||
void Init(TagHelperContext context); | ||
|
||
/// <summary> | ||
/// Asynchronously executes the <see cref="ITagHelper"/> with the given <paramref name="context"/> and | ||
/// <paramref name="output"/>. | ||
/// </summary> | ||
/// <param name="context">Contains information associated with the current HTML tag.</param> | ||
/// <param name="output">A stateful HTML element used to generate an HTML tag.</param> | ||
/// <returns>A <see cref="Task"/> that on completion updates the <paramref name="output"/>.</returns> | ||
Task ProcessAsync(TagHelperContext context, TagHelperOutput output); | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
src/Microsoft.AspNetCore.Razor.Runtime/TagHelpers/ITagHelperComponent.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,41 @@ | ||
// 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.Threading.Tasks; | ||
|
||
namespace Microsoft.AspNetCore.Razor.TagHelpers | ||
{ | ||
/// <summary> | ||
/// Contract used to modify an HTML element. | ||
/// </summary> | ||
public interface ITagHelperComponent | ||
{ | ||
/// <summary> | ||
/// When a set of <see cref="ITagHelperComponent"/>s are executed, their <see cref="Init(TagHelperContext)"/>'s | ||
/// are first invoked in the specified <see cref="Order"/>; then their | ||
/// <see cref="ProcessAsync(TagHelperContext, TagHelperOutput)"/>'s are invoked in the specified | ||
/// <see cref="Order"/>. Lower values are executed first. | ||
/// </summary> | ||
int Order { get; } | ||
|
||
/// <summary> | ||
/// Initializes the <see cref="ITagHelperComponent"/> with the given <paramref name="context"/>. Additions to | ||
/// <see cref="TagHelperContext.Items"/> should be done within this method to ensure they're added prior to | ||
/// executing the children. | ||
/// </summary> | ||
/// <param name="context">Contains information associated with the current HTML tag.</param> | ||
/// <remarks>When more than one <see cref="ITagHelperComponent"/> runs on the same element, | ||
/// <see cref="M:TagHelperOutput.GetChildContentAsync"/> may be invoked prior to <see cref="ProcessAsync"/>. | ||
/// </remarks> | ||
void Init(TagHelperContext context); | ||
|
||
/// <summary> | ||
/// Asynchronously executes the <see cref="ITagHelperComponent"/> with the given <paramref name="context"/> and | ||
/// <paramref name="output"/>. | ||
/// </summary> | ||
/// <param name="context">Contains information associated with the current HTML tag.</param> | ||
/// <param name="output">A stateful HTML element used to generate an HTML tag.</param> | ||
/// <returns>A <see cref="Task"/> that on completion updates the <paramref name="output"/>.</returns> | ||
Task ProcessAsync(TagHelperContext context, TagHelperOutput output); | ||
} | ||
} |
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
40 changes: 40 additions & 0 deletions
40
src/Microsoft.AspNetCore.Razor.Runtime/TagHelpers/TagHelperComponent.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,40 @@ | ||
// 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.Threading.Tasks; | ||
using Microsoft.Extensions.Internal; | ||
|
||
namespace Microsoft.AspNetCore.Razor.TagHelpers | ||
{ | ||
/// <summary> | ||
/// An abstract base class for <see cref="ITagHelperComponent"/>. | ||
/// </summary> | ||
public abstract class TagHelperComponent : ITagHelperComponent | ||
{ | ||
/// <inheritdoc /> | ||
/// <remarks>Default order is <c>0</c>.</remarks> | ||
public virtual int Order => 0; | ||
|
||
/// <inheritdoc /> | ||
public virtual void Init(TagHelperContext context) | ||
{ | ||
} | ||
|
||
/// <summary> | ||
/// Synchronously executes the <see cref="ITagHelperComponent"/> with the given <paramref name="context"/> and | ||
/// <paramref name="output"/>. | ||
/// </summary> | ||
/// <param name="context">Contains information associated with the current HTML tag.</param> | ||
/// <param name="output">A stateful HTML element used to generate an HTML tag.</param> | ||
public virtual void Process(TagHelperContext context, TagHelperOutput output) | ||
{ | ||
} | ||
|
||
/// <inheritdoc /> | ||
public virtual Task ProcessAsync(TagHelperContext context, TagHelperOutput output) | ||
{ | ||
Process(context, output); | ||
return TaskCache.CompletedTask; | ||
} | ||
} | ||
} |