justo.plugin.handlebars

1.0.0-alpha3.0 • Public • Published

justo.plugin.handlebars

NPM version Total downloads

Justo plugin for the Handlebars template system.

Developed in Dogma, compiled to JavaScript.

Proudly made with in Valencia, Spain, EU.

Use

const hbs = require("justo.plugin.handlebars");

hbs.render task

This task renders a Handlebars template:

render({model, tmpl, src, dst}) : string
  • model (object, required). Data object to use.
  • tmpl (string). Template text to render.
  • src (string). Template file to render.
  • dst (string). File to generate if needed.

At least, src or tmpl must be specified.

Example:

hbs.render({
  model: {name: "France 24", website: "france24.com"},
  src: "tv.hbs",
  dst: "france24.json"
});

Available helpers

The following built-in helpers can be used.

{{and}}

This helper performs a logical AND:

{{and exp exp...}}

{{or}}

This helper performs a logical OR:

{{or exp exp...}}

{{http}}

This helper returns a text with a HTTP or HTTPS url:

{{http url}}

{{in}}

This helper checks whether an item is in a collection:

{{in value collection}}
{{in value item1 item2 item3...}}

{{nin}}

This helper checks whether an item is not in a collection:

{{nin value collection}}
{{nin value item1 item2 item3...}}

{{like}}

This helper checks a value is like a pattern:

{{like value pattern}}

{{len}}

This helper returns the length of a collection:

{{len collection}}

{{includes}}

This helper checks whether a collection has an item:

{{includes collection item}}

{{esc}}

This helper escapes a text:

{{esc text}}

{{lowercase}}

This helper returns a text in lowercase:

{{lowercase text}}

{{uppercase}}

This helper returns a text in uppercase:

{{uppercase text}}

{{capitalize}}

This helper returns a text capitalized:

{{capitalize text}}

{{concat}}

This helper returns the concatenation of multiple texts:

{{concat text1 text2...}}

{{replace}}

This helper returns a text with a subtext replaced:

{{replace text old}}
{{replace text old new}}

When no new specified, the old text is removed; similar to {{replace text old ""}}.

{{true}}

This helper checks whether a value is true, "true" or "yes":

{{true value}}

{{false}}

This helper checks whether a value is false, "false" or "no":

{{false value}}

{{eq}}

This helper checks whether two values are equal:

{{eq value1 value2}}

{{ne}}

This helper checks whether two values are different:

{{ne value1 value2}}

{{lt}}

This helper checks whether a value is less than another:

{{lt value1 value2}}

{{le}}

This helper checks whether a value is less than or equal to another:

{{le value1 value2}}

{{gt}}

This helper checks whether a value is greater than another:

{{gt value1 value2}}

{{ge}}

This helper checks whether a value is greater than or equal to another:

{{ge value1 value2}}

{{iif}}

This helper is similar to cond ? value1 : value2:

{{iif cond value1 value2}}

{{coalesce}}

This helper returns the first value not null:

{{coalesce value1 value2 value3...}}

Readme

Keywords

Package Sidebar

Install

npm i justo.plugin.handlebars

Homepage

justo.rocks

Weekly Downloads

2

Version

1.0.0-alpha3.0

License

none

Unpacked Size

6.92 kB

Total Files

4

Last publish

Collaborators

  • justojs