private async Task <string> Generate(ClassDefinition definition, TemplateType templateType) { // Try to find template. var cached = engine.TemplateCache.RetrieveTemplate(templateType.ToString()); if (cached.Success) { // If template exists render template return(await engine.RenderTemplateAsync(cached.Template.TemplatePageFactory(), definition)); } // Compile and generate template return(await engine.CompileRenderAsync(templateType.ToString(), templateDefinitions[templateType], definition)); }
private async Task <string> GenerateAsync <T>(T model, string templateRelativePath) { templateRelativePath = GetOsRuntimeBaseDirectoryCombinedPath(templateRelativePath); // Try to find template. var found = Engine.TemplateCache.RetrieveTemplate(templateRelativePath); if (found.Success) { // If template exists render template return(await Engine.RenderTemplateAsync(found.Template.TemplatePageFactory(), (object)model, Type.GetTypeFromHandle(typeof(T).TypeHandle), ViewBag)); } var template = System.IO.File.ReadAllText(templateRelativePath); // Compile and generate template return(await Engine.CompileRenderAsync(templateRelativePath, template, model, ViewBag)); }