Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Common Lisp Mustache Template Renderer

NotificationsYou must be signed in to change notification settings

kanru/cl-mustache

Repository files navigation

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

Inspired byctemplate andet,Mustache is aframework-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 atmustache(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> (prove:run :cl-mustache-test)

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))

About

Common Lisp Mustache Template Renderer

Resources

Stars

Watchers

Forks

Packages

No packages published

Contributors6

Languages


[8]ページ先頭

©2009-2025 Movatter.jp