Coder Social home page Coder Social logo

tmpl's Introduction

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.

tmpl's People

Contributors

amarcruz avatar cognitom avatar gianlucaguarini avatar manhg 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.