Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

pug-runtime

pugjs7.3mMIT3.0.1

The runtime components for the pug templating language

pug

readme

pug-runtime

The runtime components for the pug templating language

Build Status Dependencies Status DevDependencies Status NPM version

Installation

npm install pug-runtime

Usage

You can call runtime methods directly using runtime.method. This is particularly useful when compiling to deal with things that are already known at compile time.

var runtime = require('pug-runtime');

assert(runtime.attr('foo', 'bar', true, true) === ' foo="bar"');

You can also build a string with a given list of functions available as pug_method by calling build(arrayOfMethods). This is useful for inlining runtime functions within the compiled templates.

var build = require('pug-runtime/build');
var src = build(['attr']);

var attr = Function('', src + ';return pug_attr;')();
assert(attr('foo', 'bar', true, true) === ' foo="bar"');

When testing code compiled for the browser in Node.js, it is necessary to make the runtime available. To do so, one can use require('pug-runtime/wrap'):

var pug = require('pug');
var wrap = require('pug-runtime/wrap');

var pugSrc = 'p= content';
// By default compileClient automatically embeds the needed runtime functions,
// rendering this module useless.
var compiledCode = pug.compileClient(pugSrc, {
  externalRuntime: true
});
//=> 'function template (locals) { ... pug.escape() ... }'

var templateFunc = wrap(compiledCode);
templateFunc({content: 'Hey!'});
//=> '<p>Hey!</p>'

// Change template function name to 'heyTemplate'
compiledCode = pug.compileClient(pugSrc, {
  externalRuntime: true,
  name: 'heyTemplate'
});
//=> 'function heyTemplate (locals) { ... }'

templateFunc = wrap(compiledCode, 'heyTemplate');
templateFunc({content: 'Hey!'});
//=> '<p>Hey!</p>'

License

MIT

changelog

Change Log

All notable changes to this project will be documented in this file. This project adheres to Semantic Versioning.

2.0.2

Changed

  • require('fs') calls will now be ignored by browser bundlers, through using browser field in package.json. Fallbacks for cases where fs module is not available were already in place prior to this release.

2.0.1

Changed

  • This package has been renamed to pug-runtime.
  • attrs() has been optimized.

2.0.0

Changed

  • classes() has been optimized, making it more than 9x faster.
  • style() has been optimized, making it 3-9x faster in average cases.
  • escape() has been optimized again, now with another 1-4x boost from the last release.
  • attrs(), attr(), and merge() also got some minor improvements. Although not benchmarked, we expect the new versions to perform better than last release.

Deprecated

  • Internal variables, or variables or functions that were not exported but visible through require('pug-runtime/build'), will not be visible through require('pug-runtime/build') anymore.
  • pug_encode_html_rules and pug_encode_char, two internal variables, have now been removed. Please note that any further changes to these internal variables will not come with a major bump.

Added

  • A new module require('pug-runtime/wrap') is added to ease testing client-side templates.

1.1.0 - 2015-07-09

Changed

  • escape() has been optimized, making it about 20-30% faster. The new implementation is inspired by the one from EJS.

1.0.0 - 2014-12-28

Added

  • Initial release