A Flight component for Hogan templating.
bower install --save flight-hoganrequirejs.config({ paths: { 'hoganjs': 'bower_components/hogan/web/build/2.0.0/hogan-2.0.0.amd' } });
Use the with_hogan mixin:
define(function (require) {
var defineComponent = require('flight/lib/component');
var withHogan = require('flight-hogan/lib/with_hogan');
return defineComponent(myComponent, withHogan);
function myComponent () {
this.after('initialize', function() {
var html = this.renderTemplate(
'Hello, {{name}}!', {
name: 'World'
});
this.$node.html(html);
});
}
});You can pass a hash of compiled templates as an option to the Hogan Precompiled component. You can generate compiled.js with Grunt using grunt-contrib-hogan.
var precompiledTemplates = require('templates/compiled');
var hoganPrecompiled = require('flight-hogan/lib/hogan_precompiled');
hoganPrecompiled.attachTo(document, {
precompiledTemplates: precompiledTemplates
});Precompiled templates are then available from the withHogan mixin:
define(function (require) {
var defineComponent = require('flight/lib/component');
var withHogan = require('flight-hogan/lib/with_hogan');
return defineComponent(myComponent, withHogan);
function myComponent () {
this.after('initialize', function() {
// e.g., render a 'hello_world' template from `templates/compiled.js`
var helloWorld = this.renderTemplate(
'hello_world', {
name: 'World'
});
});
}
});Partials will be searched for in compiled templates, or you can pass string partials to renderTemplate (you can't pass compiled templates as flight can't serialize them into event data).
define(function (require) {
var defineComponent = require('flight/lib/component');
var withHogan = require('flight-hogan/lib/with_hogan');
return defineComponent(myComponent, withHogan);
function myComponent () {
this.after('initialize', function() {
// render template with a partial
var helloWorld = this.renderTemplate('hello {{>planet}}', {}, {
planet: 'Mars'
});
});
}
});Development of this component requires Bower, and preferably Karma to be globally installed:
npm install -g bower karmaThen install the Node.js and client-side dependencies by running the following commands in the repo's root directory.
npm install
bower installTo continuously run the tests in Chrome and Firefox during development, just run:
karma startAnyone and everyone is welcome to contribute. Please take a moment to review the guidelines for contributing.