kabam-plugin-hogan
v0.1.0
Published
MWC core plugin to add support for hogan express template engine
Downloads
3
Readme
kabam-plugin-hogan
Kabam plugin to add support for hogan-express template engine utilizing hogan.js.
Installing
- Read the documentation on syntax
- Install plugin from github or npm
- Include plugin as
kabam.usePlugin('kabam-plugin-hogan');
- Create directory of views with templates - see example for details
- When you issue render function on response object in route of ExpressJS application, the view is rendered by hogan
Example
var kabamKernel = require('kabam-kernel');
var kabam = kabamKernel(require('./config.json')[(process.env.NODE_ENV) ? (process.env.NODE_ENV) : 'development']);
kabam.usePlugin(require('kabam-plugin-hogan'));
kabam.extendApp(function(core) { //setting variables accessible in all templates
core.app.locals.viewEngine = 'hogan'; //http://expressjs.com/api.html#app.locals
});
kabam.extendRoutes(function(core) {
core.app.get('/', function(req, res) {
res.render('index/index', {
'title': 'Hello, world!',
'content': 'This application uses template engine!'
});
});
core.app.get('/withOutLayout', function(req, res) {
res.type('txt');
res.render('index/index', {
'title': 'Hello, world!',
'layout': false, //we turning off the layout part of template
'content': 'This application uses template engine!',
'time': (new Date()).toLocaleTimeString()
});
});
core.app.get('/withPartials', function(req, res) {
res.render('index/index', {
'title': 'Hello, world!',
'partials': {
timePartial: 'index/partials/_currentTime'
}, //we use partials
'content': 'This application uses template engine!',
'time': (new Date()).toLocaleTimeString()
});
});
});
kabam.start();
Contents of view folder:
`views/`
`index/`
`partials/`
`_currentTime.html`
`index.html`
`layout.html`
Mustache syntax
http://mustache.github.io/mustache.5.html
Why use mustache?
- Simple syntax
- High speed
- Yandex and Twitter used it
- You can render html, rss, xml, docx and whatever want.
Test
# Install the dependencies
$ npm install
# Run the test runner
$ npm test
Configuring
This plugin has a way to include css and javascript files URL in layout file.
kabam.extendApp(kabam) {
kabam.app.locals.css.push({url: '//yandex.st/bootstrap/2.3.2/css/bootstrap.min.css'});
kabam.app.locals.javascripts.push({url: '//yandex.st/bootstrap/2.3.2/js/bootstrap.min.js', async: true});
};
Responsibility guidelines
Every kabam plugin and package has the responsible developer. His duties are
- Maintain the package - fix and find bugs from upgrading modules included or nodejs version changing
- React on bug reports
- Accept/deny pull request.
The Push
and npm publish
privilege is the right of the Responsible developer
, but the fork
- is for everybody.
Responsible developer for this package is Anatolij Ostroumov