本文整理汇总了Java中org.trimou.engine.resolver.MapResolver类的典型用法代码示例。如果您正苦于以下问题:Java MapResolver类的具体用法?Java MapResolver怎么用?Java MapResolver使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
MapResolver类属于org.trimou.engine.resolver包,在下文中一共展示了MapResolver类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: init
import org.trimou.engine.resolver.MapResolver; //导入依赖的package包/类
@Override
public synchronized void init(ProcessingEnvironment processingEnv) {
super.init(processingEnv);
types = processingEnv.getTypeUtils();
elements = processingEnv.getElementUtils();
filer = processingEnv.getFiler();
messager = processingEnv.getMessager();
engine = MustacheEngineBuilder
.newBuilder()
.addResolver(new MapResolver())
.addResolver(new ReflectionResolver())
.setProperty(EngineConfigurationKey.DEFAULT_FILE_ENCODING, StandardCharsets.UTF_8.name())
.addTemplateLocator(ClassPathTemplateLocator.builder(1)
.setClassLoader(this.getClass().getClassLoader())
.setSuffix("mustache").build())
.build();
messager.printMessage(NOTE, ApiGeneratorProcessor.class.getSimpleName() + " loaded");
}
示例2: testOutOfBoundIndexException
import org.trimou.engine.resolver.MapResolver; //导入依赖的package包/类
@Test
public void testOutOfBoundIndexException()
throws JsonIOException, JsonSyntaxException, FileNotFoundException {
// https://github.com/trimou/trimou/issues/73
String json = "{\"numbers\": [1,2]}";
String template = "One of users is {{numbers.2}}.";
final JsonElement jsonElement = new JsonParser().parse(json);
MustacheEngine engine = MustacheEngineBuilder.newBuilder()
.setMissingValueHandler(
new ThrowingExceptionMissingValueHandler())
.omitServiceLoaderConfigurationExtensions()
.setProperty(JsonElementResolver.UNWRAP_JSON_PRIMITIVE_KEY,
true)
.setProperty(GsonValueConverter.ENABLED_KEY, false)
.addResolver(new ThisResolver()).addResolver(new MapResolver())
.addResolver(new JsonElementResolver()).build();
final Mustache mustache = engine.compileMustache("unwrap_array_index",
template);
MustacheExceptionAssert.expect(MustacheProblem.RENDER_NO_VALUE)
.check(() -> mustache.render(jsonElement));
}
示例3: testOutOfBoundIndexException
import org.trimou.engine.resolver.MapResolver; //导入依赖的package包/类
@Test
public void testOutOfBoundIndexException() throws FileNotFoundException {
// https://github.com/trimou/trimou/issues/73
String json = "{\"numbers\": [1,2]}";
String template = "One of users is {{numbers.2}}.";
JsonStructure jsonStructure = Json.createReader(new StringReader(json))
.read();
MustacheEngine engine = MustacheEngineBuilder.newBuilder()
.setMissingValueHandler(
new ThrowingExceptionMissingValueHandler())
.omitServiceLoaderConfigurationExtensions()
.setProperty(JsonValueResolver.ENABLED_KEY, true)
.setProperty(JsonProcessingValueConverter.ENABLED_KEY, false)
.addResolver(new ThisResolver()).addResolver(new MapResolver())
.addResolver(new JsonValueResolver()).build();
final Mustache mustache = engine.compileMustache("unwrap_array_index",
template);
MustacheExceptionAssert.expect(MustacheProblem.RENDER_NO_VALUE)
.check(() -> mustache.render(jsonStructure));
}
示例4: getEngine
import org.trimou.engine.resolver.MapResolver; //导入依赖的package包/类
private MustacheEngine getEngine() {
return MustacheEngineBuilder.newBuilder()
.omitServiceLoaderConfigurationExtensions()
.setProperty(JsonElementResolver.UNWRAP_JSON_PRIMITIVE_KEY,
true)
.setProperty(GsonValueConverter.ENABLED_KEY, false)
.addResolver(new ThisResolver()).addResolver(new MapResolver())
.addResolver(new JsonElementResolver()).build();
}
示例5: testInterpolation
import org.trimou.engine.resolver.MapResolver; //导入依赖的package包/类
@Test
public void testInterpolation() {
MustacheEngine engine = MustacheEngineBuilder.newBuilder()
.omitServiceLoaderConfigurationExtensions()
.setProperty(PrettyTimeResolver.ENABLED_KEY, true)
.setLocaleSupport(FixedLocaleSupport.from(Locale.ENGLISH))
.addResolver(new MapResolver())
.addResolver(new PrettyTimeResolver()).build();
String expected = new Resources_en().getString("JustNowPastPrefix");
// JustNow (the first time unit in the default list) has max quantity 1 min
Calendar now = Calendar.getInstance();
now.add(Calendar.SECOND, -30);
assertEquals(expected,
engine.compileMustache("pretty_cal", "{{now.prettyTime}}")
.render(ImmutableMap.<String, Object> of("now", now)));
assertEquals(expected,
engine.compileMustache("pretty_date", "{{now.prettyTime}}")
.render(ImmutableMap.<String, Object> of("now",
now.getTime())));
assertEquals(expected,
engine.compileMustache("pretty_long", "{{now.prettyTime}}")
.render(ImmutableMap.<String, Object> of("now",
now.getTimeInMillis())));
}
示例6: getEngine
import org.trimou.engine.resolver.MapResolver; //导入依赖的package包/类
private MustacheEngine getEngine() {
return MustacheEngineBuilder.newBuilder()
.omitServiceLoaderConfigurationExtensions()
.addResolver(new ThisResolver()).addResolver(new MapResolver())
.addResolver(new JsonValueResolver())
.setProperty(JsonValueResolver.ENABLED_KEY, true)
.setProperty(JsonProcessingValueConverter.ENABLED_KEY, false)
.build();
}
示例7: register
import org.trimou.engine.resolver.MapResolver; //导入依赖的package包/类
@Override
public void register(ConfigurationExtensionBuilder builder) {
// Add built-in resolvers
builder.addResolver(new ReflectionResolver());
builder.addResolver(new ThisResolver());
builder.addResolver(new MapResolver());
builder.addResolver(new CombinedIndexResolver());
// Add built-in helpers
registerHelpers(builder, HelpersBuilder.builtin().build());
}