Resolves issue 7 regarding proper handling of nested contexts when processing a
nested context.
This commit is contained in:
@@ -458,7 +458,9 @@ public class Mustache
|
||||
_template = compiler.compile(r);
|
||||
}
|
||||
@Override public void execute (Template tmpl, Template.Context ctx, Writer out) {
|
||||
_template.execute(ctx.data, out);
|
||||
// we must take care to preserve our context rather than creating a new one, which
|
||||
// would happen if we just called execute() with ctx.data
|
||||
_template.executeSegs(ctx, out);
|
||||
}
|
||||
protected final Template _template;
|
||||
}
|
||||
|
||||
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user