Template

class Template(template: String, replaceables: String) : Stack(source)

A fast, lightweight string templating system with zero dependencies.

You supply a template String and an array of tokens to replace when calling .apply. The order of tokens supplied in the constructor corresponds to the order of strings supplied in apply().

The io.kweb.util.Template will compile your string into an executable stack, which generates output with extreme efficiency; the only string-matching performed is during io.kweb.util.Template compile, and it processes all tokens in a single, efficient iteration of the template String.

This ensures an absolute minimum of processing, and allows large templates with a large number of replacements to scale nicely.

Usage:

assert new Template("$1, $2!", "$1", "$2") .apply("Hello", "World") .equals("Hello, World!");

assert new Template("(<>[])$.toArray(new Object$.size())", "<>", "$") .apply("String", "myList") .equals("(String[])myList.toArray(new ObjectmyList.size())");

Author

"James X. Nelson (james@wetheinter.net)"

Constructors

Link copied to clipboard
constructor(template: String, vararg replaceables: String)

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard
var next: Stack?
Link copied to clipboard

Functions

Link copied to clipboard
open override fun apply(vararg values: String?): String

Applies the current template to the supplied arguments.

Link copied to clipboard
fun push(prefix: String?, pos: Int): Stack

Pushes a string constant and a pointer to a token's replacement position onto stack.