2.1.1 • Published 3 years ago

template-function-express-engine v2.1.1

Weekly downloads
5
License
MIT
Repository
github
Last release
3 years ago

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.

2.1.1

3 years ago

2.1.0

3 years ago

2.0.0

6 years ago

1.0.0

7 years ago

0.3.0

7 years ago

0.2.1

8 years ago

0.1.4

8 years ago

0.2.0

8 years ago

0.1.3

8 years ago

0.1.2

8 years ago

0.1.1

8 years ago

0.1.0

8 years ago