Socket
Socket
Sign inDemoInstall

jade-runtime

Package Overview
Dependencies
0
Maintainers
6
Versions
4
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    jade-runtime

The runtime components for the jade templating language


Version published
Weekly downloads
39
increased by18.18%
Maintainers
6
Install size
16.5 kB
Created
Weekly downloads
 

Changelog

Source

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.

Readme

Source

jade-runtime

The runtime components for the jade templating language

Build Status Dependency Status NPM version

Installation

npm install jade-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('jade-runtime');

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

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

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

var attr = Function('', src + ';return jade_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('jade-runtime/wrap'):

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

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

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

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

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

License

MIT

Keywords

FAQs

Last updated on 14 Nov 2015

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc