-
Notifications
You must be signed in to change notification settings - Fork 58
/
Copy pathPartialTokenRenderer.cs
49 lines (44 loc) · 1.7 KB
/
PartialTokenRenderer.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// <copyright file="PartialTokenRenderer.cs" company="Stubble Authors">
// Copyright (c) Stubble Authors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
// </copyright>
using System.Threading.Tasks;
using Stubble.Core.Contexts;
using Stubble.Core.Tokens;
namespace Stubble.Core.Renderers.StringRenderer.TokenRenderers
{
/// <summary>
/// A renderer for <see cref="PartialToken"/>
/// </summary>
internal class PartialTokenRenderer : StringObjectRenderer<PartialToken>
{
/// <inheritdoc/>
protected override void Write(StringRender renderer, PartialToken obj, Context context)
{
var partialName = obj.Content;
string template = null;
if (context.PartialLoader != null)
{
template = context.PartialLoader.Load(partialName.ToString());
}
if (template != null)
{
renderer.Render(context.RendererSettings.Parser.Parse(template, lineIndent: obj.LineIndent), context);
}
}
/// <inheritdoc/>
protected override async Task WriteAsync(StringRender renderer, PartialToken obj, Context context)
{
var partialName = obj.Content;
string template = null;
if (context.PartialLoader != null)
{
template = await context.PartialLoader.LoadAsync(partialName.ToString());
}
if (template != null)
{
await renderer.RenderAsync(context.RendererSettings.Parser.Parse(template, lineIndent: obj.LineIndent), context);
}
}
}
}