Handlebars
Path:
/src/type/handlebars.coffee
compiled to/lib/type/handlebars.js
Validate a possible handlebar template and return the function to directly use it.
A template function or template source or normal text are all valid and result in returning a function which may be called with a context will return the template’s resulting text.
A text which may contain handlebars syntax will be compiled into a function which if called with the context object will return the resulting text.
CoffeeScript Code validator.check
name: 'test' # name to be displayed in errors (optional)
value: 'hello {{name}}' # value to check
schema: # definition of checks
type: 'handlebars'
, (err, result) ->
# then use it
console.log result
name: 'alex'
# this will output 'hello alex'
Within the handlebars templates you may use:
- builtin helpers
- additional handlebars helpers
Schema Specification
Handlebars are a handlebars schema definition.
An object with the following keys allowed: title
, description
, key
, type
, optional
, default
. The following entries have a specific format:
title
-
Title is the title used to describe the element.
A text entry which is optional. All control characters will be removed.
description
-
Description is the free description of the element.
A text entry which is optional. All control characters will be removed.
key
-
Binding to Keyname is the mapping to which key names in an object this element belongs.
A valid regular expression which is optional. It has to be one of the following types:
- An object which has to be an instance of class
RegExp
. - A text entry in which all control characters will be removed. The text should match: /^/.?/[gim]$/.
- An object which has to be an instance of class
type
-
Type is the type of element.
A text entry in which all control characters will be removed.
optional
-
Optional is a flag defining if this element is optional.
A boolean value, which will be true for ‘true’, ‘1’, ‘on’, ‘yes’, ‘+’, 1, true and will be considered as false for ‘false’, ‘0’, ‘off’, ‘no’, ‘-’, 0, false. It’s optional.
default
-
Default Value is the default value to use if nothing given.
It has to be one of the following types (optional):
-
Template is the default template text to use.
A text entry in which all control characters will be removed.
-
Function is the default function to use.
The value has to be a function/class.
-