本文整理汇总了Java中org.trimou.engine.MustacheEngine类的典型用法代码示例。如果您正苦于以下问题:Java MustacheEngine类的具体用法?Java MustacheEngine怎么用?Java MustacheEngine使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MustacheEngine类属于org.trimou.engine包,在下文中一共展示了MustacheEngine类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: getEngine
import org.trimou.engine.MustacheEngine; //导入依赖的package包/类
/**
* Constructs a template engine with some additional helpers and lambdas for HTML generation.
*/
public MustacheEngine getEngine() {
if (engine == null) {
ClassPathTemplateLocator genericLocator = new ClassPathTemplateLocator(PRIO_CLASS_PATH,
TEMPLATE_PATH, TEMPLATE_SUFFIX);
MustacheEngineBuilder builder = MustacheEngineBuilder.newBuilder()
.setProperty(EngineConfigurationKey.DEFAULT_FILE_ENCODING,
StandardCharsets.UTF_8.name())
.addTemplateLocator(genericLocator)
.registerHelper(ExampleHelper.NAME, new ExampleHelper())
.registerHelper(TypeLinkHelper.NAME, new TypeLinkHelper())
.registerHelpers(HelpersBuilder.builtin().addInclude().addInvoke().addSet()
.addSwitch().addWith().build())
.addGlobalData(MarkdownLambda.NAME, new MarkdownLambda())
.addGlobalData(UpperCaseLambda.NAME, new UpperCaseLambda());
if (templateDir != null) {
builder.addTemplateLocator(
new FileSystemTemplateLocator(PRIO_FILE_SYSTEM, templateDir, TEMPLATE_SUFFIX));
}
engine = builder.build();
}
return engine;
}
开发者ID:ops4j,项目名称:org.ops4j.ramler,代码行数:26,代码来源:TemplateEngine.java
示例2: getEngine
import org.trimou.engine.MustacheEngine; //导入依赖的package包/类
/**
* Constructs a template engine with some additional helpers and lambdas for Typescript
* generation.
*/
public MustacheEngine getEngine() {
if (engine == null) {
ClassPathTemplateLocator genericLocator = new ClassPathTemplateLocator(PRIO_CLASS_PATH,
TEMPLATE_PATH, TEMPLATE_SUFFIX);
MustacheEngineBuilder builder = MustacheEngineBuilder.newBuilder()
.setProperty(EngineConfigurationKey.DEFAULT_FILE_ENCODING,
StandardCharsets.UTF_8.name())
.addTemplateLocator(genericLocator);
if (templateDir != null) {
builder.addTemplateLocator(
new FileSystemTemplateLocator(PRIO_FILE_SYSTEM, templateDir, TEMPLATE_SUFFIX));
}
engine = builder.build();
}
return engine;
}
开发者ID:ops4j,项目名称:org.ops4j.ramler,代码行数:21,代码来源:TypescriptTemplateEngine.java
示例3: generateArrayProperty
import org.trimou.engine.MustacheEngine; //导入依赖的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);
}
开发者ID:ops4j,项目名称:org.ops4j.ramler,代码行数:21,代码来源:ObjectBodyApiVisitor.java
示例4: generateProperty
import org.trimou.engine.MustacheEngine; //导入依赖的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);
}
开发者ID:ops4j,项目名称:org.ops4j.ramler,代码行数:20,代码来源:ObjectBodyApiVisitor.java
示例5: testEncoding
import org.trimou.engine.MustacheEngine; //导入依赖的package包/类
@Test
public void testEncoding() {
TemplateLocator locator = new ServletContextTemplateLocator(10,
"/templates", "html");
MustacheEngine engine = MustacheEngineBuilder.newBuilder()
.addTemplateLocator(locator)
.setProperty(EngineConfigurationKey.DEFAULT_FILE_ENCODING,
"windows-1250")
.build();
Mustache encoding = engine.getMustache("encoding");
assertNotNull(encoding);
assertEquals("Hurá ěščřřžžýá!", encoding.render(null));
}
开发者ID:trimou,项目名称:trimou,代码行数:17,代码来源:ServletContextTemplateLocatorTest.java
示例6: testMultipleInheritance
import org.trimou.engine.MustacheEngine; //导入依赖的package包/类
@Test
public void testMultipleInheritance() {
MapTemplateLocator locator = new MapTemplateLocator(
ImmutableMap
.of("super",
"for {{$insert}}{{/insert}}",
"sub",
"And now {{<super}} {{$insert}}something {{$insert2}}{{/insert2}} different{{/insert}} {{/super}}.",
"subsub",
"{{<sub}} {{$insert2}}completely{{/insert2}} {{/sub}}"));
MustacheEngine engine = MustacheEngineBuilder.newBuilder()
.addTemplateLocator(locator).build();
Mustache sub = engine.getMustache("subsub");
assertEquals("And now for something completely different.",
sub.render(null));
}
开发者ID:trimou,项目名称:trimou,代码行数:17,代码来源:ExtendSegmentTest.java
示例7: produceMustacheEngine
import org.trimou.engine.MustacheEngine; //导入依赖的package包/类
@ApplicationScoped
@Produces
public MustacheEngine produceMustacheEngine(
SimpleStatsCollector simpleStatsCollector) {
// 1. CDI and servlet resolvers are registered automatically
// 2. Precompile all available templates
// 3. Do not escape values
// 4. PrettyTimeHelper is registered automatically
// 5. Register extra helpers (set, isOdd, ...)
// 6. ServletContextTemplateLocator is most suitable for webapps
// 7. The current locale will be based on the Accept-Language header
// 8. Minify all the templates
// 9. Collect some basic rendering statistics
return MustacheEngineBuilder.newBuilder()
.setProperty(EngineConfigurationKey.PRECOMPILE_ALL_TEMPLATES,
true)
.setProperty(EngineConfigurationKey.SKIP_VALUE_ESCAPING, true)
.registerHelpers(HelpersBuilder.extra()
.add("format", new DateTimeFormatHelper()).build())
.addTemplateLocator(ServletContextTemplateLocator.builder()
.setRootPath("/WEB-INF/templates").setSuffix("html")
.build())
.setLocaleSupport(new RequestLocaleSupport())
.addMustacheListener(Minify.htmlListener())
.addMustacheListener(simpleStatsCollector).build();
}
开发者ID:trimou,项目名称:trimou,代码行数:27,代码来源:MustacheEngineProducer.java
示例8: testStaticMethod
import org.trimou.engine.MustacheEngine; //导入依赖的package包/类
@Test
public void testStaticMethod() {
final MustacheEngine engine = MustacheEngineBuilder.newBuilder()
.registerHelpers(HelpersBuilder.empty().addInvoke().build())
.build();
List<String> list = new ArrayList<>();
list.add("foo");
list.add("bar");
list.add("baz");
assertEquals("bazbarfoo",
engine.compileMustache("invoke_static_01",
"{{invoke this class='java.util.Collections' m='reverse'}}{{#each this}}{{this}}{{/each}}")
.render(list));
assertEquals("war",
engine.compileMustache("invoke_static_02",
"{{#invoke 'WAR' class='org.trimou.ArchiveType' m='valueOf'}}{{suffix}}{{/invoke}}")
.render(null));
assertEquals("1",
engine.compileMustache("invoke_static_03",
"{{#invoke 'MILLISECONDS' class='java.util.concurrent.TimeUnit' m='valueOf'}}{{invoke 1000l m='toSeconds'}}{{/invoke}}")
.render(null));
assertEquals("war",
engine.compileMustache("invoke_static_04",
"{{#invoke 'WAR' class=this m='valueOf'}}{{suffix}}{{/invoke}}")
.render(ArchiveType.class));
}
开发者ID:trimou,项目名称:trimou,代码行数:27,代码来源:InvokeHelperTest.java
示例9: testInterpolation
import org.trimou.engine.MustacheEngine; //导入依赖的package包/类
@Test
public void testInterpolation() {
MustacheEngine engine = MustacheEngineBuilder.newBuilder()
.omitServiceLoaderConfigurationExtensions()
.setLocaleSupport(FixedLocaleSupport.from(Locale.ENGLISH))
.addResolver(new ThisResolver())
.registerHelper("pretty", new PrettyTimeHelper()).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", "{{pretty this}}").render(now));
assertEquals(expected,
engine.compileMustache("pretty_date", "{{pretty this}}")
.render(now.getTime()));
assertEquals(expected,
engine.compileMustache("pretty_long", "{{pretty this}}")
.render(now.getTimeInMillis()));
}
开发者ID:trimou,项目名称:trimou,代码行数:24,代码来源:PrettyTimeHelperTest.java
示例10: testRecursiveInvocationLimitExceeded
import org.trimou.engine.MustacheEngine; //导入依赖的package包/类
@Test
public void testRecursiveInvocationLimitExceeded() {
MapTemplateLocator locator = new MapTemplateLocator(ImmutableMap.of(
"super", "/n{{<super}}{{/super}}"));
MustacheEngine engine = MustacheEngineBuilder
.newBuilder()
.addTemplateLocator(locator)
.setProperty(
EngineConfigurationKey.TEMPLATE_RECURSIVE_INVOCATION_LIMIT,
5).build();
try {
engine.getMustache("super").render(null);
fail("Limit exceeded and no exception thrown");
} catch (MustacheException e) {
if (!e.getCode()
.equals(MustacheProblem.RENDER_TEMPLATE_INVOCATION_RECURSIVE_LIMIT_EXCEEDED)) {
fail("Invalid problem");
}
System.out.println(e.getMessage());
// else {
// e.printStackTrace();
// }
}
}
开发者ID:trimou,项目名称:trimou,代码行数:27,代码来源:ExtendSegmentTest.java
示例11: testSwitchHelperValidation
import org.trimou.engine.MustacheEngine; //导入依赖的package包/类
@Test
public void testSwitchHelperValidation() {
final MustacheEngine engine = MustacheEngineBuilder.newBuilder()
.registerHelpers(HelpersBuilder.empty().addSwitch().build())
.build();
MustacheExceptionAssert
.expect(MustacheProblem.COMPILE_HELPER_VALIDATION_FAILURE)
.check(() -> engine.compileMustache(
"switch_helper_validation01", "{{switch}}"))
.check(() -> engine.compileMustache(
"switch_helper_validation02",
"{{#switch}}{{case \"true\"}}{{/switch}}"))
.check(() -> engine.compileMustache(
"switch_helper_validation03",
"{{#switch}}{{#case \"true\"}}{{/case}}{{default \"foo\"}}{{/switch}}"));
}
开发者ID:trimou,项目名称:trimou,代码行数:20,代码来源:SwitchHelperTest.java
示例12: testCustomListener
import org.trimou.engine.MustacheEngine; //导入依赖的package包/类
@Test
public void testCustomListener() {
MustacheEngine engine = MustacheEngineBuilder
.newBuilder()
.addMustacheListener(
Minify.customListener(new AbstractMinifier() {
@Override
public Reader minify(String mustacheName,
Reader mustacheContents) {
return mustacheName.endsWith("js") ? new StringReader(
"") : mustacheContents;
}
})).build();
assertEquals("", engine.compileMustache("mustache.js", "whatever")
.render(null));
assertEquals("<html>",
engine.compileMustache("foo", "<html>").render(null));
}
开发者ID:trimou,项目名称:trimou,代码行数:23,代码来源:MinifyListenerTest.java
示例13: testPartial
import org.trimou.engine.MustacheEngine; //导入依赖的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"));
}
开发者ID:trimou,项目名称:trimou,代码行数:22,代码来源:OptionsTest.java
示例14: testGetAppendable
import org.trimou.engine.MustacheEngine; //导入依赖的package包/类
@Test
public void testGetAppendable() {
MustacheEngine engine = MustacheEngineBuilder.newBuilder()
.registerHelper("test", new AbstractHelper() {
@Override
public void execute(Options options) {
try {
options.getAppendable()
.append(options.peek().toString());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}).build();
assertEquals("HELLO",
engine.compileMustache("helper_getappendable", "{{test}}")
.render("HELLO"));
}
开发者ID:trimou,项目名称:trimou,代码行数:19,代码来源:OptionsTest.java
示例15: testFnAppendable
import org.trimou.engine.MustacheEngine; //导入依赖的package包/类
@Test
public void testFnAppendable() {
final StringBuilder builder = new StringBuilder();
MustacheEngine engine = MustacheEngineBuilder.newBuilder()
.registerHelper("test", new AbstractHelper() {
@Override
public void execute(Options options) {
options.fn(builder);
}
}).build();
String literal = "This is /n a foo";
assertEquals(
"", engine
.compileMustache("helper_fnappendable",
"{{#test}}" + literal + "{{/test}}")
.render(null));
assertEquals(literal, builder.toString());
}
开发者ID:trimou,项目名称:trimou,代码行数:19,代码来源:OptionsTest.java
示例16: startTemplate
import org.trimou.engine.MustacheEngine; //导入依赖的package包/类
@Override
public void startTemplate(String name, Delimiters delimiters,
MustacheEngine engine) {
this.delimiters = delimiters;
this.engine = engine;
this.templateName = name;
containerStack.addFirst(new RootSegmentBase());
skipValueEscaping = engine.getConfiguration().getBooleanPropertyValue(
EngineConfigurationKey.SKIP_VALUE_ESCAPING);
handlebarsSupportEnabled = engine.getConfiguration()
.getBooleanPropertyValue(
EngineConfigurationKey.HANDLEBARS_SUPPORT_ENABLED);
start = System.currentTimeMillis();
LOGGER.debug("Start compilation of {}", new Object[] { name });
}
开发者ID:trimou,项目名称:trimou,代码行数:20,代码来源:DefaultParsingHandler.java
示例17: DefaultParser
import org.trimou.engine.MustacheEngine; //导入依赖的package包/类
/**
*
* @param engine
*/
public DefaultParser(MustacheEngine engine) {
this.state = State.TEXT;
this.line = 1;
this.delimiterIdx = 0;
this.triple = false;
this.buffer = new StringBuilder();
this.separatorIdx = 0;
this.engine = engine;
this.delimiters = new Delimiters(engine.getConfiguration()
.getStringPropertyValue(START_DELIMITER), engine
.getConfiguration().getStringPropertyValue(END_DELIMITER));
this.supportedSeparators = ImmutableSet.of(Strings.LINE_SEPARATOR_LF,
Strings.LINE_SEPARATOR_CR, Strings.LINE_SEPARATOR_CRLF);
this.zeroIndexNonSeparatorCharacters = new HashSet<>();
}
开发者ID:trimou,项目名称:trimou,代码行数:20,代码来源:DefaultParser.java
示例18: testReleaseCallbackFails
import org.trimou.engine.MustacheEngine; //导入依赖的package包/类
@Test
public void testReleaseCallbackFails() {
final AtomicBoolean callbackInvoked = new AtomicBoolean(false);
MustacheEngine engine = MustacheEngineBuilder
.newBuilder()
.addResolver(
new AbstractResolver(
Resolver.DEFAULT_PRIORITY + 100) {
@Override
public Object resolve(Object contextObject,
String name, ResolutionContext context) {
context.registerReleaseCallback(() -> { throw new NullPointerException(); });
context.registerReleaseCallback(() -> callbackInvoked.set(true));
return null;
}
}).build();
assertEquals(
"",
engine.compileMustache("release_callback_fails",
"{{cannotmatch}}").render(null));
assertTrue(callbackInvoked.get());
}
开发者ID:trimou,项目名称:trimou,代码行数:27,代码来源:ValueWrapperTest.java
示例19: Template
import org.trimou.engine.MustacheEngine; //导入依赖的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();
}
}
开发者ID:trimou,项目名称:trimou,代码行数:26,代码来源:Template.java
示例20: testHelperConfiguration
import org.trimou.engine.MustacheEngine; //导入依赖的package包/类
@Test
public void testHelperConfiguration() throws InterruptedException {
final MustacheEngine engine = MustacheEngineBuilder.newBuilder()
.setProperty(CacheHelper.FRAGMENT_CACHE_MAX_SIZE_KEY, 0)
.registerHelpers(HelpersBuilder.empty().addCache().build())
.build();
Hammer hammer1 = new Hammer(1);
Hammer hammer2 = new Hammer(2);
Hammer hammer3 = new Hammer(3);
Mustache mustache = engine.compileMustache("cache_config_01",
"{{#cache key=this.id}}{{this.age}}{{/cache}}");
assertEquals("1", mustache.render(hammer1));
assertEquals("2", mustache.render(hammer2));
assertEquals("3", mustache.render(hammer3));
hammer1.setAge(11);
hammer2.setAge(22);
hammer3.setAge(33);
assertEquals("11", mustache.render(hammer1));
assertEquals("22", mustache.render(hammer2));
assertEquals("33", mustache.render(hammer3));
}
开发者ID:trimou,项目名称:trimou,代码行数:22,代码来源:CacheHelperTest.java
注:本文中的org.trimou.engine.MustacheEngine类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论