jdiamond/Nustache — pull request #53 by haoyuhai (2013-06-26 09:21:32+00:00)
Title: Enhance method invoking(pass a render context parameter), can get the binding object by the parameter.

[Test]
+ public void It_can_render_method_result_with_context()
+ {
+ var result = Render.StringToString("{{#Rows}}{{#Columns}}{{GetValueWithContext}}{{/Columns}}{/Rows}}", GetTableData());
+ Assert.AreEqual("123246", result);
+ }

//add RenderContext param support
public string GetValueWithContext(RenderContext renderContext)
+ {
+ int row = (int)renderContext.GetSectionData("Rows");
+ int column = (int)renderContext.GetSectionData("Columns");
+ return (row * column).ToString();
+ }

//RenderContext add public method, and make other method internal.
+ public object GetSectionData(string sectionName)
+ {
+ foreach (var item in this._sectionStack)
+ {
+ if (string.Equals(item.Name, sectionName, StringComparison.CurrentCultureIgnoreCase))
+ {
+ return item.Data;
+ }
+ }
+ return null;
}

//valueGetter.GetValue add a RenderContext param.
+ public abstract object GetValue(RenderContext renderContext);