Class: Wraith.Template

Defined in: src/template.coffee

Overview

The Wraith Template object is responsible for storing a template string, generating a template function and interpolating the data to generate a view off a given set of data.

Note: Based on John Resig's microtemplating function(s).

Class Method Summary

Instance Method Summary

Class Method Details

+ (void) escapeRegExp(string)

Borrowed from Underscores templates

Parameters:

  • string (String) The string to escape

+ (void) interpolate(model, tokens) (bound)

Takes a given token array and seeks out its value in the given model. It currently assumes that a model is a Wraith.Model object.

@returns [Object|String|Boolean] The results of the token search

Parameters:

  • model (Wraith.Model) The model to search for the given token array
  • tokens (String) The string of tokens to be used when searching the model (dot notation)

+ (void) interpolateClass(model, tokens) (bound)

Takes a given token array and seeks out its value in the given model. It currently assumes that a model is a Wraith.Model object.

@returns [Object|String|Boolean] The results of the token search

Parameters:

  • model (Wraith.Model) The model to search for the given token array
  • tokens (String) The string of tokens to be used when searching the model (dot notation)

Constructor Details

- (void) constructor(template)

Constructor

Parameters:

  • template (String) The template string to apply the data to on render.

Instance Method Details

- (void) compile(data)

Compiles a template with a ERB style markup. Note: Override this if you want to use a different template system.

NOTE: JavaScript templating a-la ERB, pilfered from John Resig's Secrets of the JavaScript Ninja, page 83. Single-quote fix from Rick Strahl. With alterations for arbitrary delimiters, and to preserve whitespace.

Parameters:

  • template (String) The template to compile