-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make ResourcesTagHelper extensible (#16329)
Co-authored-by: Hisham Bin Ateya <hishamco_2007@yahoo.com>
- Loading branch information
1 parent
79a0853
commit 84ae5cb
Showing
8 changed files
with
159 additions
and
101 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
53 changes: 53 additions & 0 deletions
53
src/OrchardCore.Modules/OrchardCore.Resources/Services/ResourcesTagHelperProcessor.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,53 @@ | ||
using System.Threading.Tasks; | ||
using Microsoft.Extensions.Logging; | ||
using OrchardCore.ResourceManagement; | ||
|
||
namespace OrchardCore.Resources.Services; | ||
|
||
public class ResourcesTagHelperProcessor : IResourcesTagHelperProcessor | ||
{ | ||
private readonly IResourceManager _resourceManager; | ||
private readonly ILogger<ResourcesTagHelperProcessor> _logger; | ||
|
||
public ResourcesTagHelperProcessor(IResourceManager resourceManager, ILogger<ResourcesTagHelperProcessor> logger) | ||
{ | ||
_resourceManager = resourceManager; | ||
_logger = logger; | ||
} | ||
|
||
public Task ProcessAsync(ResourcesTagHelperProcessorContext context) | ||
{ | ||
switch (context.Type) | ||
{ | ||
case ResourceTagType.Meta: | ||
_resourceManager.RenderMeta(context.Writer); | ||
break; | ||
case ResourceTagType.HeadLink: | ||
_resourceManager.RenderHeadLink(context.Writer); | ||
break; | ||
case ResourceTagType.Stylesheet: | ||
_resourceManager.RenderStylesheet(context.Writer); | ||
break; | ||
case ResourceTagType.HeadScript: | ||
_resourceManager.RenderHeadScript(context.Writer); | ||
break; | ||
case ResourceTagType.FootScript: | ||
_resourceManager.RenderFootScript(context.Writer); | ||
break; | ||
case ResourceTagType.Header: | ||
_resourceManager.RenderMeta(context.Writer); | ||
_resourceManager.RenderHeadLink(context.Writer); | ||
_resourceManager.RenderStylesheet(context.Writer); | ||
_resourceManager.RenderHeadScript(context.Writer); | ||
break; | ||
case ResourceTagType.Footer: | ||
_resourceManager.RenderFootScript(context.Writer); | ||
break; | ||
default: | ||
_logger.LogWarning("Unknown {TypeName} value \"{Value}\".", nameof(ResourceTagType), context.Type); | ||
break; | ||
} | ||
|
||
return Task.CompletedTask; | ||
} | ||
} |
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
14 changes: 14 additions & 0 deletions
14
src/OrchardCore/OrchardCore.ResourceManagement.Abstractions/IResourcesTagHelperProcessor.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,14 @@ | ||
using System.Threading.Tasks; | ||
|
||
namespace OrchardCore.ResourceManagement; | ||
|
||
/// <summary> | ||
/// Processes resources in the <c><resources /></c> tag helper. | ||
/// </summary> | ||
public interface IResourcesTagHelperProcessor | ||
{ | ||
/// <summary> | ||
/// Invoked when rendering registered resources. | ||
/// </summary> | ||
Task ProcessAsync(ResourcesTagHelperProcessorContext context); | ||
} |
44 changes: 44 additions & 0 deletions
44
src/OrchardCore/OrchardCore.ResourceManagement.Abstractions/ResourceTagType.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,44 @@ | ||
namespace OrchardCore.ResourceManagement; | ||
|
||
/// <summary> | ||
/// The possible <c>type</c> values of the <c><resources type="..." /></c> Razor tag helper and the | ||
/// <c>{% resources type: "..." %}</c> liquid tag, indicating the kinds of resources to be rendered. The value should be | ||
/// chosen based on the tag's location in the document. | ||
/// </summary> | ||
public enum ResourceTagType | ||
{ | ||
/// <summary> | ||
/// Resources that should be rendered along with <see cref="IResourceManager.RenderMeta"/>. | ||
/// </summary> | ||
Meta, | ||
|
||
/// <summary> | ||
/// Resources that should be rendered along with <see cref="IResourceManager.RenderHeadLink"/>. | ||
/// </summary> | ||
HeadLink, | ||
|
||
/// <summary> | ||
/// Resources that should be rendered along with <see cref="IResourceManager.RenderStylesheet"/>. | ||
/// </summary> | ||
Stylesheet, | ||
|
||
/// <summary> | ||
/// Resources that should be rendered along with <see cref="IResourceManager.RenderHeadScript"/>. | ||
/// </summary> | ||
HeadScript, | ||
|
||
/// <summary> | ||
/// Resources that should be rendered along with <see cref="IResourceManager.RenderFootScript"/>. | ||
/// </summary> | ||
FootScript, | ||
|
||
/// <summary> | ||
/// Resources that should be rendered inside the <c>/html/head</c> element. | ||
/// </summary> | ||
Header, | ||
|
||
/// <summary> | ||
/// Resources that should be rendered inside the <c>/html/head</c> element, near the end of the document. | ||
/// </summary> | ||
Footer | ||
} |
14 changes: 14 additions & 0 deletions
14
...ardCore/OrchardCore.ResourceManagement.Abstractions/ResourcesTagHelperProcessorContext.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,14 @@ | ||
using System.IO; | ||
using Microsoft.AspNetCore.Razor.TagHelpers; | ||
|
||
namespace OrchardCore.ResourceManagement; | ||
|
||
/// <summary> | ||
/// The context passed to <see cref="IResourcesTagHelperProcessor.ProcessAsync"/>, to render the | ||
/// <c><resources /></c> Razor tag helper and the <c>{% resources %}</c> liquid tag. | ||
/// </summary> | ||
/// <param name="Type">The value indicating which types of resources to render.</param> | ||
/// <param name="Writer">The object that writes the rendered content into the HTML output.</param> | ||
public record ResourcesTagHelperProcessorContext( | ||
ResourceTagType Type, | ||
TextWriter Writer); |
66 changes: 15 additions & 51 deletions
66
src/OrchardCore/OrchardCore.ResourceManagement/TagHelpers/ResourcesTagHelper.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
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