JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 1
  • Score
    100M100P100Q32609F
  • License MIT

PostHTML for Express

Package Exports

  • express-posthtml

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (express-posthtml) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

NPM Node Dependencies DevDependencies Standard Code Style

Install

$ npm i -S express-posthtml

Usage

Engine

Register PostHTML as View Engine

app.engine('html', require('posthtml'))

app.set('views', /* Path to views */)
app.set('view engine', 'html')

Plugins

Global

All Views will be render with this plugin setup, if no local setup provided.

app.set('view options', [ PostHTML Plugins ])
res.render('file')

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.

app.set('view options', [])
res.render('file', { plugins: [ PostHTML Plugins ] })

Extend

If views share common plugins (e.g for BEM Support), 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.

app.set('view options', [ PostHTML Global Plugins ])
res.render('file', { plugins: [ PostHTML Local Plugins ], extend: true, })

Example

Plugins

'use strict'

// Plugins
const bem = require('posthtml-bem')
const each = require('posthtml-each')
const include = require('posthtml-include')

// App
const express = require('express')

let app = express()

// App Engine
app.engine('html', require('posthtml'))

// Settings
app.set('views', /* Path to views */)
app.set('view engine', 'html')
app.set('view options', [ include(), bem(), ]) // Global Setup

// Global Use
app.get('/', (req, res) => {
    res.render('file')
  })
// Local Use
app.get('/local', (req, res) => {
    res.render('file', { plugins: [ include(), bem({
      elemPrefix: '_',
      modPrefix: '-',
      modDlmtr: '--'})
    ] })
  })
// Extend Use
app.get('/extend', (req, res) => {
    res.render('file', { plugins: [ each() ], extend: true } )
  })  

app.listen(3000, () => {
    console.log('==> Server started')
  }
)

Package

'use strict'

// Package
const html = require('posthtml-package-html')(/* options */)

// Package for local use
const $html = require('posthtml-package-html')({
  bem: { elemPrefix: '__', modPrefix: '-', modDlmtr: '--'}
})

// App
const express = require('express')

let app = express()

// App Engine
app.engine('html', require('posthtml'))

app.set('views', /* Path to views */)
app.set('view engine', 'html')
app.set('view options', html) // Global Setup

// Global Use
app.get('/', (req, res) => {
  res.render('file')
})

// Local Use
app.get('/local', (req, res) => {   
  res.render('file', { plugins: $html })
})

// Extend Use
app.get('/extend', (req, res) => {   
  res.render('file', { extend: true, plugins: [
    require('posthtml-style-to-file')({ path: './public/styles/style.css' })   
  ] })
})

app.listen(3000, () => {
    console.log('=> Server started')
  }
)

LICENSE

MIT License (MIT)

Copyright (c) 2016 Michael Ciniawsky

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.