本文整理汇总了Java中org.trimou.handlebars.HelpersBuilder类的典型用法代码示例。如果您正苦于以下问题:Java HelpersBuilder类的具体用法?Java HelpersBuilder怎么用?Java HelpersBuilder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
HelpersBuilder类属于org.trimou.handlebars包,在下文中一共展示了HelpersBuilder类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: getEngine
import org.trimou.handlebars.HelpersBuilder; //导入依赖的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: setup
import org.trimou.handlebars.HelpersBuilder; //导入依赖的package包/类
@Setup
public void setup() {
template = MustacheEngineBuilder.newBuilder()
// Disable HTML escaping
.setProperty(EngineConfigurationKey.SKIP_VALUE_ESCAPING, true)
// Disable useless resolver
.setProperty(CombinedIndexResolver.ENABLED_KEY, false)
.addTemplateLocator(ClassPathTemplateLocator.builder(1).setRootPath("templates").setScanClasspath(false).setSuffix("trimou.html").build())
.registerHelpers(HelpersBuilder.extra().build())
// This is a single purpose helper
// It's a pity we can't use JDK8 extension and SimpleHelpers util class
.registerHelper("minusClass", new BasicValueHelper() {
@Override
public void execute(Options options) {
Object value = options.getParameters().get(0);
if (value instanceof Double && (Double) value < 0) {
options.append(" class=\"minus\"");
}
// We don't handle any other number types
}
}).build().getMustache("stocks");
this.context = getContext();
}
开发者ID:mbosecke,项目名称:template-benchmark,代码行数:24,代码来源:Trimou.java
示例3: produceMustacheEngine
import org.trimou.handlebars.HelpersBuilder; //导入依赖的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
示例4: init
import org.trimou.handlebars.HelpersBuilder; //导入依赖的package包/类
@Override
public void init(Map<String, String> properties, ResourceManager resourceManager) {
this.resourceManager = resourceManager;
engine = MustacheEngineBuilder
.newBuilder()
.registerHelpers(HelpersBuilder.extra().build())
.addTemplateLocator(new ResourceManagerTemplateLocator())
.setProperty(EngineConfigurationKey.DEBUG_MODE, Boolean.parseBoolean(properties.get("debug")))
.setProperty(EngineConfigurationKey.DEFAULT_FILE_ENCODING, properties.containsKey("charset") ? properties.get("charset") : "UTF-8")
.build();
}
开发者ID:undertow-io,项目名称:undertow.js,代码行数:12,代码来源:TrimouTemplateProvider.java
示例5: getMustacheEngine
import org.trimou.handlebars.HelpersBuilder; //导入依赖的package包/类
@Produces
@ViewEngineConfig
public MustacheEngine getMustacheEngine() {
return MustacheEngineBuilder.newBuilder()
.registerHelpers(HelpersBuilder.extra().build())
.addTemplateLocator(ServletContextTemplateLocator.builder()
.setRootPath(getProperty(mvc.getConfig(),
ViewEngine.VIEW_FOLDER,
ViewEngine.DEFAULT_VIEW_FOLDER).toString())
.setServletContext(servletContext).build())
.build();
}
开发者ID:trimou,项目名称:trimou,代码行数:13,代码来源:DefaultTrimouConfiguration.java
示例6: register
import org.trimou.handlebars.HelpersBuilder; //导入依赖的package包/类
@Override
public void register(ConfigurationExtensionBuilder builder) {
registerHelper(builder, ELHelper.DEFAULT_NAME, new ELHelper());
registerHelper(builder, HelpersBuilder.IF, new ELIfHelper());
registerHelper(builder, HelpersBuilder.EACH, new ELEachHelper());
registerHelper(builder, HelpersBuilder.SET, new ELSetHelper());
}
开发者ID:trimou,项目名称:trimou,代码行数:8,代码来源:ELConfigurationExtension.java
示例7: register
import org.trimou.handlebars.HelpersBuilder; //导入依赖的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());
}
开发者ID:trimou,项目名称:trimou,代码行数:11,代码来源:DefaultConfigurationExtension.java
示例8: testDependentNestedTemplatesHelper
import org.trimou.handlebars.HelpersBuilder; //导入依赖的package包/类
@Test
public void testDependentNestedTemplatesHelper() {
engine = MustacheEngineBuilder.newBuilder()
.registerHelpers(HelpersBuilder.empty().addInclude().build())
.build();
assertEquals("Hello world!",
engine.compileMustache("nested_dependent",
"{{+nested1}}world{{/nested1}}{{+nested2}}{{include 'nested1'}}{{/nested2}}Hello {{include 'nested2'}}!")
.render(null));
}
开发者ID:trimou,项目名称:trimou,代码行数:11,代码来源:NestedTemplateTest.java
示例9: init
import org.trimou.handlebars.HelpersBuilder; //导入依赖的package包/类
@Override
public void init(Application application) {
super.init(application);
this.localeSupport = new ThreadLocalLocaleSupport();
Router router = getRouter();
PippoSettings pippoSettings = getPippoSettings();
MustacheEngineBuilder builder = MustacheEngineBuilder.newBuilder();
builder.setLocaleSupport(localeSupport);
builder.setProperty(EngineConfigurationKey.DEFAULT_FILE_ENCODING, PippoConstants.UTF8);
builder.registerHelper("ng", new AngularJsHelper());
builder.registerHelper("i18n", new I18nHelper(application.getMessages()));
builder.registerHelper("formatTime", new DateTimeFormatHelper());
builder.registerHelper("prettyTime", new PrettyTimeHelper());
builder.registerHelper("webjarsAt", new WebjarsAtHelper(router));
builder.registerHelper("publicAt", new PublicAtHelper(router));
builder.registerHelpers(HelpersBuilder.extra().build());
String pathPrefix = getTemplatePathPrefix();
pathPrefix = StringUtils.removeStart(pathPrefix, "/");
builder.addTemplateLocator(new ClassPathTemplateLocator(10, pathPrefix, MUSTACHE));
if (pippoSettings.isDev()) {
// enable debug mode
builder.setProperty(EngineConfigurationKey.DEBUG_MODE, true);
} else {
// automatically minify pages generated in production/test
builder.addMustacheListener(Minify.htmlListener());
}
// set global template variables
builder.addGlobalData("contextPath", router.getContextPath());
builder.addGlobalData("appPath", router.getApplicationPath());
// allow custom initialization
init(application, builder);
engine = builder.build();
}
开发者ID:decebals,项目名称:pippo,代码行数:42,代码来源:TrimouTemplateEngine.java
示例10: main
import org.trimou.handlebars.HelpersBuilder; //导入依赖的package包/类
public static void main(String[] args) {
// We will always start like this - building an engine
MustacheEngineBuilder builder = MustacheEngineBuilder.newBuilder();
// Add a template locator so that the template contents is automatically
// loaded
builder.addTemplateLocator(
ClassPathTemplateLocator.builder().setSuffix("trimou").build());
// Add some extra built-in helpers
builder.registerHelpers(HelpersBuilder.extra()
.add("log",
LogHelper.builder().setDefaultLevel(Level.WARN).build())
.build());
// Global data are available in all templates
builder.addGlobalData("footer", "© 2014 Trimou team");
// HTML is not necessary
builder.setProperty(EngineConfigurationKey.SKIP_VALUE_ESCAPING, true);
// Now we are ready to build the engine...
MustacheEngine engine = builder.build();
// Note that it's not necessary to cache templates - engine has its own
// cache enabled by default
Mustache test = engine.getMustache("items");
// Prepare some data
List<Item> items = new ArrayList<>();
items.add(new Item("Foo", 5l, true));
items.add(new Item("Bar", 15l, true));
items.add(new Item("Qux", -1l, false));
items.add(new Item("Baz", 5000l, true));
System.out.println(
String.format("Start rendering of %s...", test.getName()));
long start = System.nanoTime();
// And now render the data
String output = test.render(items);
long end = System.nanoTime() - start;
System.out.println(String.format("Template %s rendered in %s ms:\n",
test.getName(), end / 1000000));
System.out.println(output);
}
开发者ID:trimou,项目名称:trimou,代码行数:49,代码来源:SimpleExample.java
注:本文中的org.trimou.handlebars.HelpersBuilder类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论