Giter VIP home page Giter VIP logo

mustache.tcl's Introduction

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 [email protected]

(C)2015 by Jan Kandziora [email protected]

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

mustache.tcl's People

Contributors

ianka avatar d-led avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.