kabam-plugin-hogan

0.1.0 • Public • Published

kabam-plugin-hogan Build Status

Kabam plugin to add support for hogan-express template engine utilizing hogan.js.

Installing

  1. Read the documentation on syntax
  2. Install plugin from github or npm
  3. Include plugin as kabam.usePlugin('kabam-plugin-hogan');
  4. Create directory of views with templates - see example for details
  5. 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?

  1. Simple syntax
  2. High speed
  3. Yandex and Twitter used it
  4. 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

Readme

Keywords

none

Package Sidebar

Install

npm i kabam-plugin-hogan

Weekly Downloads

1

Version

0.1.0

License

MIT

Last publish

Collaborators

  • chopachom