public override void Render(object toRender, Stream output) { AppContentResponder appContentResponder = ContentResponder.AppContentResponders[AppName]; ITemplateRenderer dustRenderer = appContentResponder.AppTemplateRenderer; string templateName = GetTemplateName(toRender); string templates = dustRenderer.CompiledTemplates; string result = DustScript.Render(templates, templateName, toRender); string layout; byte[] data; if (HttpArgs.Has("layout", out layout)) { string absolutePath = ExecutionRequest.Request.Url.AbsolutePath; string extension = Path.GetExtension(absolutePath); string path = absolutePath.Truncate(extension.Length); LayoutModel layoutModel = appContentResponder.GetLayoutModelForPath(path); layoutModel.LayoutName = layout; layoutModel.PageContent = result; MemoryStream ms = new MemoryStream(); appContentResponder.CommonTemplateRenderer.RenderLayout(layoutModel, ms); ms.Seek(0, SeekOrigin.Begin); data = ms.GetBuffer(); } else { data = Encoding.UTF8.GetBytes(result); } output.Write(data, 0, data.Length); }
public virtual void Render(string templateName, object toRender, Stream output) { string result = DustScript.Render(CompiledTemplates, templateName, toRender); byte[] data = Encoding.UTF8.GetBytes(result); output.Write(data, 0, data.Length); }
/// <summary> /// Render the specified LayoutModel to the specifie output Stream /// </summary> /// <param name="toRender"></param> /// <param name="output"></param> public virtual void RenderLayout(LayoutModel toRender, Stream output) { string result = DustScript.Render(CompiledLayoutTemplates, toRender.LayoutName, toRender); byte[] data = Encoding.UTF8.GetBytes(result); output.Write(data, 0, data.Length); }
private void Compile() { Args.ThrowIfNullOrEmpty(SourceFilePath, "SourceFilePath"); string source = File.ReadAllText(SourceFilePath); this.Compiled = DustScript.Compile(source, this.Name); this.ToJsonFile(GetSaveToPath()); }
private void AppendTemplatesFromDirectory(DirectoryInfo appDust, StringBuilder templates) { string domAppName = AppConf.DomApplicationIdFromAppName(this.AppContentResponder.AppConf.Name); Logger.AddEntry("AppDustRenderer::Compiling directory {0}", appDust.FullName); string appCompiledTemplates = DustScript.CompileTemplates(appDust, "*.dust", SearchOption.AllDirectories, domAppName + ".", Logger); templates.Append(appCompiledTemplates); }