本文整理汇总了Java中org.jtwig.JtwigModel.with方法的典型用法代码示例。如果您正苦于以下问题:Java JtwigModel.with方法的具体用法?Java JtwigModel.with怎么用?Java JtwigModel.with使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.jtwig.JtwigModel
的用法示例。
在下文中一共展示了JtwigModel.with方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: renderElement
import org.jtwig.JtwigModel; //导入方法依赖的package包/类
private String renderElement(Map<String, String> data) {
// Cache template contents
if (template == null) {
if (this.templateAbsolutePath != "") {
System.err.println(
"Load tempate by absolute path: " + this.templateAbsolutePath);
template = JtwigTemplate.fileTemplate(this.templateAbsolutePath);
} else {
System.err
.println("Load tempate by resource path: " + this.templateName);
template = JtwigTemplate.classpathTemplate(this.templateName);
}
}
JtwigModel model = JtwigModel.newModel();
for (String key : data.keySet()) {
// System.err.println(String.format("\"%s\" = \"%s\"", key,
// data.get(key)));
model.with(key, data.get(key).replace("\"", "\\\""));
}
String output = template.render(model);
// System.err.println("renderElement : " + output);
return output;
}
示例2: longFirstArgEvaluation
import org.jtwig.JtwigModel; //导入方法依赖的package包/类
@Test
public void longFirstArgEvaluation() throws Exception {
JtwigModel model = new JtwigModel();
model.with("var", 5L);
String result = JtwigTemplate.inlineTemplate("{{ var == 5 }}")
.render(model);
assertThat(result, is(equalTo("true")));
}
示例3: longSecondArgEvaluation
import org.jtwig.JtwigModel; //导入方法依赖的package包/类
@Test
public void longSecondArgEvaluation() throws Exception {
JtwigModel model = new JtwigModel();
model.with("var", 5L);
String result = JtwigTemplate.inlineTemplate("{{ 5 == var }}")
.render(model);
assertThat(result, is(equalTo("true")));
}
示例4: issue86WithVariable
import org.jtwig.JtwigModel; //导入方法依赖的package包/类
@Test
public void issue86WithVariable() throws Exception {
JtwigModel model = new JtwigModel();
model.with("value", 1);
String result = JtwigTemplate
.inlineTemplate("{{ value-1 }}")
.render(model);
assertThat(result, is(equalTo("0")));
}
示例5: issue86WithVariableUnary
import org.jtwig.JtwigModel; //导入方法依赖的package包/类
@Test
public void issue86WithVariableUnary() throws Exception {
JtwigModel model = new JtwigModel();
model.with("value", -1);
String result = JtwigTemplate
.inlineTemplate("{{ -value }}")
.render(model);
assertThat(result, is(equalTo("1")));
}
示例6: issue75IsNull
import org.jtwig.JtwigModel; //导入方法依赖的package包/类
@Test
public void issue75IsNull() throws Exception {
JtwigModel model = new JtwigModel();
model.with("a", new NullPointer());
String result = JtwigTemplate
.inlineTemplate("{% if (a.value is null) %}A{% else %}B{% endif %}")
.render(model);
assertThat(result, containsString("A"));
}
示例7: issue75IsNullWithParentheses
import org.jtwig.JtwigModel; //导入方法依赖的package包/类
@Test
public void issue75IsNullWithParentheses() throws Exception {
JtwigModel model = new JtwigModel();
model.with("a", new NullPointer());
String result = JtwigTemplate
.inlineTemplate("{% if (a.value) is null %}A{% else %}B{% endif %}")
.render(model);
assertThat(result, containsString("A"));
}
示例8: notDefinedMethod
import org.jtwig.JtwigModel; //导入方法依赖的package包/类
@Test
public void notDefinedMethod() throws Exception {
JtwigModel model = new JtwigModel();
model.with("a", "test");
String result = JtwigTemplate
.inlineTemplate("{% if (a.check) is not defined %}A{% endif %}")
.render(model);
assertThat(result, is(equalTo("A")));
}
示例9: testUTFEncoding
import org.jtwig.JtwigModel; //导入方法依赖的package包/类
@Test
public void testUTFEncoding() throws Exception {
JtwigModel model = new JtwigModel();
model.with("text", "tête de bou 간편한 설치 및 사용");
String result = JtwigTemplate
.inlineTemplate("{{ text }}", configuration()
.render().withOutputCharset(Charset.forName("UTF-8")).and()
.build())
.render(model);
assertThat(result, is(equalTo("tête de bou 간편한 설치 및 사용")));
}
示例10: testTemplateTrue
import org.jtwig.JtwigModel; //导入方法依赖的package包/类
@Test
public void testTemplateTrue() throws Exception {
JtwigModel model = new JtwigModel();
model.with("value", true);
String result = JtwigTemplate.inlineTemplate("{{ value ? '1' : '2' }}")
.render(model);
assertThat(result, is(equalTo("1")));
}
示例11: isIterableArrayFunction
import org.jtwig.JtwigModel; //导入方法依赖的package包/类
@Test
public void isIterableArrayFunction () throws Exception {
JtwigModel model = new JtwigModel();
model.with("value", new Object[0]);
String result = JtwigTemplate.inlineTemplate("{% if (value is iterable) %}Hi{% endif %}")
.render(model);
assertThat(result, is(equalTo("Hi")));
}
示例12: isIterableMapFunction
import org.jtwig.JtwigModel; //导入方法依赖的package包/类
@Test
public void isIterableMapFunction () throws Exception {
JtwigModel model = new JtwigModel();
model.with("value", Collections.EMPTY_MAP);
String result = JtwigTemplate.inlineTemplate("{% if (value is iterable) %}Hi{% endif %}")
.render(model);
assertThat(result, is(equalTo("Hi")));
}
示例13: isNullFunction
import org.jtwig.JtwigModel; //导入方法依赖的package包/类
@Test
public void isNullFunction () throws Exception {
JtwigModel model = new JtwigModel();
model.with("value", null);
String result = JtwigTemplate.inlineTemplate("{% if (value is null) %}Hi{% endif %}")
.render(model);
assertThat(result, is(equalTo("Hi")));
}
示例14: handle
import org.jtwig.JtwigModel; //导入方法依赖的package包/类
@Override
protected String handle(final RequestHandler requestHandler, final AbstractRequest request, final String in)
{
String out = in;
JtwigTemplate template = null;
boolean shouldCache = false;
if ( templateStorage.containsKey( requestHandler.getName() ) )
{
template = templateStorage.get( requestHandler.getName() );
} else
{
shouldCache = true;
}
if ( template == null )
{
template = JtwigTemplate.inlineTemplate( out, configuration );
if ( shouldCache )
{
templateStorage.put( requestHandler.getName(), template );
}
}
final JtwigModel model = JtwigModel.newModel();
final Map<String, ProviderFactory<? extends VariableProvider>> factories = new HashMap<>();
for ( final ProviderFactory<? extends VariableProvider> factory : TemplateManager.get().getProviders() )
{
factories.put( factory.providerName().toLowerCase( Locale.ENGLISH ), factory );
}
final ProviderFactory<? extends VariableProvider> z = requestHandler.getFactory( request );
if ( z != null )
{
factories.put( z.providerName().toLowerCase( Locale.ENGLISH ), z );
}
factories.putAll( request.getModels() );
factories.put( "request", request );
for ( final Map.Entry<String, ProviderFactory<? extends VariableProvider>> entry : factories.entrySet() )
{
final Map<String, Object> entryObjects = new HashMap<>();
final Optional<? extends VariableProvider> providerOptional = entry.getValue().get( request );
if ( !providerOptional.isPresent() )
{
continue;
}
final VariableProvider provider = providerOptional.get();
entryObjects.putAll( provider.getAll() );
model.with( entry.getKey(), entryObjects );
}
out = template.render( model );
return out;
}