A demostration implementation of cacography template engine.

The template syntax is simple:

{{command text parameter}}
@"@", @"{", @"}"

To use render a template, you pass the input String and a processor function to render function. The processor function has type Processor, i.e. String(String, String). The processor function is like a router, routing {{command text}} to function call command(text).

String output = render(input, processor);

Refer the source code of default_processor and verbatim for how to write processor and command function.

Due to a bug in ceylon.regex, Ceylon 1.3.0 (after commit d109037) is required.


Demostration only.


Demostration only.

The rendering currently requires n+1 passes, where n is the count of occurence of {{...}}. The last 1 pass is escaping @"c".

This can be reduced at least to 2 passes. We should split the string on occurence of {{...}}, process individual parts, then join the string. This is the first pass. The second pass is escaping. Pull-requests are welcome.

Processorshared Processor=> String(String, String)

A processing function takes command and its parameter, returns processed text.

default_processorshared String default_processor(String command, String text)

Default processing function, only process verbatim(). Returns {{command text}} when command is unknown.

rendershared String render(String input, Processor processor)

The entry point.

verbatimshared String verbatim(String text)

Returns parameter text verbatim. Returns quoted {{verbatim}} if there is no parameter (empty)