Jordan Brown c70a839707 Improve error messages during parse | %!s(int64=8) %!d(string=hai) anos | |
---|---|---|
.gitignore | %!s(int64=8) %!d(string=hai) anos | |
LICENSE | %!s(int64=8) %!d(string=hai) anos | |
README.md | %!s(int64=8) %!d(string=hai) anos | |
stubble.ts | %!s(int64=8) %!d(string=hai) anos |
Stubble is a templating language for the browser, based loosely on Mustache's syntax.
../
, but this may be added later{{#each foo}}{{/each}}
instead of {{#foo}}{{/foo}}
{{{foo}}}
, for raw HTMLStubble recognizes the following types of data:
Node
and its descendantsJQuery
objectsArray-like objects (that is, objects with a length
property) can be iterated
over using a built-in helper, each
.
Instances of Node
and JQuery
are inserted into the rendered result directly. This means
that you can attach event-handlers, JQuery data, etc., and still make use of
it after wrapping the object in a template. This is the primary motivation for Stubble.
All other data types are stringified via their .toString()
method, and then
inserted into the rendered result as a text node. This means that all data is HTML-encoded
automatically.
There are three helpers built into Stubble. These helpers cover the basic logic
needed to render templates. Each helper accepts an optional {{else}}
block which
behaves differently according to its purpose.
The each
helper iterates over each item in the value passed to it, rendering
the block contents with the context set to the current item. If the value passed
is not an array-like object, or its length
property is 0
, then the else
block is rendered instead.
The if
helper tests the value passed to it. If it is truthy, the block is rendered
as usual. Otherwise, the {{else}}
block is rendered.
The with
helper is much like the if
helper, except that it temporarily changes the
context of the template to the value it receives.