# pug-runtime

> The runtime components for the pug templating language

Latest version **3.0.1** (published 2021-02-28) · MIT license · 0 weekly downloads

## Install

```sh
npm install pug-runtime
pnpm add pug-runtime
yarn add pug-runtime
bun add pug-runtime
```

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: no vulnerabilities; popular repo.

Warnings: low downloads; no types; no esm support.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 3.0.1 |
| Published | 2021-02-28 |
| First published | 2015-12-12 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 16.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 21847 |
| Author | ForbesLindesay |
| Maintainers | forbeslindesay, pug-bot |
| Keywords | pug |

## Links

- npm: https://www.npmjs.com/package/pug-runtime
- Repository: https://github.com/pugjs/pug/tree/master/packages/pug-runtime
- npm.io page: https://npm.io/package/pug-runtime

## Recent versions

- 3.0.1 (latest) — 2021-02-28
- 3.0.1-canary-10 (canary) — 2021-02-28
- 3.0.0 — 2020-05-25
- 3.0.0-canary-2 — 2020-05-25
- 3.0.0-canary-1 — 2020-05-24
- 2.0.5 — 2019-06-18
- 2.0.4 — 2018-03-06
- 2.0.3 — 2017-01-24
- 2.0.2 — 2016-07-26
- 2.0.1 — 2016-04-18
- 2.0.0 — 2015-12-23
- 0.0.0 — 2015-12-12

## README

# pug-runtime

The runtime components for the pug templating language

[![Build Status](https://img.shields.io/travis/pugjs/pug-runtime/master.svg)](https://travis-ci.org/pugjs/pug-runtime)
[![Dependencies Status](https://david-dm.org/pugjs/pug/status.svg?path=packages/pug-runtime)](https://david-dm.org/pugjs/pug?path=packages/pug-runtime)
[![DevDependencies Status](https://david-dm.org/pugjs/pug/dev-status.svg?path=packages/pug-runtime)](https://david-dm.org/pugjs/pug?path=packages/pug-runtime&type=dev)
[![NPM version](https://img.shields.io/npm/v/pug-runtime.svg)](https://www.npmjs.org/package/pug-runtime)

## 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.

```js
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.

```js
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')`:

```js
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

---
_Source: https://npm.io/package/pug-runtime · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
