posthtml-component 1.0.0-beta.1 → 1.0.0-beta.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/changelog.md +2 -47
- package/package.json +2 -2
- package/readme.md +1 -1
- package/src/index.js +15 -3
- package/test/templates/components/component-with-include.html +1 -0
- package/test/templates/components/component-with-module.html +1 -0
- package/test/templates/components/included-file.html +1 -0
- package/test/test-plugins.js +23 -4
package/changelog.md
CHANGED
|
@@ -1,48 +1,3 @@
|
|
|
1
|
-
## 1.0.0-beta.
|
|
2
|
-
|
|
3
|
-
* Added examples ([60a86fd](https://github.com/thewebartisan7/posthtml-components/commit/60a86fd))
|
|
4
|
-
* Added support for works with the same extends and modules syntax together with x-tag for easy migrat ([d5f665e](https://github.com/thewebartisan7/posthtml-components/commit/d5f665e))
|
|
5
|
-
* Allow to check if slot is defined via slots locals ([05582e6](https://github.com/thewebartisan7/posthtml-components/commit/05582e6))
|
|
6
|
-
* Apply expressions to initial tree and set nextNode after expression process ([112ccde](https://github.com/thewebartisan7/posthtml-components/commit/112ccde))
|
|
7
|
-
* Aware locals ([c78d53b](https://github.com/thewebartisan7/posthtml-components/commit/c78d53b))
|
|
8
|
-
* Before new ([4dc77d7](https://github.com/thewebartisan7/posthtml-components/commit/4dc77d7))
|
|
9
|
-
* Build examples script ([8fedbcc](https://github.com/thewebartisan7/posthtml-components/commit/8fedbcc))
|
|
10
|
-
* Check shorthand block name ([d87b379](https://github.com/thewebartisan7/posthtml-components/commit/d87b379))
|
|
11
|
-
* Cleaner find-path.js and more readme about namespace ([e15411d](https://github.com/thewebartisan7/posthtml-components/commit/e15411d))
|
|
12
|
-
* Complete refactor WIP ([45f00f5](https://github.com/thewebartisan7/posthtml-components/commit/45f00f5))
|
|
13
|
-
* Computed attributes ([049f153](https://github.com/thewebartisan7/posthtml-components/commit/049f153))
|
|
14
|
-
* Default slots without slot ([3fe6368](https://github.com/thewebartisan7/posthtml-components/commit/3fe6368))
|
|
15
|
-
* Examples site and docs ([9b853e6](https://github.com/thewebartisan7/posthtml-components/commit/9b853e6))
|
|
16
|
-
* Fix and enhance parseLocals ([b89c90a](https://github.com/thewebartisan7/posthtml-components/commit/b89c90a))
|
|
17
|
-
* Fix hardcoded slot tag name ([6f83229](https://github.com/thewebartisan7/posthtml-components/commit/6f83229))
|
|
18
|
-
* Fix merge attributes ([da41fdb](https://github.com/thewebartisan7/posthtml-components/commit/da41fdb))
|
|
19
|
-
* Fix parse attributes ([8321415](https://github.com/thewebartisan7/posthtml-components/commit/8321415))
|
|
20
|
-
* Fix tests ([252aa45](https://github.com/thewebartisan7/posthtml-components/commit/252aa45))
|
|
21
|
-
* Fix typo readme ([03f2e2f](https://github.com/thewebartisan7/posthtml-components/commit/03f2e2f))
|
|
22
|
-
* Initial commit ([ec6eae5](https://github.com/thewebartisan7/posthtml-components/commit/ec6eae5))
|
|
23
|
-
* More readme ([b5d9f86](https://github.com/thewebartisan7/posthtml-components/commit/b5d9f86))
|
|
24
|
-
* More readme ([2201df2](https://github.com/thewebartisan7/posthtml-components/commit/2201df2))
|
|
25
|
-
* More tests ([5ebaee4](https://github.com/thewebartisan7/posthtml-components/commit/5ebaee4))
|
|
26
|
-
* More tests ([2163943](https://github.com/thewebartisan7/posthtml-components/commit/2163943))
|
|
27
|
-
* Nested component tested ([8a1d117](https://github.com/thewebartisan7/posthtml-components/commit/8a1d117))
|
|
28
|
-
* Nested testing ([44a6154](https://github.com/thewebartisan7/posthtml-components/commit/44a6154))
|
|
29
|
-
* Push once and prepend ([1cfe598](https://github.com/thewebartisan7/posthtml-components/commit/1cfe598))
|
|
30
|
-
* Readme ([96ff607](https://github.com/thewebartisan7/posthtml-components/commit/96ff607))
|
|
31
|
-
* Readme ([4c8e4b8](https://github.com/thewebartisan7/posthtml-components/commit/4c8e4b8))
|
|
32
|
-
* Readme ([5e7b754](https://github.com/thewebartisan7/posthtml-components/commit/5e7b754))
|
|
33
|
-
* Readme update ([c02a781](https://github.com/thewebartisan7/posthtml-components/commit/c02a781))
|
|
34
|
-
* Readme update ([66a6213](https://github.com/thewebartisan7/posthtml-components/commit/66a6213))
|
|
35
|
-
* Readme update ([6ccf1ab](https://github.com/thewebartisan7/posthtml-components/commit/6ccf1ab))
|
|
36
|
-
* Readme updated ([3c5ac7e](https://github.com/thewebartisan7/posthtml-components/commit/3c5ac7e))
|
|
37
|
-
* Remove comments ([9f4216f](https://github.com/thewebartisan7/posthtml-components/commit/9f4216f))
|
|
38
|
-
* Shorthands slot names and other enhancements ([a091cc2](https://github.com/thewebartisan7/posthtml-components/commit/a091cc2))
|
|
39
|
-
* Slot is fill and fill is slot ([fc4283c](https://github.com/thewebartisan7/posthtml-components/commit/fc4283c))
|
|
40
|
-
* Slot locals ([6d4b3dc](https://github.com/thewebartisan7/posthtml-components/commit/6d4b3dc))
|
|
41
|
-
* Split in multiple files ([9f660c7](https://github.com/thewebartisan7/posthtml-components/commit/9f660c7))
|
|
42
|
-
* Unique default slot name from filename ([25259ef](https://github.com/thewebartisan7/posthtml-components/commit/25259ef))
|
|
43
|
-
* update ([827fe7f](https://github.com/thewebartisan7/posthtml-components/commit/827fe7f))
|
|
44
|
-
* Update readme ([19ef893](https://github.com/thewebartisan7/posthtml-components/commit/19ef893))
|
|
45
|
-
* Update readme ([42fa034](https://github.com/thewebartisan7/posthtml-components/commit/42fa034))
|
|
46
|
-
|
|
47
|
-
|
|
1
|
+
## 1.0.0-beta.2 (2022-10-20)
|
|
48
2
|
|
|
3
|
+
* First beta release
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "posthtml-component",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.3",
|
|
4
4
|
"description": "PostHTML Components Blade-like with slots, attributes as props and custom tag",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": "thewebartisan7/posthtml-components",
|
|
@@ -26,7 +26,6 @@
|
|
|
26
26
|
"deepmerge": "^4.2.2",
|
|
27
27
|
"posthtml-attrs-parser": "^0.1.1",
|
|
28
28
|
"posthtml-expressions": "^1.9.0",
|
|
29
|
-
"posthtml-match-helper": "^1.0.3",
|
|
30
29
|
"posthtml-parser": "^0.11.0",
|
|
31
30
|
"posthtml-render": "^3.0.0",
|
|
32
31
|
"style-to-object": "^0.3.0"
|
|
@@ -46,6 +45,7 @@
|
|
|
46
45
|
"markdown-it-toc-done-right": "^4.2.0",
|
|
47
46
|
"posthtml": "^0.16.6",
|
|
48
47
|
"posthtml-beautify": "^0.7.0",
|
|
48
|
+
"posthtml-include": "^1.7.4",
|
|
49
49
|
"posthtml-markdownit": "^1.3.0",
|
|
50
50
|
"xo": "^0.37.1"
|
|
51
51
|
}
|
package/readme.md
CHANGED
package/src/index.js
CHANGED
|
@@ -65,9 +65,6 @@ module.exports = (options = {}) => tree => {
|
|
|
65
65
|
}
|
|
66
66
|
|
|
67
67
|
options.roots = Array.isArray(options.folders) ? options.folders : [options.folders];
|
|
68
|
-
// options.roots.forEach((root, index) => {
|
|
69
|
-
// options.roots[index] = path.resolve(options.root, root);
|
|
70
|
-
// });
|
|
71
68
|
options.namespaces = Array.isArray(options.namespaces) ? options.namespaces : [options.namespaces];
|
|
72
69
|
options.namespaces.forEach((namespace, index) => {
|
|
73
70
|
options.namespaces[index].root = path.resolve(namespace.root);
|
|
@@ -109,6 +106,10 @@ function processTree(options) {
|
|
|
109
106
|
let processCounter = 0;
|
|
110
107
|
|
|
111
108
|
return function (tree) {
|
|
109
|
+
if (options.plugins.length > 0) {
|
|
110
|
+
tree = applyPluginsToTree(tree, options.plugins);
|
|
111
|
+
}
|
|
112
|
+
|
|
112
113
|
match.call(tree, options.matcher, currentNode => {
|
|
113
114
|
if (!currentNode.attrs) {
|
|
114
115
|
currentNode.attrs = {};
|
|
@@ -149,6 +150,10 @@ function processTree(options) {
|
|
|
149
150
|
// const plugins = [...options.plugins, expressions(options.expressions)];
|
|
150
151
|
nextNode = expressions(options.expressions)(nextNode);
|
|
151
152
|
|
|
153
|
+
if (options.plugins.length > 0) {
|
|
154
|
+
nextNode = applyPluginsToTree(nextNode, options.plugins);
|
|
155
|
+
}
|
|
156
|
+
|
|
152
157
|
// Process <yield> tag
|
|
153
158
|
const content = match.call(nextNode, {tag: options.yield}, nextNode => {
|
|
154
159
|
// Fill <yield> with current node content or default <yield> content or empty
|
|
@@ -183,3 +188,10 @@ function processTree(options) {
|
|
|
183
188
|
return tree;
|
|
184
189
|
};
|
|
185
190
|
}
|
|
191
|
+
|
|
192
|
+
function applyPluginsToTree(tree, plugins) {
|
|
193
|
+
return plugins.reduce((tree, plugin) => {
|
|
194
|
+
tree = plugin(tree);
|
|
195
|
+
return tree;
|
|
196
|
+
}, tree);
|
|
197
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<div><include src="components/included-file.html"></include></div>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<module href="/components/module.html"><p>Module file</p></module>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<p>Included file</p>
|
package/test/test-plugins.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
const test = require('ava');
|
|
4
|
+
const plugin = require('../src');
|
|
5
|
+
const posthtml = require('posthtml');
|
|
6
|
+
const clean = html => html.replace(/(\n|\t)/g, '').trim();
|
|
7
7
|
|
|
8
8
|
// test('Must work with posthtml-extend syntax', async t => {
|
|
9
9
|
// const actual = `<extends src="layouts/extend.html"><block name="content">My Content</block></extends>`;
|
|
@@ -31,3 +31,22 @@
|
|
|
31
31
|
//
|
|
32
32
|
// t.is(html, expected);
|
|
33
33
|
// });
|
|
34
|
+
|
|
35
|
+
test('Must include file using posthtml-include', async t => {
|
|
36
|
+
const actual = `<component src="components/component-with-include.html"></component>`;
|
|
37
|
+
const expected = `<div><p>Included file</p></div>`;
|
|
38
|
+
|
|
39
|
+
const html = await posthtml([plugin({root: './test/templates', tag: 'component', attribute: 'src', plugins: [require('posthtml-include')({root: './test/templates', encoding: 'utf8'})]})]).process(actual).then(result => clean(result.html));
|
|
40
|
+
|
|
41
|
+
t.is(html, expected);
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
// Unfortunately it's not working
|
|
45
|
+
// test('Must include file using posthtml-modules', async t => {
|
|
46
|
+
// const actual = `<component src="components/component-with-module.html"></component>`;
|
|
47
|
+
// const expected = `<div><p>Module file</p></div>`;
|
|
48
|
+
//
|
|
49
|
+
// const html = await posthtml([plugin({root: './test/templates', tag: 'component', attribute: 'src', plugins: [require('posthtml-modules')({root: './test/templates'})]})]).process(actual).then(result => clean(result.html));
|
|
50
|
+
//
|
|
51
|
+
// t.is(html, expected);
|
|
52
|
+
// });
|