0.1.3 • Published 12 years ago

ss-hogan v0.1.3

Weekly downloads
30
License
-
Repository
github
Last release
12 years ago

Hogan Template Engine wrapper for SocketStream 0.3

http://twitter.github.com/hogan.js/

Use pre-compiled Hogan (Mustache-compatible) client-side templates in your app to benefit from increased performance and a smaller client-side library download.

Installation

Note: ss-hogan is installed by default with new apps created by SocketStream 0.3 alpha2 onwards.

First download template.js from https://raw.github.com/twitter/hogan.js/master/lib/template.js and add this to your /client/code/lib folder. This is the Hogan VM which renders pre-compiled templates. It is smaller in size than the all-inclusive hogan.js file which includes the compiler and should not be sent to the client.

Secondly, add ss-hogan to your application's package.json file and then add this line to app.js:

ss.client.templateEngine.use(require('ss-hogan'));

Restart the server. From now on all templates will be pre-compiled and attached to the HT window/global variable.

Usage

E.g. a template placed in

/client/templates/offers/latest.html

Can be rendered in your browser with

html = HT['offers-latest'].render({name: 'Special Offers'})

Options

When experimenting with Hogan, or converting an app from one template type to another, you may find it advantageous to use multiple template engines and confine use of Hogan to a sub-directory of /client/templates.

Directory names can be passed to the second argument as so:

ss.client.templateEngine.use(require('ss-hogan'), '/hogan-templates');

To specify another global/window variable instead of HT set the 'namespace' option in the config as so:

ss.client.templateEngine.use(require('ss-hogan'), '/', {namespace: 'MyVar'});