Fork me on GitHub

PebbleEngine.Builder

In package com.mitchellbosecke.pebble

public static class PebbleEngine.Builder extends Object

A builder to configure and construct an instance of a PebbleEngine.

Constructors

public Builder()

Creates the builder.

Parameters:
  • No parameters

Methods

public Builder loader(Loader<?> loader)

Sets the loader used to find templates.

Parameters:
  • Loader<?> loader

    A template loader

public Builder extension(Extension extensions)

Adds an extension, can be safely invoked several times to add different extensions.

Parameters:
  • Extension extensions

    One or more extensions to add

public Builder syntax(Syntax syntax)

Sets the syntax to be used.

Parameters:
  • Syntax syntax

    The syntax to be used

public Builder strictVariables(boolean strictVariables)

Changes the strictVariables setting of the PebbleEngine. The default value of this setting is "false".

The following examples will all print empty strings if strictVariables is false but will throw exceptions if it is true:

{{ nonExistingVariable }} {{ nonExistingVariable.attribute }} {{ nullVariable.attribute }} {{ existingVariable.nullAttribute.attribute }} {{ existingVariable.nonExistingAttribute }} {{ array[-1] }}
Parameters:
  • boolean strictVariables

    Whether or not strict variables is used

public Builder newLineTrimming(boolean enableNewLineTrimming)

Changes the newLineTrimming setting of the PebbleEngine. The default value of this setting is "true".

By default, Pebble will trim a newline that immediately follows a Pebble tag. For example, {}\n{} will have the newline removed.

If newLineTrimming is set to false, then the first newline following a Pebble tag won't be trimmed. All newlines will be preserved

Parameters:
  • boolean enableNewLineTrimming

    Whether or not the newline should be trimmed.

public Builder defaultLocale(Locale defaultLocale)

Sets the Locale passed to all templates constructed by this PebbleEngine.

An individual template can always be given a new locale during evaluation.

Parameters:
  • Locale defaultLocale

    The default locale

public Builder executorService(ExecutorService executorService)

Sets the executor service which is required if using one of Pebble's multithreading features such as the "parallel" tag.

Parameters:
  • ExecutorService executorService

    The executor service

public Builder templateCache(PebbleCache<Object, PebbleTemplate> templateCache)

Sets the cache used by the engine to store compiled PebbleTemplate instances.

Parameters:
public Builder tagCache(PebbleCache<CacheKey, Object> tagCache)

Sets the cache used by the "cache" tag.

Parameters:
public Builder autoEscaping(boolean autoEscaping)

Sets whether or not escaping should be performed automatically.

Parameters:
  • boolean autoEscaping

    The auto escaping setting

public Builder defaultEscapingStrategy(String strategy)

Sets the default escaping strategy of the built-in escaper extension.

Parameters:
  • String strategy

    The name of the default escaping strategy

public Builder addEscapingStrategy(String name, EscapingStrategy strategy)

Adds an escaping strategy to the built-in escaper extension.

Parameters:
  • String name

    The name of the escaping strategy

  • EscapingStrategy strategy

    The strategy implementation

public Builder cacheActive(boolean cacheActive)

Enable/disable all caches, i.e. cache used by the engine to store compiled PebbleTemplate instances and tags cache

Parameters:
  • boolean cacheActive

    toggle to enable/disable all caches

public Builder allowGetClass(boolean allowGetClass)

Enable/disable getClass access for attributes

Parameters:
  • boolean allowGetClass

    toggle to enable/disable getClass access

public Builder literalDecimalTreatedAsInteger(boolean literalDecimalTreatedAsInteger)

Enable/disable treat literal decimal as Integer. Default is disabled, treated as Long.

Parameters:
  • boolean literalDecimalTreatedAsInteger

    toggle to enable/disable literal decimal treated as integer

public Builder greedyMatchMethod(boolean greedyMatchMethod)

Enable/disable greedy matching mode for finding java method. Default is disabled. If enabled, when can not find perfect method (method name, parameter length and parameter type are all satisfied), reduce the limit of the parameter type, try to find other method which has compatible parameter types.

For example,

 {{ obj.number(2) }} 
the expression can match all of below methods.
   public Long getNumber(Long v) {...}
   public Integer getNumber(Integer v) {...}
   public Short getNumber(Short v) {...}
   public Byte getNumber(Byte v) {...}
   ...
 
Parameters:
  • boolean greedyMatchMethod

    toggle to enable/disable greedy match method

public PebbleEngine build()

Creates the PebbleEngine instance.

Parameters:
  • No parameters