• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java MustacheEngineBuilder类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: testHash

import org.trimou.engine.MustacheEngineBuilder; //导入依赖的package包/类
@Test
public void testHash() {
    MustacheEngine engine = MustacheEngineBuilder.newBuilder()
            .registerHelper("test", new AbstractHelper() {
                @Override
                public void execute(Options options) {
                    final Map<String, Object> hash = options.getHash();
                    assertEquals(3, hash.size());
                    assertEquals("1", hash.get("first"));
                    assertEquals(10, hash.get("second"));
                    assertNull(hash.get("third"));
                    ExceptionAssert
                            .expect(UnsupportedOperationException.class)
                            .check(() -> hash.remove("first"));
                }
            }).build();
    engine.compileMustache("helper_params",
            "{{test first=\"1\" second=this.age third=nonexisting}}")
            .render(new Hammer());
}
 
开发者ID:trimou,项目名称:trimou,代码行数:21,代码来源:OptionsTest.java


示例17: testCustomMatchName

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

    PrettyTimeResolver resolver = new PrettyTimeResolver();

    // Just to init the resolver
    MustacheEngineBuilder.newBuilder()
            .omitServiceLoaderConfigurationExtensions()
            .setProperty(PrettyTimeResolver.ENABLED_KEY, true)
            .setLocaleSupport(FixedLocaleSupport.from(Locale.ENGLISH))
            .addResolver(resolver)
            .setProperty(PrettyTimeResolver.MATCH_NAME_KEY, "pretty")
            .build();

    assertNull(resolver.resolve(null, "pretty", null));
    assertNull(resolver.resolve("foo", "pretty", null));
    assertNotNull(resolver.resolve(new Date(), "pretty", null));
}
 
开发者ID:trimou,项目名称:trimou,代码行数:19,代码来源:PrettyTimeResolverTest.java


示例18: testValidation

import org.trimou.engine.MustacheEngineBuilder; //导入依赖的package包/类
@Test
public void testValidation() {
    MustacheExceptionAssert
            .expect(MustacheProblem.COMPILE_HELPER_VALIDATION_FAILURE)
            .check(() -> MustacheEngineBuilder.newBuilder()
                    .registerHelpers(
                            HelpersBuilder.empty().addCache().build())
                    .build()
                    .compileMustache("cache_validation_01", "{{cache}}"))
            .check(() -> MustacheEngineBuilder.newBuilder()
                    .registerHelpers(
                            HelpersBuilder.empty().addCache().build())
                    .build().compileMustache("cache_validation_02",
                            "{{#cache expire='foo'}}{{/cache}}"))
            .check(() -> MustacheEngineBuilder.newBuilder()
                    .registerHelpers(
                            HelpersBuilder.empty().addCache().build())
                    .build().compileMustache("cache_validation_03",
                            "{{#cache expire=1 unit='foo'}}{{/cache}}"));
}
 
开发者ID:trimou,项目名称:trimou,代码行数:21,代码来源:CacheHelperTest.java


示例19: testRenderingErrors

import org.trimou.engine.MustacheEngineBuilder; //导入依赖的package包/类
@Test
public void testRenderingErrors() {
    final MustacheEngine engine = MustacheEngineBuilder.newBuilder()
            .registerHelpers(HelpersBuilder.empty().addInvoke().build())
            .build();
    MustacheExceptionAssert
            .expect(MustacheProblem.RENDER_HELPER_INVALID_OPTIONS)
            .check(() -> engine.compileMustache("invoke_method_not_found",
                    "{{invoke m='foo'}}").render("bar"));
    MustacheExceptionAssert
            .expect(MustacheProblem.RENDER_HELPER_INVALID_OPTIONS)
            .check(() -> engine
                    .compileMustache("invoke_method_ambiguous",
                            "{{invoke 'name' 5L class='java.lang.Long' m='getLong'}}")
                    .render("bar"));
}
 
开发者ID:trimou,项目名称:trimou,代码行数:17,代码来源:InvokeHelperTest.java


示例20: testMustacheTagPattern

import org.trimou.engine.MustacheEngineBuilder; //导入依赖的package包/类
@Test
public void testMustacheTagPattern() {
    String text = "{{foo }} and {{#bar}}...{{/bar}}";
    Pattern tagPattern = Patterns
            .newMustacheTagPattern(MustacheEngineBuilder.newBuilder()
                    .build().getConfiguration());
    Matcher matcher = tagPattern.matcher(text);
    StringBuffer result = new StringBuffer();
    int occurences = 0;
    while (matcher.find()) {
        System.out.println(matcher.group(0));
        matcher.appendReplacement(result, "FOUND");
        occurences++;
    }
    matcher.appendTail(result);
    assertEquals(3, occurences);
    assertEquals("FOUND and FOUND...FOUND", result.toString());
}
 
开发者ID:trimou,项目名称:trimou,代码行数:19,代码来源:PatternsTest.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java AnalysisResult类代码示例发布时间:2022-05-23
下一篇:
Java Cubic类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap