aboutsummaryrefslogtreecommitdiff
path: root/README.md
blob: 454520febb7c00c28b12b2f24bcc25f7b73d4ef8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# JSON Template for Common Lisp

## Summary

An implementation of [JSON Template][] in Common Lisp.

## Implementation Features

 * No dependencies
 * Portable Common Lisp (tested
   on [SBCL][], [Clozure CL][], [ECL][], [XCL][], [ABCL][])
 * HTML and URI escaping through the use of formatters
 * Apache license

## Missing Things

 * Literals (like `{.space}` and `{.meta-left}`/`{.meta-right}`)
 * Multiple-argument formatters
 * Options (like changing the meta character or the default formatter)
 * Some kind of compilation for efficiency

## Examples

```lisp
JSON-TEMPLATE> (defparameter *tmpl* (parse-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}"))
*TMPL*
```

```lisp
JSON-TEMPLATE> (expand-template *tmpl*
                                '(: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>
"
```

```lisp
JSON-TEMPLATE> (expand-template *tmpl*
                                '(:title "<Registered People>"
                                  :people ()))
"
<h1>&#60;Registered People&#62;</h1>
<p>No one's registered.</p>
"
```


[JSON Template]: http://jsont.squarespace.com
[SBCL]:          http://www.sbcl.org/
[Clozure CL]:    http://ccl.clozure.com/
[ECL]:           http://ecls.sf.net/
[XCL]:           https://github.com/gnooth/xcl
[ABCL]:          http://common-lisp.net/project/armedbear/