コード例 #1
0
ファイル: VeilViewEngine.cs プロジェクト: namics/TerrificNet
        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;
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        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));
        }
コード例 #4
0
        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));
        }