当前位置: 首页>>代码示例>>Java>>正文


Java MustacheEngineBuilder类代码示例

本文整理汇总了Java中org.trimou.engine.MustacheEngineBuilder的典型用法代码示例。如果您正苦于以下问题:Java MustacheEngineBuilder类的具体用法?Java MustacheEngineBuilder怎么用?Java MustacheEngineBuilder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


MustacheEngineBuilder类属于org.trimou.engine包,在下文中一共展示了MustacheEngineBuilder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getEngine

import org.trimou.engine.MustacheEngineBuilder; //导入依赖的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.MustacheEngineBuilder; //导入依赖的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.MustacheEngineBuilder; //导入依赖的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.MustacheEngineBuilder; //导入依赖的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: testLocatorClasspathNoRootPath

import org.trimou.engine.MustacheEngineBuilder; //导入依赖的package包/类
@Test
public void testLocatorClasspathNoRootPath() throws IOException {

    TemplateLocator locator = ClassPathTemplateLocator.builder(1)
            .setSuffix("foo").build();

    // Just to init the locator
    MustacheEngineBuilder.newBuilder().addTemplateLocator(locator).build();

    Set<String> ids = locator.getAllIdentifiers();
    // No templates available
    assertEquals(0, ids.size());

    assertEquals("{{foo}}", read(locator.locate("locator/file/index")));
    assertEquals("bar", read(locator.locate("locator/file/home")));
    assertEquals("foo", read(locator.locate("locator/file/foo")));
    assertEquals("{{foo}}", read(locator.locate("locator/file/sub/bar")));
    assertEquals("{{bar}}", read(locator.locate("locator/file/sub/subsub/qux")));
    assertEquals("root", read(locator.locate("/oof")));
}
 
开发者ID:trimou,项目名称:trimou,代码行数:21,代码来源:ClassPathTemplateLocatorTest.java

示例6: testCustomVirtualPathSeparator

import org.trimou.engine.MustacheEngineBuilder; //导入依赖的package包/类
@Test
public void testCustomVirtualPathSeparator() throws IOException {

    TemplateLocator locator = FileSystemTemplateLocator.builder()
            .setPriority(1).setRootPath("src/test/resources/locator/file")
            .setSuffix("foo").build();

    // Just to init the locator
    MustacheEngineBuilder.newBuilder().addTemplateLocator(locator)
            .setProperty(PathTemplateLocator.VIRTUAL_PATH_SEPARATOR_KEY,
                    "*")
            .build();

    Set<String> names = locator.getAllIdentifiers();
    assertEquals(5, names.size());
    assertTrue(names.contains("index"));
    assertTrue(names.contains("home"));
    assertTrue(names.contains("foo"));
    assertTrue(names.contains("sub*bar"));
    assertTrue(names.contains("sub*subsub*qux"));

    assertEquals("{{foo}}", read(locator.locate("index")));
    assertEquals("bar", read(locator.locate("home")));
    assertEquals("{{foo}}", read(locator.locate("sub*bar")));
    assertEquals("{{bar}}", read(locator.locate("sub*subsub*qux")));
}
 
开发者ID:trimou,项目名称:trimou,代码行数:27,代码来源:FileSystemTemplateLocatorTest.java

示例7: produceMustacheEngine

import org.trimou.engine.MustacheEngineBuilder; //导入依赖的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: testFluentVersions

import org.trimou.engine.MustacheEngineBuilder; //导入依赖的package包/类
@Test
public void testFluentVersions() {
    MustacheEngine engine = MustacheEngineBuilder.newBuilder().registerHelper("foo", (o) -> {
        o.pushAnd("foo").fnAnd().partialAnd("baz").appendAnd(" and").pop();
    }).registerHelper("bar", (o) -> {
        o.pushAnd("bar")
            .fnAnd(o.getAppendable())
            .partialAnd("baz", o.getAppendable())
            .getValueAnd("this", value -> assertEquals("bar", value))
            .sourceAnd("baz", source -> assertEquals("{{this}}", source))
            .peekAnd(object -> assertEquals("bar", object))
            .appendAnd(" and ")
            .getAppendableAnd(appendable -> {
                try {
                    appendable.append("test");
                } catch (IOException e) {
                    e.printStackTrace();
                }
            })
            .popAnd(object -> assertEquals("bar", object));
    }).addTemplateLocator(MapTemplateLocator.builder().put("baz", "{{this}}").build()).build();
    assertEquals("bar and test", engine.compileMustache("{{bar}}").render(null));
}
 
开发者ID:trimou,项目名称:trimou,代码行数:24,代码来源:OptionsTest.java

示例9: testGetAppendable

import org.trimou.engine.MustacheEngineBuilder; //导入依赖的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

示例10: testLambda

import org.trimou.engine.MustacheEngineBuilder; //导入依赖的package包/类
@Test
public void testLambda() {
    Lambda lambda = new InputProcessingLambda() {
        @Override
        public String invoke(String text) {
            assertNull(text);
            return "ok";
        }

        @Override
        public boolean isReturnValueInterpolated() {
            return true;
        }
    };
    assertEquals(
            "ok",
            MustacheEngineBuilder
                    .newBuilder()
                    .build()
                    .compileMustache("value_segment_lambda", "{{lambda}}")
                    .render(ImmutableMap.<String, Object> of("lambda",
                            lambda)));
}
 
开发者ID:trimou,项目名称:trimou,代码行数:24,代码来源:ValueSegmentTest.java

示例11: cacheDisabled

import org.trimou.engine.MustacheEngineBuilder; //导入依赖的package包/类
@Test
public void cacheDisabled() throws Exception {
    resolver.setEngine(MustacheEngineBuilder.newBuilder()
            .setProperty(EngineConfigurationKey.TEMPLATE_CACHE_ENABLED, false)
            .setProperty(EngineConfigurationKey.DEBUG_MODE, false)
            .build());
    assertThat(resolver.isCache(), is(false));
    resolver.setEngine(MustacheEngineBuilder.newBuilder()
            .setProperty(EngineConfigurationKey.TEMPLATE_CACHE_ENABLED, true)
            .setProperty(EngineConfigurationKey.DEBUG_MODE, true)
            .build());
    assertThat(resolver.isCache(), is(false));
    resolver.setEngine(MustacheEngineBuilder.newBuilder()
            .setProperty(EngineConfigurationKey.TEMPLATE_CACHE_ENABLED, false)
            .setProperty(EngineConfigurationKey.DEBUG_MODE, true)
            .build());
    assertThat(resolver.isCache(), is(false));
    resolver.setEngine(MustacheEngineBuilder.newBuilder()
            .setProperty(EngineConfigurationKey.TEMPLATE_CACHE_ENABLED, true)
            .setProperty(EngineConfigurationKey.DEBUG_MODE, false)
            .build());
    assertThat(resolver.isCache(), is(true));
    resolver.setCacheLimit(0);
    assertThat(resolver.isCache(), is(false));
}
 
开发者ID:trimou,项目名称:trimou,代码行数:26,代码来源:TrimouViewResolverTest.java

示例12: testPartial

import org.trimou.engine.MustacheEngineBuilder; //导入依赖的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

示例13: testInterpolation

import org.trimou.engine.MustacheEngineBuilder; //导入依赖的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

示例14: testLocale

import org.trimou.engine.MustacheEngineBuilder; //导入依赖的package包/类
@Test
public void testLocale() {

    MustacheEngine engine = MustacheEngineBuilder.newBuilder()
            .omitServiceLoaderConfigurationExtensions()
            .setLocaleSupport(FixedLocaleSupport.from(Locale.ENGLISH))
            .addResolver(new ThisResolver())
            .registerHelper("pretty", new PrettyTimeHelper()).build();

    // JustNow (the first time unit in the default list) has max quantity 1 min
    Calendar now = Calendar.getInstance();
    now.add(Calendar.SECOND, -30);

    assertEquals(new Resources_cs().getString("JustNowPastPrefix"),
            engine.compileMustache("pretty_helper_locale",
                    "{{{pretty this locale='cs'}}}").render(now));
}
 
开发者ID:trimou,项目名称:trimou,代码行数:18,代码来源:PrettyTimeHelperTest.java

示例15: testCustomConverter

import org.trimou.engine.MustacheEngineBuilder; //导入依赖的package包/类
@Test
public void testCustomConverter() {

    final Calendar day = Calendar.getInstance();
    day.set(Calendar.YEAR, day.get(Calendar.YEAR) - 1);
    day.set(Calendar.MONTH, day.get(Calendar.MONTH) - 1);

    MustacheEngine engine = MustacheEngineBuilder.newBuilder()
            .omitServiceLoaderConfigurationExtensions()
            .setLocaleSupport(FixedLocaleSupport.from(Locale.ENGLISH))
            .addResolver(new ThisResolver())
            .registerHelper("pretty",
                    PrettyTimeHelper.builder()
                            .setConverter(from -> day.getTime()).build())
            .build();
    assertEquals("1 year ago",
            engine.compileMustache("pretty_conv", "{{pretty this}}")
                    .render(Calendar.getInstance()));
}
 
开发者ID:trimou,项目名称:trimou,代码行数:20,代码来源:PrettyTimeHelperTest.java


注:本文中的org.trimou.engine.MustacheEngineBuilder类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。