/// <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 _template.Add("viewData", viewContext.Controller.ViewData.ToDictionary(x => x.Key, x => x.Value)); _template.Add("model",viewContext.ViewData.Model); //render the template to the text writer var noIndentWriter = new NoIndentWriter(writer); _template.Write(noIndentWriter); }
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); }