File: README.rst

package info (click to toggle)
cl-mustache 0.12.1-9-g684f227-1
  • links: PTS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 188 kB
  • sloc: lisp: 1,860; sh: 20; makefile: 2
file content (99 lines) | stat: -rw-r--r-- 2,276 bytes parent folder | download
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
========
CL-MUSTACHE
========

.. image:: https://travis-ci.org/kanru/cl-mustache.png?branch=master
   :target: https://travis-ci.org/kanru/cl-mustache

Inspired by ctemplate_ and et_, Mustache_ is a
framework-agnostic way to render logic-free views.

As ctemplates says, "It emphasizes separating logic from presentation:
it is impossible to embed application logic in this template language."

CL-MUSTACHE is a Common Lisp implementation of Mustache v1.1.2+λ. Tested with:

 - SBCL 1.0.55
 - CLISP 2.49

CL-MUSTACHE is semantically versioned: http://semver.org.

Documentation
=============

The different Mustache tags are documented at `mustache(5)`_.

Install It
==========

Using quicklisp is recommended.

::

    CL-USER> (ql:quickload "cl-mustache")


Use It
======

Currently accepts context data in alist format, for example:

::

   `((:tag . "string")
     (:array . #(1 2 3 4))
     (:lambda ,(lambda () "world"))
     (:nested . ((:data . t))))

To render the template:

::

    CL-USER> (mustache:render* "Hi {{person}}!" '((:person . "Mom")))
    "Hi Mom!"

Or save the renderer for later use:

::

    CL-USER> (setf view (mustache:compile-template "Hi {{person}}!"))

Or define static renderer function:

::

    CL-USER> (mustache:define view "Hi {{person}}!")
    CL-USER> (view context)

Test It
=======

::

    CL-USR> (ql:quickload "cl-mustache-test")
    CL-USR> (mustache-test:run)

Extend It (Experimental)
========================

Define your tag classes, tag character and render function:

::

    (in-package :mustache)
    (defclass exec-tag (non-standalone-tag)
      ((command :initarg :command :accessor command)))
    (set-mustache-character
      #\$
      (lambda (raw-text arg-text escapep start end)
        (make-instance 'exec-tag :command arg-text)))
    ;; or
    ;; (define-mustache-character #\$
    ;;   (make-instance 'exec-tag :command arg-text))
    (defmethod render-token ((token exec-tag) context template)
       (print-data (run-program-output (command token)) t context))

.. _ctemplate: http://code.google.com/p/google-ctemplate/
.. _et: http://www.ivan.fomichev.name/2008/05/erlang-template-engine-prototype.html
.. _Mustache: http://mustache.github.com/
.. _mustache(5): http://mustache.github.com/mustache.5.html