本文整理汇总了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");
}
}
示例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);
}
示例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);
}
示例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);
}
}
示例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());
}
示例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);
}
示例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));
}