You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 7-8.RSVP
Socket
Socket
Sign inDemoInstall

pug-runtime

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pug-runtime

The runtime components for the jade templating language


Version published
Maintainers
1
Created

Package description

What is pug-runtime?

The pug-runtime package is a runtime library for Pug, a high-performance template engine heavily influenced by Haml and implemented with JavaScript for Node.js and browsers. It is used to render Pug templates into HTML.

What are pug-runtime's main functionalities?

Rendering Pug Templates

This feature allows you to compile and render Pug templates into HTML. The code sample demonstrates how to compile a simple Pug template and render it with a given context.

const pug = require('pug-runtime');
const template = pug.compile('p Hello, #{name}!');
const html = template({ name: 'World' });
console.log(html); // Outputs: <p>Hello, World!</p>

Precompiled Templates

This feature allows you to use precompiled Pug templates. The code sample shows how to render HTML using a precompiled template function.

const pug = require('pug-runtime');
const precompiledTemplate = function(locals) { return pug.render('p Hello, ' + locals.name + '!'); };
const html = precompiledTemplate({ name: 'World' });
console.log(html); // Outputs: <p>Hello, World!</p>

Other packages similar to pug-runtime

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

Package last updated on 12 Dec 2015

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc