Skip to content

Commit

Permalink
#20 Pebble Template Engine module
Browse files Browse the repository at this point in the history
  • Loading branch information
marcinus authored and tomaszmichalak committed Feb 4, 2020
1 parent 2b815f6 commit c2f82f0
Show file tree
Hide file tree
Showing 30 changed files with 1,280 additions and 106 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ All notable changes to `knotx-template-engine` will be documented in this file.

## Unreleased
List of changes that are finished but not yet released in any final version.

- [PR-21](https://github.com/Knotx/knotx-template-engine/pull/21) - Pebble Template Engine
## 2.1.0
- [PR-18](https://github.com/Knotx/knotx-template-engine/pull/18) - `com.github.jknack` Handlebars updated to `4.1.2`.

Expand Down
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ together with Transition.

## How to use
> Please note that example below uses Handlebars to process the markup. Read more about it below.
> You may read about it in the [Handlebars module docs](https://github.com/Knotx/knotx-template-engine/tree/master/handlebars)
> If you want to use another template engine, please refer to [core module docs](https://github.com/Knotx/knotx-template-engine/tree/master/core).
> You may read about it in the [Handlebars module docs](https://github.com/Knotx/knotx-template-engine/tree/master/handlebars).
> For using a different template engine, refer to [pebble module docs]() or [core module docs](https://github.com/Knotx/knotx-template-engine/tree/master/core).
Define a module that creates `io.knotx.te.core.TemplateEngineKnot` instance.

Expand Down Expand Up @@ -92,9 +92,10 @@ Now you may use it in Fragment's Tasks.
Example configuration is available in the [conf](https://github.com/Knotx/knotx-template-engine/blob/master/conf)
section of this module.

## Handlebars Template Engine Strategy
Currently this repository delivers `handlebars` TE strategy implementation.
You may read more bout it in the [module docs](https://github.com/Knotx/knotx-template-engine/tree/master/handlebars).
## OOTB Template Engine Strategies
Currently this repository delivers `handlebars` and `pebble` TE strategies implementation.
You may read more in the [handlebars](https://github.com/Knotx/knotx-template-engine/tree/master/handlebars) and [pebble](https://github.com/Knotx/knotx-template-engine/tree/master/pebble) module docs.


### How to create a custom Template Engine Strategy
Read more about it in the [API module docs](https://github.com/Knotx/knotx-template-engine/tree/master/api).
200 changes: 100 additions & 100 deletions gradlew.bat
Original file line number Diff line number Diff line change
@@ -1,100 +1,100 @@
@rem
@rem Copyright 2015 the original author or authors.
@rem
@rem Licensed under the Apache License, Version 2.0 (the "License");
@rem you may not use this file except in compliance with the License.
@rem You may obtain a copy of the License at
@rem
@rem https://www.apache.org/licenses/LICENSE-2.0
@rem
@rem Unless required by applicable law or agreed to in writing, software
@rem distributed under the License is distributed on an "AS IS" BASIS,
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@rem See the License for the specific language governing permissions and
@rem limitations under the License.
@rem

@if "%DEBUG%" == "" @echo off
@rem ##########################################################################
@rem
@rem Gradle startup script for Windows
@rem
@rem ##########################################################################

@rem Set local scope for the variables with windows NT shell
if "%OS%"=="Windows_NT" setlocal

set DIRNAME=%~dp0
if "%DIRNAME%" == "" set DIRNAME=.
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%

@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"

@rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome

set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if "%ERRORLEVEL%" == "0" goto init

echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.

goto fail

:findJavaFromJavaHome
set JAVA_HOME=%JAVA_HOME:"=%
set JAVA_EXE=%JAVA_HOME%/bin/java.exe

if exist "%JAVA_EXE%" goto init

echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.

goto fail

:init
@rem Get command-line arguments, handling Windows variants

if not "%OS%" == "Windows_NT" goto win9xME_args

:win9xME_args
@rem Slurp the command line arguments.
set CMD_LINE_ARGS=
set _SKIP=2

:win9xME_args_slurp
if "x%~1" == "x" goto execute

set CMD_LINE_ARGS=%*

:execute
@rem Setup the command line

set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar

@rem Execute Gradle
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%

:end
@rem End local scope for the variables with windows NT shell
if "%ERRORLEVEL%"=="0" goto mainEnd

:fail
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
rem the _cmd.exe /c_ return code!
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
exit /b 1

:mainEnd
if "%OS%"=="Windows_NT" endlocal

:omega
@rem
@rem Copyright 2015 the original author or authors.
@rem
@rem Licensed under the Apache License, Version 2.0 (the "License");
@rem you may not use this file except in compliance with the License.
@rem You may obtain a copy of the License at
@rem
@rem https://www.apache.org/licenses/LICENSE-2.0
@rem
@rem Unless required by applicable law or agreed to in writing, software
@rem distributed under the License is distributed on an "AS IS" BASIS,
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@rem See the License for the specific language governing permissions and
@rem limitations under the License.
@rem

@if "%DEBUG%" == "" @echo off
@rem ##########################################################################
@rem
@rem Gradle startup script for Windows
@rem
@rem ##########################################################################

@rem Set local scope for the variables with windows NT shell
if "%OS%"=="Windows_NT" setlocal

set DIRNAME=%~dp0
if "%DIRNAME%" == "" set DIRNAME=.
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%

@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"

@rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome

set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if "%ERRORLEVEL%" == "0" goto init

echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.

goto fail

:findJavaFromJavaHome
set JAVA_HOME=%JAVA_HOME:"=%
set JAVA_EXE=%JAVA_HOME%/bin/java.exe

if exist "%JAVA_EXE%" goto init

echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.

goto fail

:init
@rem Get command-line arguments, handling Windows variants

if not "%OS%" == "Windows_NT" goto win9xME_args

:win9xME_args
@rem Slurp the command line arguments.
set CMD_LINE_ARGS=
set _SKIP=2

:win9xME_args_slurp
if "x%~1" == "x" goto execute

set CMD_LINE_ARGS=%*

:execute
@rem Setup the command line

set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar

@rem Execute Gradle
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%

:end
@rem End local scope for the variables with windows NT shell
if "%ERRORLEVEL%"=="0" goto mainEnd

:fail
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
rem the _cmd.exe /c_ return code!
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
exit /b 1

:mainEnd
if "%OS%"=="Windows_NT" endlocal

:omega
40 changes: 40 additions & 0 deletions pebble/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Knot.x Template Engine Pebble
This section describes Pebble template engine strategy that is an alternative implementation of the
template engine used in Knot.x examples.


## How does it work
Template Engine Pebble uses
[Pebble Templates](https://pebbletemplates.io/) to compile and evaluate templates.
Please refer to its documentation for any details.
Additionally, Knot.x Template Engine Pebble has built-in Guava in-memory cache for compiled PEB
Templates. Key computation is performed using the `cacheKeyAlgorithm` defined in the configuration
(the default is `MD5` of the Fragment's `body`).

## How to configure
For all configuration fields and their defaults consult [io.knotx.te.pebble.options.PebbleEngineOptions](https://github.com/Knotx/knotx-template-engine/blob/master/pebble/docs/asciidoc/dataobjects.adoc)

### Custom delimiters
By default, the Pebble engine uses `{{` and `}}` symbols as print delimiters, `{%` and `%}` as computation delimiters, `{#` and `#}` as comment delimiters and `#{` and `}` as string interpolation delimiters.
Knot.x Template Engine Pebble allows to change them using configuration

E.g.:
In order to use different symbols as below
```html
<div class="col-md-4">
<h2>Snippet1 - {: message :}</h2>
</div>
```
You can reconfigure an engine as follows in the pebble engine entry section:
```hocon
{
factory = pebble
config = {
cacheSize = 1000
syntax = {
delimiterPrintOpen = "{:"
delimiterPrintClose = ":}"
}
}
}
```
61 changes: 61 additions & 0 deletions pebble/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* Copyright (C) 2019 Knot.x Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import org.nosphere.apache.rat.RatTask

plugins {
id("io.knotx.java-library")
id("io.knotx.unit-test")
id("io.knotx.maven-publish")
id("io.knotx.codegen")
id("io.knotx.jacoco")

id("org.nosphere.apache.rat") version "0.4.0"
}

dependencies {
implementation(platform("io.knotx:knotx-dependencies:${project.version}"))
implementation("io.knotx:knotx-commons:${project.version}")

api(project(":knotx-template-engine-api"))

implementation(group = "io.vertx", name = "vertx-core")
implementation(group = "io.vertx", name = "vertx-service-proxy")
implementation(group = "io.vertx", name = "vertx-rx-java2")
implementation(group = "com.google.guava", name = "guava")
implementation(group = "io.pebbletemplates", name= "pebble", version = "3.1.2")

testImplementation("io.knotx:knotx-junit5:${project.version}")
testImplementation("org.junit.jupiter:junit-jupiter-params")
testImplementation(group = "org.mockito", name = "mockito-core")
testImplementation(group = "org.mockito", name = "mockito-junit-jupiter")
}

tasks {
named<RatTask>("rat") {
excludes.addAll("*.md", "**/build/*", "**/out/*", "**/generated/*", "**/*.adoc", "**/resources/*", "gradle.properties")
}
getByName("build").dependsOn("rat")
}

publishing {
publications {
withType(MavenPublication::class) {
from(components["java"])
artifact(tasks["sourcesJar"])
artifact(tasks["javadocJar"])
}
}
}
Loading

0 comments on commit c2f82f0

Please sign in to comment.