TemplateProcessor

class TemplateProcessor(text: String, values: MutableMap<String, Any?> = mutableMapOf(), conditionals: MutableMap<String, Boolean> = mutableMapOf(), iterables: MutableMap<String, Iterable<Any>> = mutableMapOf())

A builder-like processor for a template engine backed by JTE (Java Template Engine) with .jte templates.

Three main features:

  • Values: replace a placeholder in the template with a value. In JTE templates, values are referenced via ${NAME}.

  • Conditionals: show or hide fragments of the template code. In JTE templates, conditionals are expressed via @if(NAME)...@endif. An inverted (not) conditional is expressed via @if(!NAME)...@endif.

  • Iterables: repeat the content in their fragment as many times as the iterable's size, while replacing the placeholder with the current item during each iteration. In JTE templates, iterables are expressed via @for(item in NAME)${item}@endfor.

Parameters

text

text or code of the .jte template

Constructors

Link copied to clipboard
constructor(text: String, values: MutableMap<String, Any?> = mutableMapOf(), conditionals: MutableMap<String, Boolean> = mutableMapOf(), iterables: MutableMap<String, Iterable<Any>> = mutableMapOf())

Types

Link copied to clipboard
object Companion

Functions

Link copied to clipboard
fun conditional(conditional: String, value: Boolean): <Error class: unknown class>

Adds a conditional variable that shows or removes fragments of the template code.

Link copied to clipboard
fun copy(text: String = this.text): TemplateProcessor

Creates a copy of this template processor with the same injected properties.

Link copied to clipboard
fun iterable(placeholder: String, iterable: Iterable<Any>): <Error class: unknown class>

Adds an iterable to replace a placeholder in the template code.

Link copied to clipboard
fun optionalValue(placeholder: String, value: Any?): <Error class: unknown class>

Adds both a value to replace the placeholder (or null if absent), and registers it so that the template can check for null presence.

Link copied to clipboard
Link copied to clipboard
fun value(placeholder: String, value: Any?): <Error class: unknown class>

Adds a reference to a placeholder in the template code.