本文整理汇总了C#中Template.Render方法的典型用法代码示例。如果您正苦于以下问题:C# Template.Render方法的具体用法?C# Template.Render怎么用?C# Template.Render使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Template
的用法示例。
在下文中一共展示了Template.Render方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestConditional_True
public void TestConditional_True()
{
var template = new Template("$if(value)$yes$endif$", '$', '$');
template.Add("value", true);
var output = template.Render();
Assert.AreEqual("yes", output);
}
示例2: TestDefaultDelimiter
public void TestDefaultDelimiter()
{
var template = new Template("hello <token>.");
template.Add("token", "world");
var output = template.Render();
Assert.AreEqual("hello world.", output);
}
示例3: TestConditional_NotNull
public void TestConditional_NotNull()
{
var template = new Template("$if(value)$yes$endif$", '$', '$');
template.Add("value", "Some Object");
var output = template.Render();
Assert.AreEqual("yes", output);
}
示例4: renders_the_template
public void renders_the_template()
{
var theValue = TemplateValue.For("field", "FirstName");
var theTemplate = new Template(StringToken.FromKeyString("Test", "{field} is required"), theValue);
theTemplate.Render().ShouldBe("FirstName is required");
}
示例5: NotificationMessage
public NotificationMessage(StringToken stringToken, params TemplateValue[] values)
{
StringToken = stringToken;
_template = new Template(stringToken, values);
_message = new Lazy<string>(() => _template.Render());
}
示例6: GenerateMain
public static void GenerateMain(string entryType, string entryNamespace, bool inputArgs)
{
StreamWriter writer = new StreamWriter(FileWritterManager.WorkingPath + "main.cpp");
string txt;
Template template;
string altTools = Environment.GetEnvironmentVariable("ALTERNATIVE_TOOLS_PATH");
if(altTools == null)
altTools = Path.Combine(Environment.CurrentDirectory, (@"..\..\..\Tools").Replace('\\','/'));
StreamReader sr = new StreamReader((altTools + @"\Templates\Code\main.stg").Replace('\\', '/'));
txt = sr.ReadToEnd();
template = new Template(txt);
StreamReader fs = new StreamReader(Path.Combine(altTools, "Text/notice"));
string notice = fs.ReadToEnd();
template.Add("NOTICE", notice);
template.Add("ENTRY_TYPE", entryType);
template.Add("ENTRY_NAMESPACE_NEEDED", !String.IsNullOrEmpty(entryNamespace));
template.Add("ENTRY_NAMESPACE", entryNamespace);
template.Add("INPUT_ARGS", inputArgs);
string output = template.Render();
writer.Write(output);
writer.Flush();
writer.Close();
FileWritterManager.AddSourceFile("main.cpp");
}
示例7: TestAlternateDelimiter
public void TestAlternateDelimiter()
{
var template = new Template("hello ~token~.", '~', '~');
template.Add("token", "world");
var output = template.Render();
Assert.AreEqual("hello world.", output);
}
示例8: TestComplicatedExpression
public void TestComplicatedExpression()
{
var templateContent = "${(8+2)*(5+5) - ((2+8)/2)}";
var template = new Template(templateContent);
var render = template.Render();
Assert.AreEqual("95", render);
}
示例9: ExpandMacros
/// <summary>
/// Expands the macros in the given string using the variables stored inside
/// this object. The resulting string will have the macros expanded.
/// </summary>
/// <param name="input">The input string.</param>
/// <returns>The output string with macros expanded.</returns>
public string ExpandMacros(string input)
{
// If we have a null, then just return a null.
if (string.IsNullOrWhiteSpace(input))
{
return input;
}
// We have to repeatedly run through the macros since we have macros
// that expand into other macros.
string results = input;
while (results.IndexOf('{') >= 0)
{
// Create a template with all of the variables inside it.
var template = new Template(results, '{', '}');
foreach (KeyValuePair<string, string> macro in Substitutions)
{
template.Add(macro.Key, macro.Value);
}
// Render out the template to the results.
results = template.Render();
}
// Return the resulting string.
return results;
}
示例10: TestComent
public void TestComent()
{
var templateContent = "你好,$*使用简写符加星号可对代码注释*$欢迎使用";
var template = new Template(templateContent);
template.Set("name", "jntemplate");
var render = template.Render();
Assert.AreEqual("你好,欢迎使用", render);
}
示例11: TestClassFunction
public void TestClassFunction()
{
var templateContent = "$fun.Test(\"字符串\",1,true)";
var template = new Template(templateContent);
template.Set("fun", new TemplateMethod());
var render = template.Render();
Assert.AreEqual("您输入的参数是有:字符串 1 True ", render);
}
示例12: TestLambdaIsCalledOnceFromCustomAssignsOverMultipleParsesAndRenders
public void TestLambdaIsCalledOnceFromCustomAssignsOverMultipleParsesAndRenders()
{
Template t = new Template();
int global = 0;
Hash assigns = Hash.FromAnonymousObject(new { number = (Proc) (c => ++global) });
Assert.AreEqual("1", t.ParseInternal("{{number}}").Render(assigns));
Assert.AreEqual("1", t.ParseInternal("{{number}}").Render(assigns));
Assert.AreEqual("1", t.Render(assigns));
}
示例13: TestAttr
public void TestAttr()
{
string template = "hi $name$!";
Template st = new Template(template, '$', '$');
st.Add("name", "Ter");
string expected = "hi Ter!";
string result = st.Render();
Assert.AreEqual(expected, result);
}
示例14: TestLambdaIsCalledOnceFromPersistentAssignsOverMultipleParsesAndRenders
public void TestLambdaIsCalledOnceFromPersistentAssignsOverMultipleParsesAndRenders()
{
Template t = new Template();
int global = 0;
t.Assigns["number"] = (Proc) (c => ++global);
Assert.AreEqual("1", t.ParseInternal("{{number}}").Render());
Assert.AreEqual("1", t.ParseInternal("{{number}}").Render());
Assert.AreEqual("1", t.Render());
}
示例15: TestEarlyEval
public void TestEarlyEval()
{
string template = "<(name)>";
Template st = new Template(template);
st.Add("name", "Ter");
string expected = "Ter";
string result = st.Render();
Assert.AreEqual(expected, result);
}