tengine
Unifying APIs of various of template engines.
Last updated 2 years ago by lvchengbin .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install tengine 
SYNC missed versions from official npm registry.

Tengine

Unifying APIs of various of template engines.

Build Status Coverage Status Node Version License NPM Version NPM Download Greenkeeper badge

Installation

$ npm install tengine --save

Usage

const path = require( 'path' );
const tengine = require( 'tengine' );

const engine = tengine( 'nunjucks' );

engine.configure( {
    config : {
        autoescape : false
    },
    filters : {
        repeat : str => str + str
    }
} );

engine.global = { engine : 'tengine' };
eigine.base = path.join( __dirname, 'templates' );

engine.render( 'index.html', {
    title : 'tengine'
} ).then( res => {
    console.log( res );
} );

Supported template engines

APIs

tengine( string name[, object engine ] )

To initialize a template Engine

  • name: the name of the template engine, see Supported template engines
  • engine: to specify another template engine for replacing the default engine.
const engine = tengine( 'doT' );
const nunjucks = require( 'nunjucks' );
const engine = tengine( 'nunjucks', nunjucks );

tengine.support( string name )

to check if the template engine is supported in tengine.

  • name: the name of the template engine

tengine.engines

An array of supported template engine's name.

engine.global

Global variables for templates.

const engine = require( 'underscore' );

engine.global = {
    title : 'global title'    
}

engine.renderString( '<%-title %>' ).then( res => {
    console.log( res ); // output: global title
} );

engine.base

The base directory of template files

const engine = tengine( 'ejs' );
engine.base = '/path/to/ejs/template/directory';
engine.render( 'index.html' );

engine.engine

The template engine instance.

engins.path( string name )

To get the full path of a template file in base direcotry.

  • name: the file name of the template file.

engine.context( object data )

To get the context data which will includes the global variables if exists.

  • the local context for compiling the template.

engine.configure( object options )

Configuring the template engines.

engine.render( string file, object context )

Rendering a template file.

  • file: the template file name.
  • context: the context for the template

engine.renderString( string str, object context )

Rendering template string.

  • str: the template string
  • context: the context for compiling

Current Tags

  • 0.0.6                                ...           latest (2 years ago)

7 Versions

  • 0.0.6                                ...           2 years ago
  • 0.0.5                                ...           2 years ago
  • 0.0.4                                ...           2 years ago
  • 0.0.3                                ...           2 years ago
  • 0.0.2                                ...           2 years ago
  • 0.0.1                                ...           2 years ago
  • 0.0.0                                ...           2 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 3
Last Day 0
Last Week 3
Last Month 7
Dependencies (10)
Dev Dependencies (4)
Dependents (1)

Copyright 2014 - 2016 © taobao.org |