Summary
I recently wrote an implementation of JSON Template in Typed Racket, mainly in order to get a feel for DrRacket's advantages and disadvantages relative to Common Lisp and SLIME.
In contrast to the Common Lisp version, this implementation is not used in any production code, so it is likely to contain a couple of bugs. On the other hand, the implementation is more featureful and probably prettier overall, one reason being Racket's built-in support for regular expressions.
JSON Template is a minimalistic, declarative template language.
Downloading
You can fetch the Mercurial repository using the following command:
hg clone http://matthias.benkard.de/code/json-template-typed-racket/
(Mind the trailing slash. My web server is overly picky there.)
Alternatively, you can require
the PLaneT version directly from Racket:
(require (planet mbenkard/json-template/json-template))
Documentation
See the manual for installation and usage instructions.
Implementation Features
- No dependencies other than Racket's built-in libraries
- HTML and URI escaping through the use of formatters
- Supports arbitrary <dict?> objects as input data
- Configurable meta characters
- GPLv3 license
Missing Things
- Literals (like
{.space}
and{.meta-left}
/
{.meta-right}) - Multiple-argument formatters
- Some kind of compilation for efficiency
Examples
Example code:(define template-string " <h1>{title|html}</h1> {.section people} <ul> {.repeated section @} <li>{name} ({age} years)</li> {.end} </ul> {.or} <p>No one's registered.</p> {.end}") (define template (make-template template-string)) (template '((title . "<Registered People>") (people . (((name . "Nathalie") (age . 24)) ((name . "Heinrich") (age . 28)) ((name . "Hans") (age . 25)))))))
Result:
<h1><Registered People></h1> <ul> <li>Nathalie (24 years)</li> <li>Heinrich (28 years)</li> <li>Hans (25 years)</li> </ul>
Comments
Submit a comment
Note: This website uses a JavaScript-based spam prevention system. Please enable JavaScript in your browser to post comments. Comment format is plain text. Use blank lines to separate paragraphs.