You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
Jonathan Tremesaygues 8036015378 fix include 1 month ago
tests bugfix: Truth values should not throw an error in a list context. 3 years ago
.travis.yml added a travis config 3 years ago
COPYING changed license from GPLv2 to BSD-2-Clause 5 years ago
Makefile fixed Makefile to install README.md instead of README 3 years ago
README.md changed travis-ci build and status buttons so they link to the main repo. 3 years ago
examples.tcl use a safe interpreter in the examples 5 years ago
makedocs.tcl previous commit was a de-facto update to v1.1.3 of the spec 5 years ago
mustache.tcl fix include 1 month ago
pkgIndex.tcl previous commit was a de-facto update to v1.1.3 of the spec 5 years ago
tests.tcl allow for local testing out of the box 3 years ago

README.md

OVERVIEW

mustache.tcl is a Tcl-only implementation of the mustache templating language.

This package supports the v1.1.3 mustache spec which can be found at https://github.com/mustache/spec/tree/master/specs, lambdas are supported, too.

See https://github.com/mustache for further information on mustache.

Build Status

INVOCATION

There is only a single command

::mustache::mustache template data ?libraryvar ...?

which takes a template and a context data dict and returns the rendered text.

set text {
    <h1>Dear {{firstname}},{{! This is a comment}}</h1>
    <p>Best wishes to your {{age}} birthday.</p>
    <h2>{{sender}}</h2>
}
set data [dict create firstname "Fred" age "40th" sender "Greg & Tina"]

puts [::mustache::mustache $text $data]

Partials

Partials are supplied from variables in the current scope. If no variable is found, the libraryvars are consulted. These are dict variables where the key is matched against the partial name.

Lambdas

Lamdba use is straightforward. Just make a context value a list with “Λtcl” as first element to declare the next element as an executeable content.

IMPORTANT NOTICE, SECURITY CONCERN

To work around the limitation Tcl doesn't support explicit typing and thus,
lambdas an inherently unsafe with user supplied content (and aside from
the usual Tcl way of sandboxing anything unsafe), there is support for
"unsafe" sections. These are ordinary sections with an "unsafe" marker on
start of their context. Lambdas within those sections are always substituted
from the context *outside* the section. This makes it safe to use programmer
defined lambdas mixed with user content.

The lambda prefix can be changed globally, should this ever be needed, by doing

set ::mustache::LambdaPrefix "Λtcl"

The lambda unsafe marker can be changed globally, should this ever be needed, by doing

set ::mustache::LambdaUnsafe "λtcl"

See examples.tcl.

TESTSUITE

The package passes all the mandatory tests from the testsuite without modifications. You can update the yaml files in the tests directory to check against a newer version of the mustache spec. Call

tests.tcl

to run the testsuite. A single argument denoting the test number to run is also supported

Lambdas

The ~lambdas.yml file from the spec had to be tweaked, as there hadn’t been any Tcl lambdas in there. Second, Tcl doesn’t support explicit typing, so tcllib’s yaml suite doesn’t support the !code modifier. Instead a lambda has to be marked with Λtcl (that’s an uppercase lambda in front of the “tcl”), which acts as a magic string making mustache.tcl detecting a lambda.

The additional test file ~lambdas-unsafe.yml is supported to test the unsafe sections feature unique to mustache.tcl.

BUGS

Partials indentation was buggy <= v1.1.2.2, now it’s fixed, I think. If you found another bug or have more testcases, please contact me.

AUTHOR AND LICENSE

Jan Kandziora jjj@gmx.de

(C)2015 by Jan Kandziora jjj@gmx.de

You may use, copy, distibute, and modify this software under the terms of the BSD-2-Clause license. See file COPYING for details.