pug-runtime
The runtime components for the pug templating language
Last updated 8 years ago by forbeslindesay .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ npm install pug-runtime 
SYNC missed versions from official npm registry.

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

Current Tags

  • 3.0.1-canary-10                                ...           canary (4 years ago)
  • 3.0.1                                ...           latest (4 years ago)

12 Versions

  • 3.0.1                                ...           4 years ago
  • 3.0.1-canary-10                                ...           4 years ago
  • 3.0.0                                ...           4 years ago
  • 3.0.0-canary-2                                ...           4 years ago
  • 3.0.0-canary-1                                ...           4 years ago
  • 2.0.5                                ...           5 years ago
  • 2.0.4                                ...           7 years ago
  • 2.0.3                                ...           8 years ago
  • 2.0.2                                ...           8 years ago
  • 2.0.1                                ...           9 years ago
  • 2.0.0                                ...           9 years ago
  • 0.0.0                                ...           9 years ago
Downloads
Total 2
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (0)
None
Dev Dependencies (1)

© 2010 - cnpmjs.org x YWFE | Home | YWFE