Created
March 4, 2013 17:04
-
-
Save spullara/5083747 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.