Skip to content

Instantly share code, notes, and snippets.

@MattCheely
Created June 27, 2012 01:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MattCheely/3000611 to your computer and use it in GitHub Desktop.
Save MattCheely/3000611 to your computer and use it in GitHub Desktop.
Primary Book
Primary Book
Primary Book
Primary Book
Related Book 1
Related Book 2
@Test
public void testSurprisingBehavior() throws Exception {
final class Book {
public String title;
public Book(String title) {
this.title = title;
}
}
Map<String, Object> model = new HashMap<String, Object>();
model.put("book", new Book("Primary Book"));
List<Book> relatedBooks = new ArrayList<Book>();
relatedBooks.add(new Book("Related Book 1"));
relatedBooks.add(new Book("Related Book 2"));
model.put("relatedBooks", relatedBooks);
MustacheFactory factory = new DefaultMustacheFactory(root);
Mustache stache = factory.compile("unexpected.html");
StringWriter writer = new StringWriter();
stache.execute(writer, model);
assertEquals(getContents(root, "expectedOutput.txt"), writer.toString());
}
{{book.title}}
{{#relatedBooks}}
{{> book}}
{{/relatedBooks}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment