Skip to content

Commit 9b35192

Browse files
authored
Merge pull request #125 from posthtml/milestone-1.0.3
Milestone 1.0.3
2 parents d685485 + a0277cf commit 9b35192

23 files changed

+262
-43
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ language: node_js
33
node_js:
44
- stable
55
- lts/*
6-
- 8
6+
- 10
77

88
after_success:
99
- cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js"

README.md

Lines changed: 81 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,11 @@ module: {
5757
|:--:|:--:|:-----:|:----------|
5858
|**[`config`](#config)**|`{Object}`|`undefined`|PostHTML Config|
5959
|**[`parser`](#parser)**|`{String/Function}`|`undefined`|PostHTML Parser|
60+
|**[`skipParse`](#skipParse)**|`{Boolean}`|`false`|PostHTML Options SkipParse|
61+
|**[`render`](#render)**|`{String/Function}`|`undefined`|PostHTML Render|
6062
|**[`plugins`](#plugins)**|`{Array/Function}`|`[]`|PostHTML Plugins|
63+
|**[`sync`](#sync)**|`{boolean}`|`false`|PostHTML Options Sync|
64+
|**[`directives`](#directives)**|`{Array<Object>}`|`[]`|PostHTML Options custom [Directives](https://github.com/posthtml/posthtml-parser#directives)|
6165

6266
### `Config`
6367

@@ -66,6 +70,7 @@ module: {
6670
|**[`path`](#path)**|`{String}`|`loader.resourcePath`|PostHTML Config Path|
6771
|**[`ctx`](#context)**|`{Object}`|`{}`|PostHTML Config Context|
6872

73+
6974
If you want to use are shareable config file instead of inline options in your `webpack.config.js` create a `posthtml.config.js` file and place it somewhere down the file tree in your project. The nearest config relative to `dirname(file)` currently processed by the loader applies. This enables **Config Cascading**. Despite some edge cases the config file will be loaded automatically and **no** additional setup is required. If you don't intend to use Config Cascading, it's recommended to place `posthtml.config.js` in the **root** `./` of your project
7075

7176
```
@@ -157,6 +162,50 @@ If you want to use a custom parser e.g [SugarML](https://github.com/posthtml/sug
157162
}
158163
```
159164

165+
### `skipParse`
166+
167+
If you want to use disable parsing, you can pass it in under the `skipParse` key in the loader options
168+
169+
#### `{Boolean}`
170+
171+
**webpack.config.js**
172+
```js
173+
{
174+
loader: 'posthtml-loader',
175+
options: {
176+
skipParse: false
177+
}
178+
}
179+
```
180+
181+
### `Render`
182+
183+
If you want to use a custom render, you can pass it in under the `render` key in the loader options
184+
185+
#### `{String}`
186+
187+
**webpack.config.js**
188+
```js
189+
{
190+
loader: 'posthtml-loader',
191+
options: {
192+
render: 'posthtml-you-render'
193+
}
194+
}
195+
```
196+
197+
#### `{Function}`
198+
199+
**webpack.config.js**
200+
```js
201+
{
202+
loader: 'posthtml-loader',
203+
options: {
204+
parser: require('posthtml-you-render')()
205+
}
206+
}
207+
```
208+
160209
### `Plugins`
161210

162211
Plugins are specified under the `plugins` key in the loader options
@@ -191,6 +240,38 @@ Plugins are specified under the `plugins` key in the loader options
191240
}
192241
```
193242

243+
### `Sync`
244+
245+
Enables sync mode, plugins will run synchronously, throws an error when used with async plugins
246+
247+
#### `{Boolean}`
248+
249+
**webpack.config.js**
250+
```js
251+
{
252+
loader: 'posthtml-loader',
253+
options: {
254+
sync: true
255+
}
256+
}
257+
```
258+
259+
### `Directives`
260+
261+
If you want to use a custom directives, you can pass it in under the `directives` key in the loader options
262+
263+
#### `{Array}`
264+
265+
**webpack.config.js**
266+
```js
267+
{
268+
loader: 'posthtml-loader',
269+
options: {
270+
directives: [{name: '?php', start: '<', end: '>'}]
271+
}
272+
}
273+
```
274+
194275
<h2 align="center">Maintainer</h2>
195276

196277
<table>
@@ -202,15 +283,6 @@ Plugins are specified under the `plugins` key in the loader options
202283
<br />
203284
<a href="https://github.com/michael-ciniawsky">Michael Ciniawsky</a>
204285
</td>
205-
</tr>
206-
<tbody>
207-
</table>
208-
209-
<h2 align="center">Contributors</h2>
210-
211-
<table>
212-
<tbody>
213-
<tr>
214286
<td align="center">
215287
<img width="150" height="150" src="https://github.com/Scrum.png?v=3&s=150">
216288
<br />

lib/index.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,9 @@ module.exports = function loader (html, map, meta) {
106106
options.parser = require(options.parser)()
107107
}
108108

109-
// TODO(michael-ciniawsky) enable if when custom renderer available
110-
// if (typeof options.render === 'string') {
111-
// options.render = require(options.render)()
112-
// }
109+
if (typeof options.render === 'string') {
110+
options.render = require(options.render)()
111+
}
113112

114113
return posthtml(plugins)
115114
.process(html, options)

lib/options.js

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,14 @@
11
'use strict'
22

33
module.exports = function parseOptions (params) {
4-
if (typeof params.plugins === 'function') {
5-
params.plugins = params.plugins.call(this, this)
6-
}
7-
8-
let plugins
9-
10-
if (typeof params.plugins === 'undefined') plugins = []
11-
else if (Array.isArray(params.plugins)) plugins = params.plugins
12-
else plugins = [params.plugins]
4+
let { plugins, ...options } = params
135

14-
const options = {}
15-
16-
if (typeof params !== 'undefined') {
17-
options.parser = params.parser
18-
// options.render = params.render
6+
if (typeof plugins === 'function') {
7+
plugins = plugins.call(this, this)
198
}
209

21-
return Promise.resolve({ options: options, plugins: plugins })
10+
if (typeof plugins === 'undefined') plugins = []
11+
else if (!Array.isArray(plugins)) plugins = [plugins]
12+
13+
return Promise.resolve({ options, plugins })
2214
}

lib/options.json

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,29 @@
11
{
22
"type": "object",
33
"properties": {
4+
"sync": {
5+
"type": "boolean"
6+
},
7+
"directives": {
8+
"type": "array",
9+
"items": {
10+
"type": "object",
11+
"properties": {
12+
"name": {
13+
"type": "string"
14+
},
15+
"start": {
16+
"type": "string"
17+
},
18+
"end": {
19+
"type": "string"
20+
}
21+
}
22+
}
23+
},
24+
"skipParse": {
25+
"type": "boolean"
26+
},
427
"ident": {
528
"type": "string"
629
},
@@ -23,6 +46,13 @@
2346
{ "instanceof": "Function" }
2447
]
2548
},
49+
"render": {
50+
"oneOf": [
51+
{ "type": "string" },
52+
{ "type": "object" },
53+
{ "instanceof": "Function" }
54+
]
55+
},
2656
"plugins": {
2757
"oneOf": [
2858
{ "type": "array" },

package.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
22
"name": "posthtml-loader",
33
"description": "PostHTML for Webpack",
4-
"version": "1.0.2",
4+
"version": "2.0.0",
55
"main": "lib/index.js",
66
"engines": {
7-
"node": ">= 8"
7+
"node": ">= 10"
88
},
99
"files": [
1010
"lib"
@@ -18,20 +18,20 @@
1818
"release": "standard-version"
1919
},
2020
"dependencies": {
21-
"loader-utils": "^1.1.0",
22-
"posthtml": "^0.12.0",
21+
"loader-utils": "^2.0.0",
22+
"posthtml": "^0.13.2",
2323
"posthtml-load-config": "^1.0.0",
2424
"schema-utils": "^2.5.0"
2525
},
2626
"devDependencies": {
2727
"coveralls": "^3.0.7",
2828
"del": "^5.1.0",
29-
"jest": "^24.9.0",
30-
"jsdoc-to-markdown": "^5.0.2",
29+
"jest": "^26.4.1",
30+
"jsdoc-to-markdown": "^6.0.1",
3131
"memory-fs": "^0.5.0",
3232
"posthtml-sugarml": "1.0.0-alpha3",
3333
"standard": "^14.3.1",
34-
"standard-version": "^8.0.1",
34+
"standard-version": "^9.0.0",
3535
"webpack": "^4.41.2"
3636
},
3737
"keywords": [

test/__snapshots__/Errors.test.js.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

33
exports[`Errors Validation Error 1`] = `
4-
"Invalid options object. PostHTML Loader has been initialised using an options object that does not match the API schema.
4+
"Invalid options object. PostHTML Loader has been initialized using an options object that does not match the API schema.
55
- options.plugins should be one of these:
66
[any, ...] | object {} | function
77
Details:
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`Loader Defaults 1`] = `
4+
"export default \`<section>Hello</section>
5+
\`"
6+
`;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<?php echo $myVar; ?>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import html from './fixture.html' // eslint-disable-line

0 commit comments

Comments
 (0)