1 Installation
2 Usage
2.1 API
2.2 Examples
Version: 5.1.2

JSON Template for Racket (and Typed Racket)

Matthias A. Benkard

License: GPL v3   Web: matthias.benkard.de

1 Installation

JSON Template for Racket is published as a PLaneT module. Simply (require (planet mbenkard/json-template)) to get started.

2 Usage

2.1 API

(make-template template-data)  procedure?
  template-data : string?
Create a template from template-data, which must be in JSON Template syntax.

The returned procedure expects a single argument, the substitution context, and returns the expanded template as a string. Three types of contexts are supported:

make-template’s behavior can be customized by the parameters formatters, meta-left, meta-right, default-formatter, and format-char.

For general information about JSON Template, see the official introduction and the language reference.

2.2 Examples

> (define template (make-template "\n<h1>{title|html}</h1>\n{.section people}\n<ul>\n{.repeated section @}\n  <li>{name} ({age} years)</li>\n{.end}\n</ul>\n{.or}\n<p>No one's registered.</p>\n{.end}\n"))
> (template '((title . "<Registered People>")
              (people
                       ((name . "Nathalie") (age . 24))
                       ((name . "Heinrich") (age . 28))
                       ((name . "Hans")     (age . 25)))))

<h1>&#60;Registered People&#62;</h1>

<ul>

  <li>Nathalie (24 years)</li>

  <li>Heinrich (28 years)</li>

  <li>Hans (25 years)</li>

</ul>

> (template '((title . "<Registered People>")
              (people)))

<h1>&#60;Registered People&#62;</h1>

<ul>

</ul>

> (template '((title . "<Registered People>")))

<h1>&#60;Registered People&#62;</h1>

<p>No one's registered.</p>