Debian Codegraph @

README.rst

raw
1 ========
2 CL-MUSTACHE
3 ========
4
5 .. image:: https://travis-ci.org/kanru/cl-mustache.png?branch=master
6 :target: https://travis-ci.org/kanru/cl-mustache
7
8 Inspired by ctemplate_ and et_, Mustache_ is a
9 framework-agnostic way to render logic-free views.
10
11 As ctemplates says, "It emphasizes separating logic from presentation:
12 it is impossible to embed application logic in this template language."
13
14 CL-MUSTACHE is a Common Lisp implementation of Mustache v1.1.2+λ. Tested with:
15
16 - SBCL 1.0.55
17 - CLISP 2.49
18
19 CL-MUSTACHE is semantically versioned: http://semver.org.
20
21 Documentation
22 =============
23
24 The different Mustache tags are documented at `mustache(5)`_.
25
26 Install It
27 ==========
28
29 Using quicklisp is recommended.
30
31 ::
32
33 CL-USER> (ql:quickload "cl-mustache")
34
35
36 Use It
37 ======
38
39 Currently accepts context data in alist format, for example:
40
41 ::
42
43 `((:tag . "string")
44 (:array . #(1 2 3 4))
45 (:lambda ,(lambda () "world"))
46 (:nested . ((:data . t))))
47
48 To render the template:
49
50 ::
51
52 CL-USER> (mustache:render* "Hi {{person}}!" '((:person . "Mom")))
53 "Hi Mom!"
54
55 Or save the renderer for later use:
56
57 ::
58
59 CL-USER> (setf view (mustache:compile-template "Hi {{person}}!"))
60
61 Or define static renderer function:
62
63 ::
64
65 CL-USER> (mustache:define view "Hi {{person}}!")
66 CL-USER> (view context)
67
68 Test It
69 =======
70
71 ::
72
73 CL-USR> (ql:quickload "cl-mustache-test")
74 CL-USR> (mustache-test:run)
75
76 Extend It (Experimental)
77 ========================
78
79 Define your tag classes, tag character and render function:
80
81 ::
82
83 (in-package :mustache)
84 (defclass exec-tag (non-standalone-tag)
85 ((command :initarg :command :accessor command)))
86 (set-mustache-character
87 #\$
88 (lambda (raw-text arg-text escapep start end)
89 (make-instance 'exec-tag :command arg-text)))
90 ;; or
91 ;; (define-mustache-character #\$
92 ;; (make-instance 'exec-tag :command arg-text))
93 (defmethod render-token ((token exec-tag) context template)
94 (print-data (run-program-output (command token)) t context))
95
96 .. _ctemplate: http://code.google.com/p/google-ctemplate/
97 .. _et: http://www.ivan.fomichev.name/2008/05/erlang-template-engine-prototype.html
98 .. _Mustache: http://mustache.github.com/
99 .. _mustache(5): http://mustache.github.com/mustache.5.html