public Response RenderView(ViewLocationResult viewLocationResult, dynamic model, IRenderContext renderContext) { var template = renderContext.ViewCache.GetOrAdd(viewLocationResult, result => { try { var context = new NancyVeilContext(renderContext, Extensions); var engine = new VeilEngine(context); Type modelType = model == null ? typeof(object) : model.GetType(); return engine.CompileNonGeneric(viewLocationResult.Extension, result.Contents(), modelType); } catch (Exception e) { return CreateErrorPage(e); } }); var response = new HtmlResponse(); response.ContentType = "text/html; charset=utf-8"; response.Contents = s => { var writer = new StreamWriter(s, Encoding.UTF8); template(writer, model); writer.Flush(); }; return response; }
public Response RenderView(ViewLocationResult viewLocationResult, dynamic model, IRenderContext renderContext) { var template = renderContext.ViewCache.GetOrAdd(viewLocationResult, result => { try { var context = new NancyVeilContext(renderContext, Extensions); var engine = new VeilEngine(context); Type modelType = model == null ? typeof(object) : model.GetType(); return(engine.CompileNonGeneric(viewLocationResult.Extension, result.Contents(), modelType)); } catch (Exception e) { return(CreateErrorPage(e)); } }); var response = new HtmlResponse(); response.ContentType = "text/html; charset=utf-8"; response.Contents = s => { var writer = new StreamWriter(s, Encoding.UTF8); template(writer, model); writer.Flush(); }; return(response); }
public VeilHandlebarsRenderSpeedBenchmarkCase() { var templateContents = Templates.ReadTemplate("Template.hbs"); var context = new VeilContext(); context.RegisterTemplate("Roles", Templates.ReadTemplate("Roles.hbs")); var engine = new VeilEngine(context); compiledTypedTemplate = engine.Compile<ViewModel>("hbs", new StringReader(templateContents)); compiledUntypedTemplate = engine.CompileNonGeneric("hbs", new StringReader(templateContents), typeof(ViewModel)); compiledDynamicTemplate = engine.Compile<dynamic>("hbs", new StringReader(templateContents)); compiledDictionaryTemplate = engine.Compile<IDictionary<string, object>>("hbs", new StringReader(templateContents)); }
public VeilHandlebarsRenderSpeedBenchmarkCase() { var templateContents = Templates.ReadTemplate("Template.haml"); var context = new VeilContext(); context.RegisterTemplate("Roles", Templates.ReadTemplate("Roles.haml")); var engine = new VeilEngine(context); compiledTypedTemplate = engine.Compile <ViewModel>("haml", new StringReader(templateContents)); compiledUntypedTemplate = engine.CompileNonGeneric("haml", new StringReader(templateContents), typeof(ViewModel)); compiledDynamicTemplate = engine.Compile <dynamic>("haml", new StringReader(templateContents)); compiledDictionaryTemplate = engine.Compile <IDictionary <string, object> >("haml", new StringReader(templateContents)); }