This package has been deprecated

Author message:

Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.

template-function-express-engine
TypeScript icon, indicating that this package has built-in type declarations

2.1.1 • Public • Published

Template Function Express Engine

Available from NPM Built using Travis

An Express engine for template functions.

What is a template function?

A template function is just a function that returns a string:

function anExampleTemplateFunction ()
{
	return 'I am a template function.';
}

Template functions are useful because they are just ordinary functions written in JavaScript; partials and layouts are achieved simply by calling another function and there is no performance overhead by introducing a new syntax.

Usage

You can hook up this engine into Express using express#engine():

const express          = require('express');
const { createEngine } = require('template-function-express-engine');

express()

	.engine(
		'js', createEngine()
	)

	.set('view engine', 'js');

Your template file must export a synchronous function that returns a string and accepts one argument which will be representing the model. For example:

module.exports = function greetings ({ firstName, lastName })
{
	return `Hello, my name is ${firstName} ${lastName}.`;
};

Caching

For development, it is useful to update your templates without restarting the web server. This engine will respect the view cache setting.

Getting started

This project is available through the Node Package Manager (NPM), so you can install it like so:

npm install template-function-express-engine

Please Note: Versions of Node lower than v7.0.0 are not supported.

Development

This project doesn't have much of a build process. It does have tests though; which you can run like so:

npm test

This also runs code quality checks using ESLint. Please refer to the .eslintrc files to familiar yourself with the rules.

License

This project is released under the MIT license.

Package Sidebar

Install

npm i template-function-express-engine

Weekly Downloads

0

Version

2.1.1

License

MIT

Unpacked Size

7.63 kB

Total Files

6

Last publish

Collaborators

  • lsphillips