Formatting, and small javadoc improvement.
This commit is contained in:
@@ -40,20 +40,22 @@ public class Template
|
|||||||
* the variable context that was in effect at the time the lambda was called.
|
* the variable context that was in effect at the time the lambda was called.
|
||||||
*/
|
*/
|
||||||
public abstract class Fragment {
|
public abstract class Fragment {
|
||||||
/** Executes this template fragment, writing its result to {@code out}. */
|
/** Executes this fragment; writes its result to {@code out}. */
|
||||||
public abstract void execute (Writer out);
|
public abstract void execute (Writer out);
|
||||||
|
|
||||||
/** Executes this template fragment with the provided context, writing its result to {@code out}. */
|
/** Executes this fragment with the provided context; writes its result to {@code out}. The
|
||||||
|
* provided context will be nested in the fragment's bound context. */
|
||||||
public abstract void execute (Object context, Writer out);
|
public abstract void execute (Object context, Writer out);
|
||||||
|
|
||||||
/** Executes this template fragment and returns its result as a string. */
|
/** Executes this fragment and returns its result as a string. */
|
||||||
public String execute () {
|
public String execute () {
|
||||||
StringWriter out = new StringWriter();
|
StringWriter out = new StringWriter();
|
||||||
execute(out);
|
execute(out);
|
||||||
return out.toString();
|
return out.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Executes this template fragment with the provided context, and returns its result as a string. */
|
/** Executes this fragment with the provided context; returns its result as a string. The
|
||||||
|
* provided context will be nested in the fragment's bound context. */
|
||||||
public String execute (Object context) {
|
public String execute (Object context) {
|
||||||
StringWriter out = new StringWriter();
|
StringWriter out = new StringWriter();
|
||||||
execute(context, out);
|
execute(context, out);
|
||||||
@@ -105,15 +107,15 @@ public class Template
|
|||||||
|
|
||||||
protected Fragment createFragment (final Segment[] segs, final Context currentCtx) {
|
protected Fragment createFragment (final Segment[] segs, final Context currentCtx) {
|
||||||
return new Fragment() {
|
return new Fragment() {
|
||||||
@Override public void execute(Writer out) {
|
@Override public void execute (Writer out) {
|
||||||
execute(currentCtx, out);
|
execute(currentCtx, out);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public void execute(Object context, Writer out) {
|
@Override public void execute (Object context, Writer out) {
|
||||||
execute(currentCtx.nest(context, 0, false, false), out);
|
execute(currentCtx.nest(context, 0, false, false), out);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void execute(Context ctx, Writer out) {
|
private void execute (Context ctx, Writer out) {
|
||||||
for (Segment seg : segs) {
|
for (Segment seg : segs) {
|
||||||
seg.execute(Template.this, ctx, out);
|
seg.execute(Template.this, ctx, out);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -667,15 +667,14 @@ public class MustacheTest
|
|||||||
@Test public void testLambdaWithContext () {
|
@Test public void testLambdaWithContext () {
|
||||||
test("a in l1, a in l2", "{{#l1}}{{a}}{{/l1}}, {{#l2}}{{a}}{{/l2}}",
|
test("a in l1, a in l2", "{{#l1}}{{a}}{{/l1}}, {{#l2}}{{a}}{{/l2}}",
|
||||||
context("l1", new Mustache.Lambda() {
|
context("l1", new Mustache.Lambda() {
|
||||||
public void execute(Template.Fragment frag, Writer out) throws IOException {
|
public void execute (Template.Fragment frag, Writer out) throws IOException {
|
||||||
frag.execute(context("a", "a in l1"), out);
|
frag.execute(context("a", "a in l1"), out);
|
||||||
}
|
|
||||||
}, "l2", new Mustache.Lambda() {
|
|
||||||
public void execute(Template.Fragment frag, Writer out) throws IOException {
|
|
||||||
frag.execute(context("a", "a in l2"), out);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
));
|
}, "l2", new Mustache.Lambda() {
|
||||||
|
public void execute (Template.Fragment frag, Writer out) throws IOException {
|
||||||
|
frag.execute(context("a", "a in l2"), out);
|
||||||
|
}
|
||||||
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test public void testNonStandardDefaultDelims () {
|
@Test public void testNonStandardDefaultDelims () {
|
||||||
|
|||||||
Reference in New Issue
Block a user