An open API service indexing awesome lists of open source software.

https://github.com/posthtml/express-posthtml

PostHTML for Express
https://github.com/posthtml/express-posthtml

Last synced: 4 months ago
JSON representation

PostHTML for Express

Awesome Lists containing this project

README

          

[![npm][npm]][npm-url]
[![deps][deps]][deps-url]
[![tests][tests]][tests-url]
[![coverage][cover]][cover-url]
[![code style][style]][style-url]
[![chat][chat]][chat-badge]






Express PostHTML


Install

```bash
npm i -S express-posthtml
```

Usage

### Engine

Register PostHTML as Express View Engine

```js
app.engine('html', require('express-posthtml'))
```

Options

|Name|Type|Default|Description|
|:--:|:--:|:-----:|:----------|
|`plugins`|`{Array}`|`[]`|PostHTML Plugins|
|`options`|`{Object}`|`{}`|PostHTML Options|

### Global

All views will render with this setup, if no local setup provided.

```js
app.set('view options', { plugins: [], options: {} })
```

```js
res.render('file.ext')
```

### Local

View specific setup by adding plugins separately to the respective routes. Note that if you have set plugins globally, routes with local setup will not use the global setup by default.

```js
app.set('view options', { options: { parser: pug }})
```

```js
res.render('file.pug', { plugins: [...plugins] })
```

### Extend

If views share common plugins (e.g for [BEM Support][bem]), but view specific additions are necessary, use the extend option. Now the global setup is used and will be extended with the local plugins of the respective route.

[bem]: https://github.com/rajdee/posthtml-bem

```js
app.set('view options', { plugins: [...plugins], options: {} })
```

```js
res.render('file', { plugins: [/* PostHTML Plugins */], extend: true })
```

Example

```js
import express from 'express'
import posthtml from 'express-posthtml'

const app = express()

app.engine('html', posthtml)

const plugins = [
require('posthtml-bem')(),
require('posthtml-expressions')()
]
const options = {}

app.set('views', /* Path to views */)
app.set('view options', { plugins: plugins, options: options })

app.get('/', (req, res) => res.render('index.html'))

app.listen(3000)
```

Maintainers







Michael Ciniawsky


[npm]: https://img.shields.io/npm/v/express-posthtml.svg
[npm-url]: https://npmjs.com/package/express-posthtml

[node]: https://img.shields.io/node/v/postcss-load-plugins.svg
[node-url]: https://nodejs.org/

[deps]: https://david-dm.org/posthtml/express-posthtml.svg
[deps-url]: https://david-dm.org/posthtml/express-posthtml

[style]: https://img.shields.io/badge/code%20style-standard-yellow.svg
[style-url]: http://standardjs.com/

[tests]: http://img.shields.io/travis/posthtml/express-posthtml.svg
[tests-url]: https://travis-ci.org/posthtml/express-posthtml

[cover]: https://coveralls.io/repos/github/posthtml/express-posthtml/badge.svg
[cover-url]: https://coveralls.io/github/posthtml/express-posthtml

[chat]: https://badges.gitter.im/posthtml/posthtml.svg
[chat-badge]: https://gitter.im/posthtml/posthtml?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge"