async public Task WriteToAsync(IAsyncWriter Stream, String TemplateName, Dictionary<string, object> Scope = null) { var TemplateCode = await GetTemplateCodeByFileAsync(TemplateName); var TextWriter = new NodeTextWriter(Stream); var TemplateContext = new TemplateContext(TextWriter, TemplateFactory, new TemplateScope(Scope)); await TemplateCode.RenderAsync(TemplateContext); await TextWriter.FlushAsync(); }
protected void Autoescape(TemplateContext Context, dynamic Expression, EmptyDelegate Block) { bool OldAutoescape = Context.Autoescape; Context.Autoescape = Expression; { Block(); } Context.Autoescape = OldAutoescape; }
public void Render(TemplateContext Context) { Context.RenderingTemplate = this; try { this.LocalRender(Context); } catch (FinalizeRenderException) { } catch (Exception Exception) { Context.Output.WriteLine(Exception); } }
public void Render(TemplateContext Context) { Context.RenderingTemplate = this; Exception ProducedException = null; try { this.LocalRender(Context); } catch (FinalizeRenderException) { } catch (Exception Exception) { ProducedException = Exception; } if (ProducedException != null) { Context.Output.WriteLine(ProducedException.ToString()); //throw (ProducedException); } }
/* async virtual protected Task LocalRenderAsync(TemplateContext Context) { } */ /* async public Task RenderAsync(TemplateContext Context) { } */ async public Task RenderAsync(TemplateContext Context) { Context.RenderingTemplate = this; Exception ProducedException = null; try { await this.LocalRenderAsync(Context); } catch (FinalizeRenderException) { } catch (Exception Exception) { ProducedException = Exception; } if (ProducedException != null) { await Context.Output.WriteLineAsync(ProducedException.ToString()); //throw (ProducedException); } }
protected override Task LocalRenderAsync(TemplateContext Context) { throw new NotImplementedException(); }
protected void CallParentBlock(String BlockName, TemplateContext Context) { this.ParentTemplate.GetFirstAscendingBlock(BlockName)(Context); }
async protected Task CallBlockAsync(String BlockName, TemplateContext Context) { await Context.RenderingTemplate.GetFirstAscendingBlock(BlockName)(Context); }
protected void SetAndRenderParentTemplate(String ParentTemplateFileName, TemplateContext Context) { this.ParentTemplate = Context.TemplateFactory.GetTemplateCodeByFile(ParentTemplateFileName); this.ParentTemplate.ChildTemplate = this; #if NET_4_5 this.ParentTemplate.LocalRenderAsync(Context); #else this.ParentTemplate.LocalRender(Context); #endif throw (new FinalizeRenderException()); }
protected abstract void LocalRender(TemplateContext Context);
/* * async protected virtual Task LocalRenderAsync(TemplateContext Context) * { * } */ /* * public async Task RenderAsync(TemplateContext Context) * { * } */ #if NET_4_5 protected abstract Task LocalRenderAsync(TemplateContext Context);
protected void CallBlock(String BlockName, TemplateContext Context) { Context.RenderingTemplate.GetFirstAscendingBlock(BlockName)(Context); }
async protected Task ForeachAsync(TemplateContext Context, String VarName, dynamic Expression, EmptyDelegate Iteration, EmptyDelegate Else = null) { int Index = 0; foreach (var Item in DynamicUtils.ConvertToIEnumerable(Expression)) { Context.SetVar("loop", new Dictionary<String, dynamic> { { "index", Index + 1 }, { "index0", Index }, }); Context.SetVar(VarName, Item); await Iteration(); Index++; } if (Index == 0) { if (Else != null) await Else(); } }
abstract protected Task LocalRenderAsync(TemplateContext Context);
async protected Task SetAndRenderParentTemplateAsync(String ParentTemplateFileName, TemplateContext Context) { this.ParentTemplate = await Context.TemplateFactory.GetTemplateCodeByFileAsync(ParentTemplateFileName); this.ParentTemplate.ChildTemplate = this; await this.ParentTemplate.LocalRenderAsync(Context); throw (new FinalizeRenderException()); }
protected virtual void LocalRender(TemplateContext Context) { }