3.0.8 • Published 7 years ago

riot-tmpl v3.0.8

Weekly downloads
5,355
License
MIT
Repository
github
Last release
7 years ago

Build Status Code Quality Coverage Status NPM version NPM downloads MIT License

Tmpl

The riot template engine

Installation

Npm

npm install riot-tmpl --save

Bower

From v2.4.2, bower is not supported.

Documentation

How it works?

Three ways:

  • Expressions: tmpl('{ value }', data). Returns the result of evaluated expression as a raw object.

  • Templates: tmpl('Hi { name } { surname }', data). Returns a string with evaluated expressions.

  • Filters: tmpl('{ show: !done, highlight: active }', data). Returns a space separated list of trueish keys (mainly used for setting html classes), e.g. "show highlight".

Template examples

tmpl('{ title || "Untitled" }', data)
tmpl('Results are { results ? "ready" : "loading" }', data)
tmpl('Today is { new Date() }', data)
tmpl('{ message.length > 140 && "Message is too long" }', data)
tmpl('This item got { Math.round(rating) } stars', data)
tmpl('<h1>{ title }</h1>{ body }', data)

Falsy expressions

In templates (as opposed to single expressions) all falsy values except zero (undefined/null/false) will default to empty string:

tmpl('{ undefined } - { false } - { null } - { 0 }', {})
// will return: " - - - 0"

tmpl('{}')                 // undefined
tmpl('{ false }', {})      // false
tmpl('{ null }', {})       // null
tmpl('{ 0 }', {})          // 0

Changes in v2.3

  • Brackets can not contain characters in the set [\x00-\x1F<>a-zA-Z0-9'",;\\]
  • No comments in expressions, the compiler is the only that strip comments
  • Attributes with expressions containing > must be quoted

See API and CHANGES for details.

3.0.8

7 years ago

3.0.7

7 years ago

3.0.6

7 years ago

3.0.5

7 years ago

3.0.4

7 years ago

3.0.3

7 years ago

3.0.2

7 years ago

3.0.1

7 years ago

3.0.0

7 years ago

3.0.0-rc

7 years ago

2.4.2

8 years ago

2.4.1

8 years ago

2.4.0

8 years ago

2.4.0-beta

8 years ago

2.3.22

8 years ago

2.3.21

8 years ago

2.3.20

8 years ago

2.3.19

8 years ago

2.3.18

8 years ago

2.3.17

8 years ago

2.3.16

8 years ago

2.3.15

8 years ago

2.3.14

8 years ago

2.3.13

8 years ago

2.3.12

8 years ago

2.3.1

8 years ago

2.3.0

8 years ago

2.3.0-beta.8

9 years ago

2.3.0-beta.7

9 years ago

2.3.0-beta.6

9 years ago

2.3.0-beta.5

9 years ago

2.3.0-beta.4

9 years ago

2.3.0-beta.3

9 years ago

2.3.0-beta.2

9 years ago

2.3.0-beta.1

9 years ago

2.0.0-beta.2

9 years ago

2.0.0-beta

9 years ago