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


Java PebbleEngine类代码示例

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


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

示例1: testSomeStuff

import com.mitchellbosecke.pebble.PebbleEngine; //导入依赖的package包/类
@Test
public void testSomeStuff() throws PebbleException, IOException {
	ClasspathLoader loader = new ClasspathLoader();
	loader.setPrefix(getClass().getPackage().getName().replace('.', '/'));
	
	PebbleEngine engine = new PebbleEngine.Builder()
		.loader(loader)
		.build();
	
	PebbleTemplate template = engine.getTemplate("sample.html");
	
	StringWriter result = new StringWriter();
	template.evaluate(result, ImmutableMap.of("foo",new Fake(ImmutableMap.of("bar", "bar"))));
	assertEquals("-->bar<--", result.toString());
	
}
 
开发者ID:flapdoodle-oss,项目名称:de.flapdoodle.solid,代码行数:17,代码来源:PebbleThemeTest.java

示例2: testVariableScope

import com.mitchellbosecke.pebble.PebbleEngine; //导入依赖的package包/类
@Test
public void testVariableScope() throws Exception {
  PebbleEngine pebble = new PebbleEngine.Builder().loader(new StringLoader()).strictVariables(false).build();

  StringBuilder source = new StringBuilder("{% set fooList = range(1, 1) %}");
  source.append("{% for item in fooList %}");
  source.append("{% set foo1 = 'fooValue' %}");
  source.append("Foo1 value : {{ foo1 }}");
  source.append("{% endfor %}");
  source.append("Foo1 value : {{ foo1 }}");

  source.append("{% for item in fooList %}");
  source.append("{% set foo2 = 'fooValue2' %}");
  source.append("Foo2 value : {{ foo2 }}");
  source.append("{% endfor %}");
  source.append("Foo2 value : {{ foo2 }}");

  PebbleTemplate template = pebble.getTemplate(source.toString());

  Map<String, Object> context = new HashMap<>();

  Writer writer = new StringWriter();
  template.evaluate(writer, context);
  assertEquals("Foo1 value : fooValueFoo1 value : Foo2 value : fooValue2Foo2 value : ", writer.toString());
}
 
开发者ID:flapdoodle-oss,项目名称:de.flapdoodle.solid,代码行数:26,代码来源:ForNodeTest.java

示例3: testNestedLoop

import com.mitchellbosecke.pebble.PebbleEngine; //导入依赖的package包/类
@Test
public void testNestedLoop() throws Exception {
  PebbleEngine pebble = new PebbleEngine.Builder().loader(new StringLoader()).strictVariables(false).build();

  StringBuilder source = new StringBuilder("{% for i in 0..2 %}");
  source.append("{% for j in 0..2 %}");
  source.append("i={{ i }} j={{ j }} ");
  source.append("{% endfor %}");
  source.append("{% endfor %}");
  source.append("i={{ i }} j={{ j }} ");

  PebbleTemplate template = pebble.getTemplate(source.toString());

  Map<String, Object> context = new HashMap<>();

  Writer writer = new StringWriter();
  template.evaluate(writer, context);
  assertEquals("i=0 j=0 i=0 j=1 i=0 j=2 i=1 j=0 i=1 j=1 i=1 j=2 i=2 j=0 i=2 j=1 i=2 j=2 i= j= ", writer.toString());
}
 
开发者ID:flapdoodle-oss,项目名称:de.flapdoodle.solid,代码行数:20,代码来源:ForNodeTest.java

示例4: testLoopIndex

import com.mitchellbosecke.pebble.PebbleEngine; //导入依赖的package包/类
@Test
public void testLoopIndex() throws Exception {
  PebbleEngine pebble = new PebbleEngine.Builder().loader(new StringLoader()).strictVariables(false).build();

  StringBuilder source = new StringBuilder("{% for i in 0..2 %}");
  source.append("{% for j in 0..2 %}");
  source.append("inner={{ loop.index }} ");
  source.append("{% endfor %}");
  source.append("outer={{ loop.index }} ");
  source.append("{% endfor %}");
  source.append("outside loop={{ loop.index }} ");

  PebbleTemplate template = pebble.getTemplate(source.toString());

  Map<String, Object> context = new HashMap<>();

  Writer writer = new StringWriter();
  template.evaluate(writer, context);
  assertEquals("inner=0 inner=1 inner=2 outer=0 inner=0 inner=1 inner=2 outer=1 inner=0 inner=1 inner=2 outer=2 outside loop= ", writer.toString());
}
 
开发者ID:flapdoodle-oss,项目名称:de.flapdoodle.solid,代码行数:21,代码来源:ForNodeTest.java

示例5: pebbleEngine

import com.mitchellbosecke.pebble.PebbleEngine; //导入依赖的package包/类
@Bean
public PebbleEngine pebbleEngine() {
    PebbleEngine.Builder builder = new PebbleEngine.Builder();
    builder.loader(this.pebbleLoader);
    builder.extension(this.pebbleSpringExtension());
    if (this.extensions != null && !this.extensions.isEmpty()) {
        builder.extension(this.extensions.toArray(new Extension[this.extensions.size()]));
    }
    if (!this.properties.isCache()) {
        builder.cacheActive(false);
    }
    if (this.properties.getDefaultLocale() != null) {
        builder.defaultLocale(this.properties.getDefaultLocale());
    }
    builder.strictVariables(this.properties.isStrictVariables());
    return builder.build();
}
 
开发者ID:PebbleTemplates,项目名称:pebble-spring-boot-starter,代码行数:18,代码来源:PebbleAutoConfiguration.java

示例6: generate

import com.mitchellbosecke.pebble.PebbleEngine; //导入依赖的package包/类
protected void generate(String path, String name, String templatePath, Map model){
    try {
        String pathString = path + "/" + name;
        System.out.println("Creating " + pathString);
        Path filePath = Paths.get(pathString);
        Files.createDirectories(filePath.getParent());
        PebbleExtension extension = new PebbleExtension();
        
        extension.getFilters().put("data_type", new DataTypeFilter());
        extension.getFilters().put("camel_case", new CamelCaseFilter());
        extension.getFilters().put("singular", new SingularFilter());
        extension.getFilters().put("plural", new PluralFilter());
        
        PebbleEngine engine = new PebbleEngine.Builder().extension(extension).build();
        
        PebbleTemplate template = engine.getTemplate(templatePath);
        java.io.Writer writer = new FileWriter(path + "/" + name);
                    
        template.evaluate(writer, model);
        System.out.println(writer.toString());            
        writer.close();
        
    } catch (PebbleException | IOException ex) {
        Logger.getLogger(AbstractWriter.class.getName()).log(Level.SEVERE, null, ex);
    }
}
 
开发者ID:azzuwan,项目名称:Novogen,代码行数:27,代码来源:AbstractWriter.java

示例7: registerLayoutRenderer

import com.mitchellbosecke.pebble.PebbleEngine; //导入依赖的package包/类
@Override
public void registerLayoutRenderer(Directory root, StampoGlobalConfiguration configuration,
    Map<String, Function<LayoutParameters, LayoutProcessorOutput>> extensionProcessor) {

  PebbleEngine engine = build(root, configuration);

  extensionProcessor.put(
      "peb",
      lParam -> {
        try {
          StringWriter sw = new StringWriter();
          engine.getTemplate(lParam.layoutTemplate.get().toString()).evaluate(sw, lParam.model,
              lParam.locale);
          return new LayoutProcessorOutput(sw.toString(), "pebble", lParam.layoutTemplate,
              lParam.locale);
        } catch (PebbleException | IOException e) {
          throw new LayoutException(lParam.layoutTemplate.get(), lParam.targetResource, e);
        }
      });
}
 
开发者ID:digitalfondue,项目名称:stampo,代码行数:21,代码来源:PebbleRenderer.java

示例8: registerResourceRenderer

import com.mitchellbosecke.pebble.PebbleEngine; //导入依赖的package包/类
@Override
public void registerResourceRenderer(
    Directory root,
    StampoGlobalConfiguration configuration,
    Map<String, Function<FileResourceParameters, FileResourceProcessorOutput>> extensionProcessor) {
  PebbleEngine pebble = build(root, configuration);
  extensionProcessor.put("peb", params -> {
    try {
      Writer writer = new StringWriter();
      pebble.getTemplate(params.fileResource.getPath().toString())//
          .evaluate(writer, params.model, params.locale);
      return new FileResourceProcessorOutput(writer.toString(), params.fileResource.getPath(),
          "pebble", params.locale);
    } catch (PebbleException | IOException e) {
      throw new TemplateException(params.fileResource.getPath(), e);
    }
  });
}
 
开发者ID:digitalfondue,项目名称:stampo,代码行数:19,代码来源:PebbleRenderer.java

示例9: createPebbleEngine

import com.mitchellbosecke.pebble.PebbleEngine; //导入依赖的package包/类
/**
 * Creates a PebbleEngine instance.
 *
 * @return a PebbleEngine object that can be used to create PebbleTemplate objects
 */
public PebbleEngine createPebbleEngine() {
    PebbleEngine.Builder builder = new PebbleEngine.Builder();
    builder.strictVariables(strictVariables);

    if (defaultLocale != null) {
        builder.defaultLocale(defaultLocale);
    }

    if (templateLoaders == null) {
        if (templateLoaderPaths != null && templateLoaderPaths.length > 0) {
            List<Loader<?>> templateLoaderList = new ArrayList<>();
            for (String path : templateLoaderPaths) {
                templateLoaderList.add(getTemplateLoaderForPath(path));
            }
            setTemplateLoader(templateLoaderList);
        }
    }

    Loader<?> templateLoader = getAggregateTemplateLoader(templateLoaders);
    builder.loader(templateLoader);

    return builder.build();
}
 
开发者ID:aspectran,项目名称:aspectran,代码行数:29,代码来源:PebbleEngineFactory.java

示例10: pebbleEngine

import com.mitchellbosecke.pebble.PebbleEngine; //导入依赖的package包/类
@Bean
@ConditionalOnMissingBean(PebbleEngine.class)
public PebbleEngine pebbleEngine(final PebbleEngineConfigurer pebbleEngineConfigurer) {
    final PebbleTemplateLoader loader = new PebbleTemplateLoader();
    loader.setResourceLoader(new ServletContextResourceLoader(context.getServletContext()));
    loader.setPrefix(this.properties.getPrefix());
    loader.setSuffix(this.properties.getSuffix());

    final List<Loader<?>> list = new ArrayList<>();
    list.add(loader);
    list.add(new ClasspathLoader());
    list.add(new FileLoader());

    final DelegatingLoader loaderAll = new DelegatingLoader(list);
    pebbleEngineConfigurer.setLoader(loaderAll);
    pebbleEngineConfigurer.setCache(this.properties.isCache());
    pebbleEngineConfigurer.setCacheSize(this.properties.getCacheSize());

    return pebbleEngineConfigurer.getPebbleEngine();
}
 
开发者ID:LionelWoody,项目名称:spring-boot-starter-pebble,代码行数:21,代码来源:PebbleAutoConfiguration.java

示例11: getPebbleEngine

import com.mitchellbosecke.pebble.PebbleEngine; //导入依赖的package包/类
public PebbleEngine getPebbleEngine() {

        final PebbleEngine.Builder builder = new PebbleEngine.Builder()
                .loader(this.loader)
                .extension(extensions.toArray(new Extension[extensions.size()]));

        if (cache) {
            builder.templateCache(CacheBuilder.newBuilder().maximumSize(cacheSize).build())
                    .tagCache(CacheBuilder.newBuilder().maximumSize(cacheSize).build());
        } else {
            builder.templateCache(CacheBuilder.newBuilder().maximumSize(0).build())
                    .tagCache(CacheBuilder.newBuilder().maximumSize(0).build());
        }

        log.debug("PebbleEngine built! 这里不写几个汉字不显眼!!!");
        return builder.build();
    }
 
开发者ID:LionelWoody,项目名称:spring-boot-starter-pebble,代码行数:18,代码来源:PebbleEngineConfigurer.java

示例12: handleLeadingSlash

import com.mitchellbosecke.pebble.PebbleEngine; //导入依赖的package包/类
private void handleLeadingSlash(final HttpServletRequest req, HttpServletResponse res, Site sites) throws PebbleException,
        IOException, ServletException {
    if (req.getMethod().equals("GET")) {
        res.setStatus(HttpServletResponse.SC_MOVED_PERMANENTLY);
        res.setHeader("Location", rewritePageUrl(req));
        return;
    } else if (req.getMethod().equals("POST")) {
        if (CoreConfiguration.getConfiguration().developmentMode()) {
            PebbleEngine engine = new PebbleEngine.Builder().loader(new StringLoader()).extension(new CMSExtensions()).build();
            PebbleTemplate compiledTemplate =
                    engine.getTemplate("<html><head></head><body><h1>POST action with backslash</h1><b>You posting data with a URL with a backslash. Alter the form to post with the same URL without the backslash</body></html>");
            res.setStatus(500);
            res.setContentType("text/html");
            compiledTemplate.evaluate(res.getWriter());
        } else {
            renderer.errorPage(req, res, sites, 500);
        }
    }
}
 
开发者ID:FenixEdu,项目名称:fenixedu-cms,代码行数:20,代码来源:CMSURLHandler.java

示例13: renderString

import com.mitchellbosecke.pebble.PebbleEngine; //导入依赖的package包/类
@Override
public void renderString(String templateContent, Map<String, Object> model, Writer writer) {
    String language = (String) model.get(PippoConstants.REQUEST_PARAMETER_LANG);

    if (StringUtils.isNullOrEmpty(language)) {
        language = getLanguageOrDefault(language);
    }
    Locale locale = (Locale) model.get(PippoConstants.REQUEST_PARAMETER_LOCALE);
    if (locale == null) {
        locale = getLocaleOrDefault(language);
    }

    try {
        PebbleEngine stringEngine = new PebbleEngine.Builder()
            .loader(new StringLoader())
            .strictVariables(engine.isStrictVariables())
            .templateCache(null)
            .build();

        PebbleTemplate template = stringEngine.getTemplate(templateContent);
        template.evaluate(writer, model, locale);
        writer.flush();
    } catch (Exception e) {
        throw new PippoRuntimeException(e);
    }
}
 
开发者ID:decebals,项目名称:pippo,代码行数:27,代码来源:PebbleTemplateEngine.java

示例14: basic

import com.mitchellbosecke.pebble.PebbleEngine; //导入依赖的package包/类
@Test
public void basic() throws Exception {
  Locale locale = Locale.getDefault();
  new MockUnit(Env.class, Config.class, Binder.class, PebbleEngine.class)
      .expect(defLoader)
      .expect(newEngine)
      .expect(env("dev", locale))
      .expect(cacheStatic)
      .expect(cache("pebble.cache", null))
      .expect(cache(0))
      .expect(cache("pebble.tagCache", null))
      .expect(tagCache(0))
      .expect(locale(locale))
      .expect(build)
      .expect(bindEngine)
      .expect(renderer)
      .run(unit -> {
        new Pebble()
            .configure(unit.get(Env.class), unit.get(Config.class), unit.get(Binder.class));
      });
}
 
开发者ID:jooby-project,项目名称:jooby,代码行数:22,代码来源:PebbleTest.java

示例15: prefixAsRoot

import com.mitchellbosecke.pebble.PebbleEngine; //导入依赖的package包/类
@Test
public void prefixAsRoot() throws Exception {
  Locale locale = Locale.getDefault();
  new MockUnit(Env.class, Config.class, Binder.class, PebbleEngine.class)
      .expect(defLoader)
      .expect(newEngine)
      .expect(env("dev", locale))
      .expect(cacheStatic)
      .expect(cache("pebble.cache", null))
      .expect(cache(0))
      .expect(cache("pebble.tagCache", null))
      .expect(tagCache(0))
      .expect(locale(locale))
      .expect(build)
      .expect(bindEngine)
      .expect(renderer)
      .run(unit -> {
        new Pebble("/", ".html")
            .configure(unit.get(Env.class), unit.get(Config.class), unit.get(Binder.class));
      });
}
 
开发者ID:jooby-project,项目名称:jooby,代码行数:22,代码来源:PebbleTest.java


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