本文整理汇总了Java中org.trimou.engine.locator.ClassPathTemplateLocator类的典型用法代码示例。如果您正苦于以下问题:Java ClassPathTemplateLocator类的具体用法?Java ClassPathTemplateLocator怎么用?Java ClassPathTemplateLocator使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ClassPathTemplateLocator类属于org.trimou.engine.locator包,在下文中一共展示了ClassPathTemplateLocator类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: getEngine
import org.trimou.engine.locator.ClassPathTemplateLocator; //导入依赖的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.locator.ClassPathTemplateLocator; //导入依赖的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: init
import org.trimou.engine.locator.ClassPathTemplateLocator; //导入依赖的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");
}
开发者ID:spotify,项目名称:flo,代码行数:21,代码来源:ApiGeneratorProcessor.java
示例4: setup
import org.trimou.engine.locator.ClassPathTemplateLocator; //导入依赖的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
示例5: testLocator
import org.trimou.engine.locator.ClassPathTemplateLocator; //导入依赖的package包/类
@Test
public void testLocator() {
TemplateLocator locator1 = ClassPathTemplateLocator.builder(10)
.setRootPath("templates").setSuffix("html").build();
TemplateLocator locator2 = ClassPathTemplateLocator.builder(9)
.setScanClasspath(false).build();
TemplateLocator locator3 = ClassPathTemplateLocator.builder(8)
.setSuffix("html").setRootPath("META-INF/templates")
.setScanClasspath(false).build();
// Just to init the locators
MustacheEngine engine = MustacheEngineBuilder.newBuilder()
.addTemplateLocator(locator1).addTemplateLocator(locator2)
.addTemplateLocator(locator3).build();
Set<String> locator1Ids = locator1.getAllIdentifiers();
assertEquals(0, locator1Ids.size());
Mustache foo = engine.getMustache("foo");
assertNotNull(foo);
assertEquals("<html/>", foo.render(null));
Set<String> locator2Ids = locator2.getAllIdentifiers();
assertEquals(0, locator2Ids.size());
foo = engine.getMustache("templates/foo.html");
assertNotNull(foo);
assertEquals("<html/>", foo.render(null));
Set<String> locator3Ids = locator3.getAllIdentifiers();
assertEquals(0, locator3Ids.size());
Mustache bar = engine.getMustache("bar");
assertNotNull(bar);
assertEquals("<xml/>", bar.render(null));
}
开发者ID:trimou,项目名称:trimou,代码行数:35,代码来源:ClassPathTemplateLocatorIntegrationTest.java
示例6: build
import org.trimou.engine.locator.ClassPathTemplateLocator; //导入依赖的package包/类
public TrimouViewRenderer build(MustacheEngineBuilder builder) {
// Locator for views
builder.addTemplateLocator(ClassPathTemplateLocator.builder(10).setClassLoader(this.getClass().getClassLoader()).build());
// Locator for partials and template inheritance
builder.addTemplateLocator(ClassPathTemplateLocator.builder(9).setClassLoader(this.getClass().getClassLoader()).setSuffix(suffix).build());
return build(builder.build());
}
开发者ID:trimou,项目名称:trimou,代码行数:8,代码来源:TrimouViewRenderer.java
示例7: init
import org.trimou.engine.locator.ClassPathTemplateLocator; //导入依赖的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
示例8: main
import org.trimou.engine.locator.ClassPathTemplateLocator; //导入依赖的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.engine.locator.ClassPathTemplateLocator类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论