weave
| #lang weave | package: weave |
Weave is a dead-simple text templating system for Racket.
1 Example
#lang weave @@(define (hello to) "Hello, @{to}!") This is a test of weave! @(hello "world") @(hello "weave") @(string-trim (weave "goodbye.rkt" '("world" "weave")))
#lang weave (hellos) @@(define (goodbye to) "Goodbye, @{to}!") @(string-join (for/list ([hello (in-list hellos)]) (goodbye hello)) "\n")
This is a test of weave! |
|
Hello, world! |
Hello, weave! |
Goodbye, world! |
Goodbye, weave! |
2 Syntax
@(form) is equivalent to (format "~a" form). For example, @(+ 1 2) would expand to "3".
@@(form) executes the given code, but does not print any value. Additionally, a single newline after a @@ form is ignored, if one is present.
@{value} displays the value inline. For example, @{name}, if name was defined to be "Wren", would simply expand to "Wren"
\@ expands to a @ verbatim and prevents any Weave forms from being expanded, e.g. \@(+ 1 1) expands to "@(+ 1 1)".
3 Weaving and template files
You can create template files by using #lang weave. These files, when executed, will print out their templated result, or you can use the weave macro to get the templated result as a string.
Parameters will be #f when a template file with arguments is executed as a main module.
syntax
(weave template-path argument ...)
4 Interpolation
| (require weave/interpolate) | package: weave |
Weave also has built-in string interpolation, implemented by replacing #%datum if weave/interpolate is required.