public void TestEarlyEvalNoIndent() { string templates = "t() ::= << abc>>\n" + "main() ::= <<\n" + "<t()>\n" + "<(t())>\n" + // early eval ignores indents; mostly for simply strings " <t()>\n" + " <(t())>\n" + ">>\n"; writeFile(tmpdir, "t.stg", templates); TemplateGroup group = new TemplateGroupFile(Path.Combine(tmpdir, "t.stg")); Template st = group.GetInstanceOf("main"); StringWriter sw = new StringWriter(); NoIndentWriter w = new NoIndentWriter(sw); st.Write(w); string result = sw.ToString(); string expected = "abc" + newline + "abc" + newline + "abc" + newline + "abc"; Assert.AreEqual(expected, result); }
/// <summary> /// Renders the string template /// </summary> /// <param name="viewContext"></param> /// <param name="writer"></param> public void Render(ViewContext viewContext, System.IO.TextWriter writer) { //persist the controller's viewdata in the template's attribute store foreach (var item in viewContext.Controller.ViewData) _template.SetAttribute(item.Key, item.Value); //persist the context (so the template has access to it) _template.SetAttribute("context", viewContext.HttpContext); //render the template to the text writer var noIndentWriter = new NoIndentWriter(writer); _template.Write(noIndentWriter); }
public static void Render(string name, object model, TextWriter textWriter) { var template = Group.GetInstanceOf(name); if (model != null) { template.SetAttribute("model", model); } var noIndentWriter = new NoIndentWriter(textWriter); template.Write(noIndentWriter); }
/// <summary> /// Renders the string template /// </summary> /// <param name="viewContext"></param> /// <param name="writer"></param> public void Render(ViewContext viewContext, System.IO.TextWriter writer) { //persist the controller's viewdata in the template's attribute store foreach (var item in viewContext.Controller.ViewData) { _template.SetAttribute(item.Key, item.Value); } //persist the context (so the template has access to it) _template.SetAttribute("context", viewContext.HttpContext); //render the template to the text writer var noIndentWriter = new NoIndentWriter(writer); _template.Write(noIndentWriter); }