A demostration implementation of cacography template engine.
The template syntax is simple:
{{commad}}
{{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.
| Packages | |
| io.github.weakish.cacography | Demostration only. |
| Dependencies | ||
ceylon.regex | 1.3.0 | |
ceylon.test | 1.3.0 | |
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.
| Aliases | |
Processor | shared Processor=> String(String, String)A processing function takes command and its parameter, returns processed text. |
| Functions | |
default_processor | shared String default_processor(String command, String text)Default processing function, only process |
render | shared String render(String input, Processor processor)The entry point. |
verbatim | shared String verbatim(String text)Returns parameter text verbatim.
Returns quoted |