Template

Skull. Template

new Template()

Skull.Template provides wrapper for template engine (_.template by default). This wrapper performs caching, error handling and adding a bit of debugging info. By default Skull.Template fetches templates stored in script tags with js-tpl-<templateName> class.

Source:

Methods

(protected) _compileTemplate(rawTemplate) → {function}

Compiles template to function

Parameters:
Name Type Description
rawTemplate String
Source:
Returns:
Type
function

(protected) _getCompiledTemplate(name) → {function}

Gets compiled template by its name

Parameters:
Name Type Description
name String
Source:
Returns:
Type
function

(protected) _getTemplate(name) → {function}

Returns either cached compiled template or compiles it, caches and returns it

Parameters:
Name Type Description
name String

template name

Source:
Returns:

compiled template

Type
function

(protected) _getTemplateNode(name) → {jQuery}

Fetches template by name.

Parameters:
Name Type Description
name String
Source:
Throws:

'No such template'

Type
Error
Returns:
Type
jQuery

(protected) _preprocessTemplate(node) → {String}

Primary templates processing – e.g. whitespace trimming

Parameters:
Name Type Description
node jQuery
Source:
Returns:
Type
String

initialize(options)

Parameters:
Name Type Description
options Object
Properties
Name Type Attributes Default Description
selectorPrefix String <optional>
'script.js-tpl-'

default selector for finding template nodes

trim Boolean <optional>
true

trim whitespaces from template before compiling

dontCache Boolean <optional>
false

Useful when developing, you can change template right on page without reloading it

tplFunction function <optional>
_.template

Template function must accept template string and return compiled to function template. Another (and preferable) way to change this is to inherit and override.

Source:

tmpl(name, tplDataopt, callbackopt) → {function|String|undefined}

This normally should be only one Template method you call from other places. When provided with truthie second argument, returns rendered templates, otherwise, compiled. When provided with third argument, calls it with passing, again, rendered or compiled template.

Parameters:
Name Type Attributes Default Description
name String
tplData Object <optional>
null

if passed, function returns rendered template. If not, compiled template.

callback function <optional>
null

if defined, will be called instead of returning result.

Source:
Returns:
Type
function | String | undefined