本文整理汇总了Java中org.trimou.util.ImmutableMap类的典型用法代码示例。如果您正苦于以下问题:Java ImmutableMap类的具体用法?Java ImmutableMap怎么用?Java ImmutableMap使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ImmutableMap类属于org.trimou.util包,在下文中一共展示了ImmutableMap类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: generateArrayProperty
import org.trimou.util.ImmutableMap; //导入依赖的package包/类
/**
* @param type
* @param property
*/
private void generateArrayProperty(ArrayTypeDeclaration property) {
String fieldName = Names.buildVariableName(property);
String itemTypeName = context.getApiModel().getItemType(property);
String typeVar = Annotations.findTypeVar(property);
String tsItemType;
if (typeVar != null) {
tsItemType = typeVar;
}
else {
tsItemType = itemTypeName;
}
MustacheEngine engine = context.getTemplateEngine().getEngine();
Map<String, String> contextObject = ImmutableMap.of("name", fieldName, "tsPropType",
tsItemType + "[]");
engine.getMustache("property").render(context.getOutput(), contextObject);
}
示例2: generateProperty
import org.trimou.util.ImmutableMap; //导入依赖的package包/类
/**
* @param type
* @param property
*/
private void generateProperty(TypeDeclaration property) {
String fieldName = Names.buildVariableName(property);
String tsPropType;
String typeVar = Annotations.findTypeVar(property);
if (typeVar != null) {
tsPropType = typeVar;
}
else {
tsPropType = propertyTypeWithArgs(property);
}
MustacheEngine engine = context.getTemplateEngine().getEngine();
Map<String, String> contextObject = ImmutableMap.of("name", fieldName, "tsPropType",
tsPropType);
engine.getMustache("property").render(context.getOutput(), contextObject);
}
示例3: testInterpolation
import org.trimou.util.ImmutableMap; //导入依赖的package包/类
@Test
public void testInterpolation(Alpha alpha, Bravo bravo, Charlie charlie) {
assertNotNull(alpha);
assertNotNull(bravo);
assertNotNull(charlie);
assertNotNull(engine);
Mustache mustache = engine
.compileMustache(
"cdi_bean_resolver",
"{{hello}}: {{#alpha}}{{id}} {{bravo.age}}{{/alpha}} {{bravo.getId}} {{charlie.id}}{{neverExisted}}");
String result = String.format("Hello: %s 78 %s %s", alpha.getId(),
bravo.getId(), charlie.getId());
Map<String, Object> data = ImmutableMap.of("hello", "Hello");
assertEquals(result, mustache.render(data));
assertEquals(result, mustache.render(data));
}
示例4: testHelper
import org.trimou.util.ImmutableMap; //导入依赖的package包/类
@Test
public void testHelper() {
MustacheEngine engine = MustacheEngineBuilder.newBuilder().build();
assertEquals("true", engine.compileMustache("elhelper_01", "{{el 'this eq this'}}").render(true));
assertEquals("yes", engine.compileMustache("elhelper_02", "{{#el 'this gt 10'}}yes{{/el}}").render(10));
assertEquals("yes", engine.compileMustache("elhelper_03", "{{#el 'this < 1'}}yes{{/el}}").render(0));
assertEquals("10", engine.compileMustache("elhelper_04", "{{el 'this.age'}}").render(new Hammer(10)));
assertEquals("1two",
engine.compileMustache("elhelper_05", "{{#el '[1, \"two\"]'}}{{#each this}}{{this}}{{/each}}{{/el}}")
.render(null));
assertEquals(
"123", engine
.compileMustache("elhelper_06",
"{{#el '{\"one\":1, \"two\":2, \"three\":3}'}}{{one}}{{two}}{{three}}{{/el}}")
.render(null));
assertEquals("no", engine.compileMustache("elhelper_07", "{{el 'this ? \"yes\" : \"no\"'}}").render(false));
assertEquals("10", engine.compileMustache("elhelper_08", "{{#el 'foo < bar ? foo : bar'}}{{this}}{{/el}}")
.render(ImmutableMap.of("foo", 10, "bar", 20)));
}
示例5: Template
import org.trimou.util.ImmutableMap; //导入依赖的package包/类
/**
*
* @param generatedId
* @param name
* @param engine
* @param nestedTemplates
*/
public Template(Long generatedId, String name, MustacheEngine engine,
List<Template> nestedTemplates) {
this.generatedId = generatedId;
this.name = name;
this.engine = engine;
this.globalExecutionContext = ExecutionContexts
.newGlobalExecutionContext(engine.getConfiguration());
if (nestedTemplates == null || nestedTemplates.isEmpty()) {
this.nestedTemplates = Collections.emptyMap();
} else {
ImmutableMapBuilder<String, Template> builder = ImmutableMap
.builder();
for (Template template : nestedTemplates) {
builder.put(template.getName(), template);
}
this.nestedTemplates = builder.build();
}
}
示例6: testReturnValueInterpolated
import org.trimou.util.ImmutableMap; //导入依赖的package包/类
@Test
public void testReturnValueInterpolated() {
Lambda lambda = new InputProcessingLambda() {
@Override
public String invoke(String text) {
return "{{foo}}|{{foo}}";
}
@Override
public boolean isReturnValueInterpolated() {
return true;
}
};
assertEquals(
"true|true",
engine.compileMustache("lambda_return_interpolated",
"{{#lambda}}Hello{{/lambda}}").render(
ImmutableMap.of("foo", "true", "lambda", lambda)));
lambda = (input) -> "{{foo}}|{{foo}}";
assertEquals(
"true|true",
engine.compileMustache("lambda_return_interpolated2",
"{{#lambda}}Hello{{/lambda}}").render(
ImmutableMap.of("foo", "true", "lambda", lambda)));
}
示例7: testAsyncHelper
import org.trimou.util.ImmutableMap; //导入依赖的package包/类
@Test
public void testAsyncHelper() {
MustacheEngine engine = MustacheEngineBuilder.newBuilder()
.setExecutorService(Executors.newFixedThreadPool(
Runtime.getRuntime().availableProcessors()))
.registerHelpers(
HelpersBuilder.empty().addAsync().addInclude().build())
.addTemplateLocator(new MapTemplateLocator(
ImmutableMap.of("template", "async")))
.build();
assertEquals("Hello async world!!",
engine.compileMustache("async_helper01",
"Hello {{#async}}{{include templateName}} {{world}}{{/async}}!")
.render(ImmutableMap.of("templateName", "template",
"world", "world!")));
}
示例8: testAsyncHelperNested
import org.trimou.util.ImmutableMap; //导入依赖的package包/类
@Test
public void testAsyncHelperNested() {
MustacheEngine engine = MustacheEngineBuilder.newBuilder()
.setExecutorService(Executors.newFixedThreadPool(
Runtime.getRuntime().availableProcessors()))
.registerHelpers(
HelpersBuilder.empty().addAsync().addInclude().build())
.addTemplateLocator(new MapTemplateLocator(
ImmutableMap.of("template", "async")))
.build();
assertEquals("Hello async world! No!",
engine.compileMustache("async_helper02",
"Hello {{#async}}{{include templateName}} {{#async}}{{#async}}{{world}}{{/async}}{{/async}}{{#async}}!{{/async}}{{/async}}{{#async}} No{{/async}}!")
.render(ImmutableMap.of("templateName", "template",
"world", "world")));
}
示例9: testNumericExpressionHelperInstanceForEachOperator
import org.trimou.util.ImmutableMap; //导入依赖的package包/类
@Test
public void testNumericExpressionHelperInstanceForEachOperator() {
final MustacheEngine engine = MustacheEngineBuilder.newBuilder()
.registerHelpers(
NumericExpressionHelper.forEachOperator().build())
.build();
assertEquals(
"foo", engine
.compileMustache("number_default_op1",
"{{#gt this 10}}foo{{/gt}}")
.render(11L));
assertEquals(
"foo", engine
.compileMustache("number_default_op2",
"{{#eq this 10}}foo{{/eq}}")
.render(10L));
assertEquals("yes",
engine.compileMustache("number_nin1",
"{{#nin val1 '0' '5'}}yes{{/nin}}")
.render(ImmutableMap.<String, Object> of("val1",
2, "val2", 1,
"val3", 10L, "val4",
BigDecimal.ZERO, "val5", BigInteger.ONE)));
}
示例10: testSetHelper
import org.trimou.util.ImmutableMap; //导入依赖的package包/类
@Test
public void testSetHelper() {
MustacheEngine engine = MustacheEngineBuilder.newBuilder()
.registerHelpers(HelpersBuilder.empty().addSet().build()).build();
assertEquals("hellohello", engine.compileMustache("set_helper01",
"{{foo}}{{bar}}{{#set foo=\"hello\"}}{{foo}}{{bar}}{{#set bar=foo}}{{bar}}{{/set}}{{/set}}{{foo}}{{bar}}")
.render(null));
assertEquals("helloping1",
engine.compileMustache("set_helper02",
"{{#set foo=\"hello\" bar=\"ping\" qux=one}}{{foo}}{{bar}}{{qux}}{{/set}}")
.render(ImmutableMap.of("one", BigDecimal.ONE)));
assertEquals("helloworld",
engine.compileMustache("set_helper03",
"{{#set foo=['hello','world']}}{{#each foo}}{{this}}{{/each}}{{/set}}")
.render(null));
}
示例11: testEmbeddedHelper
import org.trimou.util.ImmutableMap; //导入依赖的package包/类
@Test
public void testEmbeddedHelper() {
MustacheEngine engine = MustacheEngineBuilder
.newBuilder()
.registerHelpers(HelpersBuilder.empty().addEmbed().build())
.addTemplateLocator(
new MapTemplateLocator(ImmutableMap.of("template",
"Hello!"))).build();
assertEquals(
"<script id=\"template\" type=\"text/template\">\nHello!\n</script>",
engine.compileMustache("embed_helper01", "{{embed this}}")
.render("template"));
assertEquals(
"<script id=\"template\" type=\"text/template\">\nHello!\n</script>",
engine.compileMustache("embed_helper01", "{{embed 'temp' this}}")
.render("late"));
}
示例12: testCustomSourceProcessor
import org.trimou.util.ImmutableMap; //导入依赖的package包/类
@Test
public void testCustomSourceProcessor() {
MustacheEngine engine = MustacheEngineBuilder
.newBuilder()
.registerHelpers(
HelpersBuilder.empty()
.addEmbed((mustacheName, mustacheSource) ->
new StringBuilder()
.append("<source>")
.append(mustacheSource)
.append("</source>")
.toString())
.build())
.addTemplateLocator(
new MapTemplateLocator(ImmutableMap.of("template",
"{{foo}}"))).build();
assertEquals(
"<source>{{foo}}</source>",
engine.compileMustache("embed_helper02", "{{embed 'template'}}")
.render(null));
}
示例13: testPartial
import org.trimou.util.ImmutableMap; //导入依赖的package包/类
@Test
public void testPartial() {
final MustacheEngine engine = MustacheEngineBuilder.newBuilder()
.addTemplateLocator(new MapTemplateLocator(
ImmutableMap.of("foo", "{{this}}")))
.registerHelper("test", new AbstractHelper() {
@Override
public void execute(Options options) {
options.partial(
options.getParameters().get(0).toString());
}
}).build();
assertEquals("HELLO",
engine.compileMustache("helper_partial01", "{{test 'foo'}}")
.render("HELLO"));
MustacheExceptionAssert
.expect(MustacheProblem.RENDER_INVALID_PARTIAL_KEY)
.check(() -> engine
.compileMustache("helper_partial02", "{{test 'bar'}}")
.render("HELLO"));
}
示例14: testSource
import org.trimou.util.ImmutableMap; //导入依赖的package包/类
@Test
public void testSource() {
final MustacheEngine engine = MustacheEngineBuilder.newBuilder()
.addTemplateLocator(new MapTemplateLocator(
ImmutableMap.of("foo", "{{this}}")))
.registerHelper("test", new AbstractHelper() {
@Override
public void execute(Options options) {
append(options, options.source(
options.getParameters().get(0).toString()));
}
}).build();
assertEquals("{{this}}",
engine.compileMustache("helper_source01", "{{test 'foo'}}")
.render(null));
MustacheExceptionAssert
.expect(MustacheProblem.RENDER_INVALID_PARTIAL_KEY)
.check(() -> engine
.compileMustache("helper_source02", "{{test 'bar'}}")
.render(null));
}
示例15: testHelper
import org.trimou.util.ImmutableMap; //导入依赖的package包/类
@Test
public void testHelper() {
final MustacheEngine engine = MustacheEngineBuilder.newBuilder()
.registerHelpers(HelpersBuilder.empty().addEval().build())
.build();
String[] array = { "alpha", "bravo", "charlie" };
List<String> list = ImmutableList.of("foo", "bar", "baz");
Map<String, Object> data = ImmutableMap
.of("array", array, "list", list);
assertEquals(
"foo:alpha,bar:bravo,baz:charlie",
engine.compileMustache(
"eval_helper1",
"{{#each list}}{{this}}:{{eval 'array' iter.position}}{{#if iter.hasNext}},{{/if}}{{/each}}")
.render(data));
}