Skip to content

Commit 366df34

Browse files
author
Sam Pullara
committed
Partial code didnt have a proper identity callback.
1 parent e1e3b8a commit 366df34

4 files changed

Lines changed: 37 additions & 1 deletion

File tree

compiler/src/main/java/com/github/mustachejava/codes/PartialCode.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import com.github.mustachejava.TemplateContext;
88
import com.github.mustachejava.util.LatchedWriter;
99

10+
import java.io.IOException;
1011
import java.io.Writer;
1112
import java.util.concurrent.Callable;
1213
import java.util.concurrent.ExecutorService;
@@ -30,6 +31,21 @@ public PartialCode(TemplateContext tc, DefaultMustacheFactory cf, String variabl
3031
this(tc, cf, null, ">", variable);
3132
}
3233

34+
@Override
35+
public void identity(Writer writer) {
36+
try {
37+
if (name != null) {
38+
writer.write(tc.startChars());
39+
writer.write(type);
40+
writer.write(name);
41+
writer.write(tc.endChars());
42+
}
43+
appendText(writer);
44+
} catch (IOException e) {
45+
throw new MustacheException(e);
46+
}
47+
}
48+
3349
@Override
3450
public Code[] getCodes() {
3551
return partial.getCodes();

compiler/src/test/java/com/github/mustachejava/InterpreterTest.java

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import org.codehaus.jackson.JsonNode;
99
import org.codehaus.jackson.map.MappingJsonFactory;
1010

11+
import javax.annotation.Nullable;
1112
import java.io.*;
1213
import java.util.Arrays;
1314
import java.util.HashMap;
@@ -274,7 +275,24 @@ public void testPartial() throws MustacheException, IOException {
274275
assertEquals(getContents(root, "template_partial.txt"), sw.toString());
275276
}
276277

277-
public void testComplex() throws MustacheException, IOException {
278+
public void testPartialWithTF() throws MustacheException, IOException {
279+
MustacheFactory c = init();
280+
Mustache m = c.compile("partialintemplatefunction.html");
281+
StringWriter sw = new StringWriter();
282+
m.execute(sw, new Object() {
283+
public TemplateFunction i() {
284+
return new TemplateFunction() {
285+
@Override
286+
public String apply(@Nullable String s) {
287+
return s;
288+
}
289+
};
290+
}
291+
});
292+
assertEquals("This is not interesting.", sw.toString());
293+
}
294+
295+
public void testComplex() throws MustacheException, IOException {
278296
StringWriter json = new StringWriter();
279297
MappingJsonFactory jf = new MappingJsonFactory();
280298
final JsonGenerator jg = jf.createJsonGenerator(json);
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{{#i}}This is {{>uninterestingpartial}}{{/i}}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
not interesting.

0 commit comments

Comments
 (0)