Skip to content

Instantly share code, notes, and snippets.

@spullara
Created March 4, 2013 17:04
Show Gist options
  • Save spullara/5083747 to your computer and use it in GitHub Desktop.
Save spullara/5083747 to your computer and use it in GitHub Desktop.
public void testFunctions2() {
Map<String, Object> scopes = new HashMap<String, Object>();
scopes.put("map", new HashMap<String, String>(){{put("key", "value");}});
final Function<String, String> upperFunction = new Function<String, String>()
{
@Override
public String apply(String aInput)
{
return aInput.toUpperCase();
}
};
scopes.put("upper", upperFunction);
Writer writer = new StringWriter();
MustacheFactory mf = new DefaultMustacheFactory();
Mustache mustache = mf.compile(new StringReader("map.key={{map.key}}{{#upper}}, in #upper map.key={{map.key}}{{/upper}} \n" +
"in #map{{#map}}, in #upper {{#upper}} keyInUpper={{key}} {{/upper}} {{/map}} "), "example");
mustache.execute(writer, scopes);
try
{
writer.flush();
}
catch (IOException e)
{
//
}
assertEquals("map.key=value, IN #UPPER MAP.KEY=VALUE \nin #map, in #upper KEYINUPPER=VALUE ", writer.toString());
}
@alexandrenavarro
Copy link

I tried and it does not work. I discovered I'm not using the last version of mustach. I used mustache 0.8.4, jdk 1.6 and guava 14.0-rc3. When I used 0.8.10, it works. Sorry.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment