public static async ValueTask <string> RenderAsync(this IFluidTemplate template, TemplateContext context, TextEncoder encoder) { if (context == null) { ExceptionHelper.ThrowArgumentNullException(nameof(context)); } if (template == null) { ExceptionHelper.ThrowArgumentNullException(nameof(template)); } var sb = StringBuilderPool.GetInstance(); var writer = new StringWriter(sb.Builder); // A template is evaluated in a child scope such that the provided TemplateContext is immutable context.EnterChildScope(); try { await template.RenderAsync(writer, encoder, context); writer.Flush(); return(sb.ToString()); } finally { sb.Dispose(); writer.Dispose(); context.ReleaseScope(); } }
protected virtual void SetCachedTemplate(string path, IFluidTemplate template) { _cache[path] = template; //// Default sliding expiration to prevent the entries for being kept indefinitely //viewEntry.SlidingExpiration = TimeSpan.FromHours(1); //viewEntry.ExpirationTokens.Add(fileProvider.Watch(path)); }
public static void Render(this IFluidTemplate template, TemplateContext context, TextEncoder encoder, TextWriter writer) { var task = template.RenderAsync(writer, encoder, context); if (!task.IsCompletedSuccessfully) { task.AsTask().GetAwaiter().GetResult(); } }
public static ValueTask <string> RenderAsync(this IFluidTemplate template, TemplateContext context, TextEncoder encoder) { if (context == null) { ExceptionHelper.ThrowArgumentNullException(nameof(context)); } if (template == null) { ExceptionHelper.ThrowArgumentNullException(nameof(template)); }
private void ProcessTemplate(IFluidTemplate template, ExtractingLiquidWalker visitor, string path) { if (template is CompositeFluidTemplate compositeTemplate) { foreach (var innerTemplate in compositeTemplate.Templates) { ProcessTemplate(innerTemplate, visitor, path); } } else if (template is FluidTemplate singleTemplate) { ProcessTemplate(singleTemplate, visitor, path); } }
public static async Task <string> RenderAsync(this IFluidTemplate template, TemplateContext context) { if (context == null) { throw new ArgumentNullException(nameof(context)); } using (var writer = new StringWriter()) { await template.RenderAsync(writer, HtmlEncoder.Default, context); return(writer.ToString()); } }
public static bool TryParse(this FluidParser parser, string template, out IFluidTemplate result, out string error) { try { error = null; result = parser.Parse(template); return(true); } catch (ParseException e) { error = e.Message; result = null; return(false); } catch (Exception e) { error = e.Message; result = null; return(false); } }
public static async Task <string> RenderAsync(this IFluidTemplate template, TextEncoder encoder, TemplateContext context) { if (context == null) { throw new ArgumentNullException(nameof(context)); } if (template == null) { throw new ArgumentNullException(nameof(template)); } using (var sb = StringBuilderPool.GetInstance()) { using (var writer = new StringWriter(sb.Builder)) { await template.RenderAsync(writer, encoder, context); return(writer.ToString()); } } }
public static string Render(this IFluidTemplate template, TemplateContext context) { return(template.RenderAsync(context).GetAwaiter().GetResult()); }
public static bool TryParse(this FluidParser parser, string template, out IFluidTemplate result) { return(parser.TryParse(template, out result, out _)); }
public static string Render(this IFluidTemplate template) { var task = template.RenderAsync(); return(task.IsCompletedSuccessfully ? task.Result : task.AsTask().GetAwaiter().GetResult()); }
protected virtual bool TryGetCachedTemplate(string path, out IFluidTemplate template) { return(_cache.TryGetValue(path, out template)); }
public LiquidViewTemplate(IFluidTemplate fluidTemplate) { FluidTemplate = fluidTemplate; }
public static void Render(this IFluidTemplate template, TextWriter writer, TextEncoder encoder, TemplateContext context) { template.RenderAsync(writer, encoder, context).GetAwaiter().GetResult(); }
public static string Render(this IFluidTemplate template) { return(template.RenderAsync().GetAwaiter().GetResult()); }
public static Task <string> RenderAsync(this IFluidTemplate template) { return(template.RenderAsync(new TemplateContext())); }
public static string Render(this IFluidTemplate template, TemplateContext context, TextEncoder encoder) { var task = template.RenderAsync(context, encoder); return(task.IsCompletedSuccessfully ? task.Result : task.AsTask().GetAwaiter().GetResult()); }
public static Task <string> RenderAsync(this IFluidTemplate template, TemplateContext context) { return(template.RenderAsync(HtmlEncoder.Default, context)); }
public static ValueTask <string> RenderAsync(this IFluidTemplate template, TemplateContext context) { return(template.RenderAsync(context, NullEncoder.Default)); }
public TestCase(string source) { _source = source; _template = _parser.Parse(source); }