├── .editorconfig ├── .github ├── ISSUE_TEMPLATE.md └── PULL_REQUEST_TEMPLATE.md ├── .gitignore ├── .npmignore ├── .travis.yml ├── CHANGELOG.md ├── CONTRIBUTING.md ├── INDEX.md ├── LICENSE ├── README.md ├── index.js ├── package-lock.json ├── package.json └── test ├── fixtures ├── error.ssml ├── index.html ├── index.pug └── index.ssml └── index.test.js /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | charset = utf-8 5 | indent_size = 2 6 | end_of_line = lf 7 | indent_style = space 8 | trim_trailing_whitespace = true 9 | insert_final_newline = true 10 | 11 | [*.md] 12 | trim_trailing_whitespace = false 13 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | ## Problem 2 | 3 | Briefly describe the issue you are experiencing (or the feature you want to see 4 | added to the plugin). Tell us what you were trying to do and what happened 5 | instead. Remember, this is _not_ a place to ask questions. For that, go to 6 | http://gitter.im/posthtml/posthtml 7 | 8 | ## Details 9 | 10 | Describe in more detail the problem you have been experiencing, if necessary. 11 | 12 | ## Error Logs 13 | 14 | Create a [gist](https://gist.github.com) which is a paste of your **full** 15 | logs(_result.tree_ (PostHTML Tree), _result.html_ (HTML)), and link them here. 16 | Do **not** paste your full logs here, as it will make this issue long and hard 17 | to read! If you are reporting a bug, **always** include logs! 18 | 19 | ## Issue [ Code ] 20 | 21 | Please remember that, with sample code; it's easier to reproduce bug and much 22 | faster to fix it. 23 | 24 | Please refer to a simple code example. 25 | 26 | ```bash 27 | $ git clone https://github.com// 28 | ``` 29 | 30 | ## Environment 31 | 32 | Please provide information about your environment. 33 | 34 | | OS | Node | npm | PostHTML | 35 | |:------------:|:-----:|:-------:|:--------:| 36 | | OS X 10.11.4 | 6.0.0 | 3.9.0 | 0.8.7 | 37 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | ## Proposed Changes 2 | 3 | Describe the big picture of your changes here to communicate to the maintainers 4 | why we should accept this pull request. If it fixes a bug or resolves a feature 5 | request, be sure to link to that issue. 6 | 7 | ## Types of Changes 8 | 9 | What types of changes does your code introduce 10 | _Put an `x` in the boxes that apply_ 11 | 12 | - [ ] Bug (non-breaking change which fixes an issue) 13 | - [ ] Feature (non-breaking change which adds functionality) 14 | - [ ] Breaking Change (fix or feature which changes existing functionality) 15 | 16 | ## Checklist 17 | 18 | _Put an `x` in the boxes that apply. You can also fill these out after creating 19 | the PR. If you're unsure about any of them, don't hesitate to ask. We're here to 20 | help! This is a reminder of what we are going to look for before merging your 21 | code._ 22 | 23 | - [ ] I have read the [CONTRIBUTING](/CONTRIBUTING.md) guide 24 | - [ ] Lint and unit tests pass with my changes 25 | - [ ] I have added tests that prove my fix is effective/works 26 | - [ ] I have added necessary documentation (if appropriate) 27 | - [ ] Any dependent changes are merged and published in downstream modules 28 | 29 | ## Further Comments 30 | 31 | If this is a large or complex change, kick off the discussion by explaining why 32 | you chose the solution you did and what alternatives you considered, etc... 33 | 34 | ### Reviewers: @michael-ciniawsky, ... 35 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # OS 2 | 3 | .DS_Store 4 | ._* 5 | 6 | # NODEJS 7 | 8 | .nyc_output 9 | 10 | npm-debug.log 11 | 12 | coverage 13 | node_modules 14 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | # FILES 2 | 3 | .travis.yml 4 | .gitignore 5 | .editorconfig 6 | 7 | CONTRIBUTING.md 8 | 9 | npm-debug.log 10 | 11 | # DIRECTORIES 12 | 13 | .github 14 | .nyc_output 15 | 16 | dmd 17 | test 18 | coverage 19 | node_modules 20 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | 3 | node_js: 4 | - node 5 | - 6 6 | 7 | cache: 8 | directories: 9 | - node_modules 10 | 11 | after_success: 12 | - cat ./coverage/lcov.info | ./node_modules/.bin/coveralls' 13 | 14 | notifications: 15 | email: false 16 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Change Log 2 | 3 | All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines. 4 | 5 | 6 | # 1.1.0 (2017-03-08) 7 | 8 | 9 | ### Bug Fixes 10 | 11 | * **index.js:** add missing 'use strict' statement ([b2b51c4](https://github.com/posthtml/express-posthtml/commit/b2b51c4)) 12 | 13 | 14 | ### Features 15 | 16 | * add extend option ([e870b4d](https://github.com/posthtml/express-posthtml/commit/e870b4d)) 17 | * **index:** expose posthtml options ([e5131cf](https://github.com/posthtml/express-posthtml/commit/e5131cf)) 18 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | You want to help? You rock! Now, take a moment to be sure your contributions make sense to everyone else. 2 | 3 | ## Reporting Issues 4 | 5 | Found a problem? Want a new feature? 6 | 7 | - See if your issue or idea has [already been reported]. 8 | - Provide a [reduced test case] or a [live example]. 9 | 10 | Remember, a bug is a _demonstrable problem_ caused by _our_ code. 11 | 12 | ## Submitting Pull Requests 13 | 14 | Pull requests are the greatest contributions, so be sure they are focused in scope, and do avoid unrelated commits. 15 | 16 | 1. To begin, [fork this project], clone your fork, and add our upstream. 17 | ```bash 18 | # Clone your fork of the repo into the current directory 19 | git clone https://github.com//PLUGIN_NAME 20 | # Navigate to the newly cloned directory 21 | cd PLUGIN_NAME 22 | # Assign the original repo to a remote called "upstream" 23 | git remote add upstream https://github.com/GITHUB_NAME/PLUGIN_NAME 24 | # Install the tools necessary for development 25 | npm install 26 | ``` 27 | 28 | 2. Create a branch for your feature or fix: 29 | ```bash 30 | # Move into a new branch for a feature 31 | git checkout -b feature/thing 32 | ``` 33 | ```bash 34 | # Move into a new branch for a fix 35 | git checkout -b fix/something 36 | ``` 37 | 38 | 3. Be sure your code follows our practices. 39 | ```bash 40 | # Test current code 41 | npm run test 42 | ``` 43 | 44 | 4. Push your branch up to your fork: 45 | ```bash 46 | # Push a feature branch 47 | git push origin feature/thing 48 | ``` 49 | ```bash 50 | # Push a fix branch 51 | git push origin fix/something 52 | ``` 53 | 54 | 5. Now [open a pull request] with a clear title and description. 55 | 56 | [already been reported]: issues 57 | [fork this project]: fork 58 | [live example]: http://codepen.io/pen 59 | [open a pull request]: https://help.github.com/articles/using-pull-requests/ 60 | [reduced test case]: https://css-tricks.com/reduced-test-cases/ 61 | -------------------------------------------------------------------------------- /INDEX.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | ## posthtml(path, options, cb) ⇒ function 4 | PostHTML View Engine for Express 5 | 6 | **Kind**: global function 7 | **Returns**: function - cb HTML 8 | **Requires**: module:posthtml 9 | **Version**: 1.1.0 10 | **Author**: Michael Ciniawsky (@michael-ciniawsky) 11 | **License**: MIT 12 | 13 | | Param | Type | Description | 14 | | --- | --- | --- | 15 | | path | String | View Path | 16 | | options | Object | View Options | 17 | | cb | function | Callback | 18 | 19 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License (MIT) 2 | 3 | Copyright (c) 2016 Michael Ciniawsky 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![npm][npm]][npm-url] 2 | [![deps][deps]][deps-url] 3 | [![tests][tests]][tests-url] 4 | [![coverage][cover]][cover-url] 5 | [![code style][style]][style-url] 6 | [![chat][chat]][chat-badge] 7 | 8 |
9 | 10 | 11 | 12 | 13 |

Express PostHTML

14 |
15 | 16 |

Install

17 | 18 | ```bash 19 | npm i -S express-posthtml 20 | ``` 21 | 22 |

Usage

23 | 24 | ### Engine 25 | 26 | Register PostHTML as Express View Engine 27 | 28 | ```js 29 | app.engine('html', require('express-posthtml')) 30 | ``` 31 | 32 |

Options

33 | 34 | |Name|Type|Default|Description| 35 | |:--:|:--:|:-----:|:----------| 36 | |`plugins`|`{Array}`|`[]`|PostHTML Plugins| 37 | |`options`|`{Object}`|`{}`|PostHTML Options| 38 | 39 | ### Global 40 | 41 | All views will render with this setup, if no local setup provided. 42 | 43 | ```js 44 | app.set('view options', { plugins: [], options: {} }) 45 | ``` 46 | 47 | ```js 48 | res.render('file.ext') 49 | ``` 50 | 51 | ### Local 52 | 53 | 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. 54 | 55 | ```js 56 | app.set('view options', { options: { parser: pug }}) 57 | ``` 58 | 59 | ```js 60 | res.render('file.pug', { plugins: [...plugins] }) 61 | ``` 62 | 63 | ### Extend 64 | 65 | 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. 66 | 67 | [bem]: https://github.com/rajdee/posthtml-bem 68 | 69 | ```js 70 | app.set('view options', { plugins: [...plugins], options: {} }) 71 | ``` 72 | 73 | ```js 74 | res.render('file', { plugins: [/* PostHTML Plugins */], extend: true }) 75 | ``` 76 | 77 |

Example

78 | 79 | ```js 80 | import express from 'express' 81 | import posthtml from 'express-posthtml' 82 | 83 | const app = express() 84 | 85 | app.engine('html', posthtml) 86 | 87 | const plugins = [ 88 | require('posthtml-bem')(), 89 | require('posthtml-expressions')() 90 | ] 91 | const options = {} 92 | 93 | app.set('views', /* Path to views */) 94 | app.set('view options', { plugins: plugins, options: options }) 95 | 96 | app.get('/', (req, res) => res.render('index.html')) 97 | 98 | app.listen(3000) 99 | ``` 100 | 101 |

Maintainers

102 | 103 | 104 | 105 | 106 | 112 | 113 | 114 |
107 | 109 |
110 | Michael Ciniawsky 111 |
115 | 116 | [npm]: https://img.shields.io/npm/v/express-posthtml.svg 117 | [npm-url]: https://npmjs.com/package/express-posthtml 118 | 119 | [node]: https://img.shields.io/node/v/postcss-load-plugins.svg 120 | [node-url]: https://nodejs.org/ 121 | 122 | [deps]: https://david-dm.org/posthtml/express-posthtml.svg 123 | [deps-url]: https://david-dm.org/posthtml/express-posthtml 124 | 125 | [style]: https://img.shields.io/badge/code%20style-standard-yellow.svg 126 | [style-url]: http://standardjs.com/ 127 | 128 | [tests]: http://img.shields.io/travis/posthtml/express-posthtml.svg 129 | [tests-url]: https://travis-ci.org/posthtml/express-posthtml 130 | 131 | [cover]: https://coveralls.io/repos/github/posthtml/express-posthtml/badge.svg 132 | [cover-url]: https://coveralls.io/github/posthtml/express-posthtml 133 | 134 | [chat]: https://badges.gitter.im/posthtml/posthtml.svg 135 | [chat-badge]: https://gitter.im/posthtml/posthtml?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge" 136 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | // ------------------------------------ 2 | // #EXPRESS - POSTHTML 3 | // ------------------------------------ 4 | 5 | 'use strict' 6 | 7 | const fs = require('fs') 8 | const posthtml = require('posthtml') 9 | 10 | /** 11 | * @author Michael Ciniawsky (@michael-ciniawsky) 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) { 29 | options.extend = options.extend || false 30 | 31 | let plugins 32 | 33 | if (!options.plugins && !options.extend) { 34 | plugins = options.settings['view options'].plugins || [] 35 | } else if (options.extend === true) { 36 | plugins = options.settings['view options'].plugins 37 | plugins = plugins.concat(options.plugins) 38 | } else { 39 | plugins = options.plugins || [] 40 | } 41 | 42 | options = options.settings['view options'].options || {} 43 | 44 | fs.readFile(path, 'utf8', (err, html) => { 45 | if (err) return cb(err) 46 | 47 | return posthtml(plugins) 48 | .process(html, options) 49 | .then(result => cb(null, result.html)) 50 | .catch((err) => cb(err)) 51 | }) 52 | } 53 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "express-posthtml", 3 | "version": "1.1.0", 4 | "description": "PostHTML View Engine for Express", 5 | "engines": { 6 | "node": ">=6" 7 | }, 8 | "main": "index.js", 9 | "scripts": { 10 | "lint": "standard", 11 | "test": "jest --verbose --coverage", 12 | "docs": "jsdoc2md index.js > INDEX.md", 13 | "clean": "rm -rf jest coverage jsdoc-api dmd", 14 | "start": "sudo npm run clean && npm run lint && npm test", 15 | "release": "standard-version" 16 | }, 17 | "dependencies": { 18 | "posthtml": "^0.11.3" 19 | }, 20 | "devDependencies": { 21 | "coveralls": "^3.0.3", 22 | "express": "^4.15.2", 23 | "jest": "^24.7.1", 24 | "jsdoc-to-markdown": "^4.0.1", 25 | "posthtml-bem": "^0.2.2", 26 | "posthtml-expressions": "^1.1.0", 27 | "posthtml-pug": "^1.0.2", 28 | "posthtml-sugarml": "^1.0.0-alpha3", 29 | "standard": "^12.0.1", 30 | "standard-version": "^8.0.1", 31 | "supertest": "^4.0.2" 32 | }, 33 | "standard": { 34 | "env": { 35 | "jest": true 36 | } 37 | }, 38 | "keywords": [ 39 | "HTML", 40 | "PostHTML", 41 | "Express", 42 | "View Engine" 43 | ], 44 | "author": { 45 | "name": "Michael Ciniawsky", 46 | "email": "" 47 | }, 48 | "repository": { 49 | "type": "git", 50 | "url": "git+https://github.com/posthtml/express-posthtml.git" 51 | }, 52 | "bugs": { 53 | "url": "https://github.com/posthtml/express-posthtml/issues" 54 | }, 55 | "homepage": "https://github.com/posthtml/express-posthtml#readme", 56 | "license": "MIT" 57 | } 58 | -------------------------------------------------------------------------------- /test/fixtures/error.ssml: -------------------------------------------------------------------------------- 1 |

dsasadqw.34.2EQ#$234 2 | -------------------------------------------------------------------------------- /test/fixtures/index.html: -------------------------------------------------------------------------------- 1 |

{{ foo }}
2 | -------------------------------------------------------------------------------- /test/fixtures/index.pug: -------------------------------------------------------------------------------- 1 | div {{ foo }} 2 | -------------------------------------------------------------------------------- /test/fixtures/index.ssml: -------------------------------------------------------------------------------- 1 | div {{ foo }} 2 | -------------------------------------------------------------------------------- /test/index.test.js: -------------------------------------------------------------------------------- 1 | // ------------------------------------ 2 | // #EXPRESS - POSTHTML - TEST 3 | // ------------------------------------ 4 | 5 | 'use strict' 6 | const path = require('path') 7 | 8 | const express = require('express') 9 | const supertest = require('supertest') 10 | 11 | const posthtml = require('..') 12 | 13 | test('Pug', () => { 14 | const app = express() 15 | 16 | const plugins = [ 17 | require('posthtml-expressions')({ locals: { foo: 'bar' } }) 18 | ] 19 | const options = { parser: require('posthtml-pug')() } 20 | 21 | app.engine('pug', posthtml) 22 | 23 | app.set('views', path.resolve(__dirname, 'fixtures')) 24 | app.set('view options', { plugins: plugins, options: options }) 25 | 26 | app.get('/', (req, res) => res.render('index.pug')) 27 | 28 | return supertest(app).get('/').expect(200).then((res) => { 29 | expect(res.text.trim()).toEqual('
bar
') 30 | }) 31 | }) 32 | 33 | test('HTML', () => { 34 | const app = express() 35 | 36 | const plugins = [ 37 | require('posthtml-expressions')({ locals: { foo: 'bar' } }) 38 | ] 39 | 40 | app.engine('html', posthtml) 41 | 42 | app.set('views', path.resolve(__dirname, 'fixtures')) 43 | app.set('view options', { plugins: plugins }) 44 | 45 | app.get('/', (req, res) => res.render('index.html')) 46 | 47 | return supertest(app).get('/').expect(200).then((res) => { 48 | expect(res.text.trim()).toEqual('
bar
') 49 | }) 50 | }) 51 | 52 | test('SSML', () => { 53 | const app = express() 54 | 55 | const plugins = [ 56 | require('posthtml-expressions')({ locals: { foo: 'bar' } }) 57 | ] 58 | const options = { parser: require('posthtml-sugarml')() } 59 | 60 | app.engine('ssml', posthtml) 61 | 62 | app.set('views', path.resolve(__dirname, 'fixtures')) 63 | app.set('view options', { plugins: plugins, options: options }) 64 | 65 | app.get('/', (req, res) => res.render('index.ssml')) 66 | 67 | return supertest(app).get('/').expect(200).then((res) => { 68 | expect(res.text.trim()).toEqual('
bar
') 69 | }) 70 | }) 71 | 72 | test.skip('Error', () => { 73 | const app = express() 74 | 75 | const plugins = [ 76 | require('posthtml-expressions')({ locals: { foo: 'bar' } }) 77 | ] 78 | const options = { parser: require('posthtml-sugarml')() } 79 | 80 | app.engine('ssml', posthtml) 81 | 82 | app.set('views', path.resolve(__dirname, 'fixtures')) 83 | app.set('view options', { plugins: plugins, options: options }) 84 | 85 | app.get('/', (req, res) => res.render('error.ssml')) 86 | 87 | return supertest(app).get('/').then((res) => expect(res.status).toEqual(500)) 88 | }) 89 | --------------------------------------------------------------------------------