本文整理了Java中com.github.mustachejava.Mustache.execute()
方法的一些代码示例,展示了Mustache.execute()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Mustache.execute()
方法的具体详情如下:
包路径:com.github.mustachejava.Mustache
类名称:Mustache
方法名:execute
[英]Execute the mustache object with a given writer and a single scope context.
[中]使用给定的编写器和单个作用域上下文执行mustache对象。
代码示例来源:origin: spullara/mustache.java
private String render(Mustache template, Object data) {
Writer writer = new StringWriter();
template.execute(writer, data);
return writer.toString();
}
代码示例来源:origin: spullara/mustache.java
String compile(String template, Object model) {
final StringWriter buffer = new StringWriter();
factory.compile(template).execute(buffer, model);
return buffer.toString();
}
代码示例来源:origin: spullara/mustache.java
private void verifyOutput(String expected, Object model, Mustache mustache) {
StringWriter writer = new StringWriter();
mustache.execute(writer, model);
assertEquals(expected, writer.toString());
}
代码示例来源:origin: spullara/mustache.java
private void time(Mustache parse, Object parent) {
long start;
start = System.currentTimeMillis();
for (int i = 0; i < 500; i++) {
parse.execute(new StringWriter(), parent);
}
System.out.println((System.currentTimeMillis() - start));
}
代码示例来源:origin: spullara/mustache.java
@SuppressWarnings("unchecked")
protected void handleFunction(Writer writer, Function function, List<Object> scopes) throws IOException {
String value;
Object newtemplate = function.apply(null);
if (newtemplate == null) {
value = "";
} else {
String templateText = newtemplate.toString();
StringWriter sw = new StringWriter();
// The specification says that template functions need to be parsed with the default delimiters
// Running Interpolation - Alternate Delimiters - A lambda's return value should parse with the default delimiters.: failed!
// TemplateContext newTC = new TemplateContext(tc.startChars(), tc.endChars(), tc.file(), tc.line(), tc.startOfLine());
TemplateContext newTC = new TemplateContext(DEFAULT_SM, DEFAULT_EM, tc.file(), tc.line(), tc.startOfLine());
df.getFragment(new FragmentKey(newTC, templateText)).execute(sw, scopes).close();
value = sw.toString();
}
execute(writer, value);
}
代码示例来源:origin: spullara/mustache.java
@Test
public void testDotNotationWithNull() throws IOException {
DefaultMustacheFactory mf = new DefaultMustacheFactory();
Mustache m = mf.compile(new StringReader("[{{category.name}}]"), "test");
StringWriter sw = new StringWriter();
Map map = new HashMap();
map.put("category", null);
m.execute(sw, map).close();
}
}
代码示例来源:origin: spullara/mustache.java
@Test
public void textExplicitNullMapValue() {
Map<String, Object> model = new HashMap<>();
model.put("nullData", null);
StringWriter writer = new StringWriter();
mustache.execute(writer, model);
assertEquals("", writer.toString());
}
代码示例来源:origin: spullara/mustache.java
private StringWriter execute(String name, Object object) {
MustacheFactory c = createMustacheFactory();
Mustache m = c.compile(name);
StringWriter sw = new StringWriter();
m.execute(sw, object);
return sw;
}
代码示例来源:origin: spullara/mustache.java
public void testMultipleCallsWithDifferentScopes() throws IOException {
String template = "Value: {{value}}";
Mustache mustache = new DefaultMustacheFactory().compile(new StringReader(
template), "test");
// scope object doesn't have a 'value' property, lookup will fail
mustache.execute(new StringWriter(), new Object());
// scope object has a 'value' property, lookup shouldn't fail
StringWriter sw = new StringWriter();
mustache.execute(sw, new Object() {
String value = "something";
});
assertEquals("Value: something", sw.toString());
}
代码示例来源:origin: spullara/mustache.java
private StringWriter execute(String name, List<Object> objects) {
MustacheFactory c = createMustacheFactory();
Mustache m = c.compile(name);
StringWriter sw = new StringWriter();
m.execute(sw, objects);
return sw;
}
代码示例来源:origin: spullara/mustache.java
public void testImplicitIteratorNoScope() throws IOException {
Mustache test = new DefaultMustacheFactory().compile(new StringReader("{{.}}"), "test");
StringWriter sw = new StringWriter();
test.execute(sw, "").close();
assertEquals("", sw.toString());
StringWriter sw2 = new StringWriter();
test.execute(sw2, new Object[0]).close();
assertEquals("", sw2.toString());
}
代码示例来源:origin: spullara/mustache.java
private String getOutput(final boolean setObjectHandler) {
final DefaultMustacheFactory mustacheFactory = new DefaultMustacheFactory();
if (setObjectHandler) {
mustacheFactory.setObjectHandler(new SimpleObjectHandler());
}
final Mustache defaultMustache = mustacheFactory.compile(new StringReader("{{#okGenerator.isItOk}}{{okGenerator.isItOk}}{{/okGenerator.isItOk}}"), "Test template");
final Map<String, Object> params = new HashMap<>();
params.put("okGenerator", new OkGenerator());
final Writer writer = new StringWriter();
defaultMustache.execute(writer, params);
return writer.toString();
}
代码示例来源:origin: spullara/mustache.java
public void testMultipleCallsWithDifferentMapScopes() throws IOException {
String template = "Value: {{value}}";
Mustache mustache = new DefaultMustacheFactory().compile(new StringReader(
template), "test");
Map<String, String> emptyMap = new HashMap<>();
Map<String, String> map = new HashMap<>();
map.put("value", "something");
// map doesn't have an entry for 'value', lookup will fail
mustache.execute(new StringWriter(), emptyMap);
// map has an entry for 'value', lookup shouldn't fail
StringWriter sw = new StringWriter();
mustache.execute(sw, map);
assertEquals("Value: something", sw.toString());
}
代码示例来源:origin: spullara/mustache.java
@Test
public void testXMLtoMapWithBase() throws IOException, SAXException, ParserConfigurationException {
Map<String, Object> map = convertXMLtoMap(xml2);
DefaultMustacheFactory dmf = new DefaultMustacheFactory();
Mustache response = dmf.compile(new StringReader(template2), "entries");
Object base = new Object() {
public String Base_URL = "http://www.google.com";
};
Writer execute = response.execute(new StringWriter(), new Object[] { base, map });
assertEquals(correct2, execute.toString());
}
代码示例来源:origin: spullara/mustache.java
public void testPropertyWithDot() throws IOException {
DefaultMustacheFactory mustacheFactory = new DefaultMustacheFactory();
Reader reader = new StringReader("value=${some.value}");
Mustache mustache = mustacheFactory.compile(reader, "maven", "${", "}");
Map<String, String> properties = new HashMap<>();
properties.put("some.value", "some.value");
StringWriter writer = new StringWriter();
mustache.execute(writer, new Object[]{properties}).close();
Assert.assertEquals("value=some.value", writer.toString());
}
代码示例来源:origin: spullara/mustache.java
@Test
public void testXMLtoMap() throws IOException, SAXException, ParserConfigurationException {
Map<String, Object> map = convertXMLtoMap(xml);
DefaultMustacheFactory dmf = new DefaultMustacheFactory();
Mustache response = dmf.compile(new StringReader(template), "response");
Writer execute = response.execute(new StringWriter(), map);
assertEquals(correct, execute.toString());
}
代码示例来源:origin: spullara/mustache.java
private void testMiss(Object model, String template) {
Mustache mustache = compile(template);
StringWriter writer = new StringWriter();
mustache.execute(writer, model);
assertEquals("", writer.toString());
}
代码示例来源:origin: spullara/mustache.java
public void testMalformedTag() {
try {
String template = "\n{{$value}}\n{/value}}";
Mustache mustache = new DefaultMustacheFactory().compile(new StringReader(template), "test");
StringWriter sw = new StringWriter();
mustache.execute(sw, new Object[0]);
fail("Should have failed to compile");
} catch (MustacheException e) {
assertEquals("Failed to close 'value' tag @[test:2]", e.getMessage());
}
}
代码示例来源:origin: spullara/mustache.java
public void testContextPrecedence() throws IOException {
Mustache m = new DefaultMustacheFactory().compile(new StringReader("{{#a}}{{b.c}}{{/a}}"), "test");
Map map = new ObjectMapper().readValue("{\"a\": {\"b\": {}}, \"b\": {\"c\": \"ERROR\"}}", Map.class);
StringWriter sw = new StringWriter();
m.execute(sw, map).close();
assertEquals("", sw.toString());
}
代码示例来源:origin: spullara/mustache.java
@Test
public void testIterable() throws IOException {
DefaultMustacheFactory dmf = new DefaultMustacheFactory();
Mustache test = dmf.compile(new StringReader("{{#values}}\ntest: {{value}}\n{{/values}}"), "test");
Node invert = test.invert("test: sam\ntest: fred\n");
Node node = new Node();
Node sam = new Node();
sam.put("value", value("sam"));
Node fred = new Node();
fred.put("value", value("fred"));
node.put("values", list(asList(sam, fred)));
assertEquals(node, invert);
StringWriter sw = new StringWriter();
test.execute(sw, invert).close();
System.out.println(sw);
}
内容来源于网络,如有侵权,请联系作者删除!