当前位置: 首页>>代码示例>>C#>>正文


C# Template.Load方法代码示例

本文整理汇总了C#中Template.Load方法的典型用法代码示例。如果您正苦于以下问题:C# Template.Load方法的具体用法?C# Template.Load怎么用?C# Template.Load使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Template的用法示例。


在下文中一共展示了Template.Load方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: RunMustacheSpecs

        private static void RunMustacheSpecs(MustacheSpec.MustacheTest test)
        {
            TemplateLocator testDataTemplateLocator = name =>
            {
                if (test.Partials != null && test.Partials[name] != null)
                {
                    var template = new Template();
                    template.Load(new StringReader(test.Partials[name].ToString()));
                    return template;
                };

                return null;
            };

            var rendered = Render.StringToString(test.Template, test.Example, testDataTemplateLocator);
            Assert.AreEqual(test.Expected, rendered, "JSON object rendering failed for " + test.Description);

            rendered = Render.StringToString(test.Template, test.StronglyTypedExample, testDataTemplateLocator);
            Assert.AreEqual(test.Expected, rendered, "Strongly typed rendering failed for " + test.Description);

            var templ = new Template();
            templ.Load(new StringReader(test.Template));

            if (!test.Name.ToLower().Contains("context miss") &&
                !test.Name.ToLower().Contains("broken chain") &&
                !(test.SpecName == "inverted" && (test.Name == "List" || test.Name == "Context")))
            {
                try
                {
                    var compiledTemplate = templ.Compile(
                    test.StronglyTypedExample != null ? test.StronglyTypedExample.GetType() : typeof(object),
                    testDataTemplateLocator);
                    rendered = compiledTemplate(test.StronglyTypedExample);
                    Assert.AreEqual(test.Expected, rendered, "Compiled Template rendering failed for " + test.Description);
                }
                catch (Nustache.Core.NustacheException ex)
                {
                    if (ex.Message.StartsWith("Unsupported:"))
                    {
                        Assert.Inconclusive(ex.Message);
                    }
                }
            }
            else
            {
                bool gotException = false;
                try
                {
                    var compiledTemplate = templ.Compile(
                        test.StronglyTypedExample != null ? test.StronglyTypedExample.GetType() : typeof(object),
                        testDataTemplateLocator);
                }
                catch (Compilation.CompilationException)
                {
                    gotException = true;
                }

                Assert.IsTrue(gotException, "Expected test to throw a compilation exception for an invalid template");
            }
        }
开发者ID:reicheltp,项目名称:Nustache,代码行数:60,代码来源:Official_Specs.cs

示例2: It_can_include_templates_over_three_levels_with_external_includes

        public void It_can_include_templates_over_three_levels_with_external_includes()
        {
            var baseTemplate = new Template("Base");
            baseTemplate.Load(new StringReader("Base{{>BaseContent}}"));

            var masterTemplate = new Template("Master");
            masterTemplate.Load(new StringReader("{{<BaseContent}}Master{{>MasterContent}}{{/BaseContent}}{{>Base}}"));

            var templates = new Dictionary<string, Template>();
            templates.Add("Base", baseTemplate);
            templates.Add("Master", masterTemplate);

            TemplateLocator locateTemplate =
                name =>
                {
                    Template ret;
                    templates.TryGetValue(name, out ret);
                    if (ret == null) throw new KeyNotFoundException(string.Format("The view '{0}' could not be found.", name));
                    return ret;
                };

            var result = Render.StringToString("{{<MasterContent}}Hello{{/MasterContent}}{{>Master}}", null, locateTemplate);

            Assert.AreEqual("BaseMasterHello", result);
        }
开发者ID:gordonmleigh,项目名称:Nustache,代码行数:25,代码来源:Describe_Template_Render.cs

示例3: It_can_include_templates

        public void It_can_include_templates()
        {
            var fooTemplate = new Template();
            fooTemplate.Load(new StringReader("FOO"));

            var result = Render.StringToString(
                "before{{>foo}}after", null, name => fooTemplate);

            Assert.AreEqual("beforeFOOafter", result);
        }
开发者ID:pluraldj,项目名称:Nustache,代码行数:10,代码来源:Describe_Template_Render.cs

示例4: NustacheView

 public NustacheView(NustacheViewEngine engine, VirtualPath path, IResource resource, IResourceResolver resolver)
 {
     _engine = engine;
     _path = path;
     _resolver = resolver;
     using (var stream = resource.Open())
     using (var reader = new StreamReader(stream)) {
         Template = new Template();
         Template.Load(reader);
     }
 }
开发者ID:jammycakes,项目名称:dolstagis.web,代码行数:11,代码来源:NustacheView.cs

示例5: It_asks_the_RenderContext_to_include_a_named_template

        public void It_asks_the_RenderContext_to_include_a_named_template()
        {
            var a = new TemplateInclude("a");
            var template = new Template();
            template.Load(new Part[] { new LiteralText("b") });
            var writer = new StringWriter();
            var context = new RenderContext(new Template(), null, writer, name => template, Options.Defaults());

            a.Render(context);

            Assert.AreEqual("b", writer.GetStringBuilder().ToString());
        }
开发者ID:lukemerrett,项目名称:Nustache,代码行数:12,代码来源:Describe_TemplateInclude.cs

示例6: AllTests

        public void AllTests(string name, Dictionary<object, object> data, string template, Dictionary<object, string> partials, string expected)
        {
            FixData(data);

            var actual = Render.StringToString(
                template,
                data,
                partial =>
                {
                    if (partials.ContainsKey(partial))
                    {
                        var t = new Template();
                        t.Load(new StringReader(partials[partial]));
                        return t;
                    }
                    else
                    {
                        return null;
                    }
                });

            Assert.AreEqual(expected, actual);
        }
开发者ID:Romanx,项目名称:Nustache,代码行数:23,代码来源:Mustache_Spec.cs

示例7: It_throws_to_prevent_infinite_template_recursion

        public void It_throws_to_prevent_infinite_template_recursion()
        {
            var fooTemplate = new Template();
            fooTemplate.Load(new StringReader("{{>foo}}"));

            Assert.Throws<NustacheException>(
                () => Render.StringToString(
                    "before{{>foo}}after", null, name => fooTemplate));
        }
开发者ID:pluraldj,项目名称:Nustache,代码行数:9,代码来源:Describe_Template_Render.cs


注:本文中的Template.Load方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。