Resolves issue 7 regarding proper handling of nested contexts when processing a

nested context.
This commit is contained in:
Michael Bayne
2011-05-26 14:52:45 -07:00
parent 31d0a0985d
commit ef971015bd
3 changed files with 34 additions and 13 deletions
@@ -37,18 +37,6 @@ import java.util.concurrent.ConcurrentHashMap;
*/
public class Template
{
/**
* Executes this template with the given context, writing the results to the supplied writer.
* @throws MustacheException if an error occurs while executing or writing the template.
*/
public void execute (Object context, Writer out) throws MustacheException
{
Context ctx = new Context(context, null, 0, Mode.OTHER);
for (Segment seg : _segs) {
seg.execute(this, ctx, out);
}
}
/**
* Executes this template with the given context, returning the results as a string.
* @throws MustacheException if an error occurs while executing or writing the template.
@@ -60,12 +48,28 @@ public class Template
return out.toString();
}
/**
* Executes this template with the given context, writing the results to the supplied writer.
* @throws MustacheException if an error occurs while executing or writing the template.
*/
public void execute (Object context, Writer out) throws MustacheException
{
executeSegs(new Context(context, null, 0, Mode.OTHER), out);
}
protected Template (Segment[] segs, Mustache.Compiler compiler)
{
_segs = segs;
_compiler = compiler;
}
protected void executeSegs (Context ctx, Writer out) throws MustacheException
{
for (Segment seg : _segs) {
seg.execute(this, ctx, out);
}
}
/**
* Called by executing segments to obtain the value of the specified variable in the supplied
* context.