Skip to content

Commit e5131cf

Browse files
feat(index): expose posthtml options
1 parent f012ebe commit e5131cf

File tree

1 file changed

+30
-8
lines changed

1 file changed

+30
-8
lines changed

index.js

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,46 @@
77
const fs = require('fs')
88
const posthtml = require('posthtml')
99

10-
exports = module.exports = function (path, options, cb) {
10+
/**
11+
* @author Michael Ciniawsky (@michael-ciniawsky) <michael.ciniawsky@gmail.com>
12+
* @description PostHTML View Engine for Express
13+
* @license MIT
14+
*
15+
* @module express-posthtml
16+
* @version 1.1.0
17+
*
18+
* @requires posthtml
19+
*
20+
* @method posthtml
21+
*
22+
* @param {String} path View Path
23+
* @param {Object} options View Options
24+
* @param {Function} cb Callback
25+
*
26+
* @return {Function} cb HTML
27+
*/
28+
module.exports = function (path, options, cb) {
1129
options.extend = options.extend || false
1230

1331
let plugins
1432

15-
if (!options.plugins && options.extend === false) {
16-
plugins = options.settings['view options'] || []
33+
if (!options.plugins && !options.extend) {
34+
plugins = options.settings['view options'].plugins || []
1735
} else if (options.extend === true) {
18-
plugins = options.settings['view options'].concat(options.plugins)
36+
plugins = options.settings['view options'].plugins
37+
plugins = plugins.concat(options.plugins)
1938
} else {
2039
plugins = options.plugins || []
2140
}
2241

23-
fs.readFile(path, function (err, content) {
24-
if (err) return cb(new Error(err))
42+
options = options.settings['view options'].options || {}
2543

26-
posthtml(plugins)
27-
.process(content.toString())
44+
fs.readFile(path, 'utf8', (err, html) => {
45+
if (err) return cb(err)
46+
47+
return posthtml(plugins)
48+
.process(html, options)
2849
.then(result => cb(null, result.html))
50+
.catch((err) => cb(err))
2951
})
3052
}

0 commit comments

Comments
 (0)