New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

adapter-template

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

adapter-template

Adapters to standardise the interfaces on the plethora of available templating engines.

  • 0.6.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1
decreased by-75%
Maintainers
1
Weekly downloads
 
Created
Source

adapter-template

Adapters to standardise the interfaces on the plethora of available templating engines.

wercker status

Usage

To use the adapter, invoke the package with the name of the template language you want to use:

var adapter = require('adapter-template');
var jade = adapter('jade');

The adapter will now provide access to an appropriate templating engine via a renderFile method which takes as parameters a path to a template, an object that can be used by that template, and a callback:

jade.renderFile('./test/fixtures/user.jade', { user: 'tobi' }, function (err, html){
  console.log(html);
});

To use the adapter in Express, do the following:

var express = require('express');
var adapter = require('adapter-template');
var engineName = 'jade';

var app = express();

app.engine(engineName, adapter(engineName).renderFile);
app.set('views', __dirname + '/fixtures');
...

Express requires a function that takes a path, locals and a callback, which renderFile does.

Adding Additional Templating Engines

Adding an Engine That Already Supports Express

The easiest templating libraries to support are those that:

  • provide Express support by way of the express() or renderFile() method;
  • have the same module name as the template file extension.

All that is required for these is to add an entry for an engine to the dependencies in package.json, and a template with the same file extension to the fixtures collection in the tests directory (see test/fixtures). This template will be picked up automatically when running tests, and its presence will cause a test to be run for the corresponding template engine.

Adding an Express-compatible Engine Named Differently to Its Language

The next most simple templating engine to support are those that:

  • provide Express support by way of the express() or renderFile() method;
  • have a different module name to the template file extension.

As described in the previous section, an entry is needed in package.json and a template must be added to the fixtures collection in the tests directory in order to trigger tests. But in addition an entry is needed in lib/setModuleDefaults.js to indicate what the real module name is. For example, to use the module hbs to provide Handlebars support, the following needs to be added to the default settings:

handlebars: {
  module: 'hbs'
}

Without this entry the generic adapter will try to load a module called handlebars.

Template Languages Supported:

  • atpl
  • ejs
  • handlebars
  • jade
  • swig
  • toffee
  • whiskers

Changelog

2014-07-28 (v0.6.0)

Add handlebars support.

Enable modules to have a different name to the template language they support.

2014-07-25 (v0.5.0)

Add swig support.

2014-07-25 (v0.4.0)

package.json was breaking Wercker.

Improve descriptions in README.

2014-07-25 (v0.3.0)

Ensure package.json is ready for NPM publishing.

2014-07-25 (v0.2.0)

Fix test dependencies for Wercker.

Add Wercker status badge to README.

2014-07-25 (v0.1.0)

Initial release with support for template engines that already provide Express support.

Keywords

FAQs

Package last updated on 28 Jul 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc