posthtml-component 1.0.0-beta.4 → 1.0.0-beta.6
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/package.json +1 -1
- package/readme.md +1 -1
- package/src/index.js +28 -16
- package/src/slots.js +10 -10
- package/.c8rc +0 -3
- package/.clintonrc.json +0 -21
- package/.editorconfig +0 -19
- package/.huskyrc +0 -7
- package/.idea/posthtml-components.iml +0 -8
- package/.lintstagedrc +0 -4
- package/.nycrc +0 -4
- package/changelog.md +0 -13
- package/docs/docs.html +0 -1514
- package/docs/index.html +0 -136
- package/docs/test.html +0 -234
- package/test/templates/components/child.html +0 -41
- package/test/templates/components/component-append-prepend.html +0 -1
- package/test/templates/components/component-default-yield.html +0 -1
- package/test/templates/components/component-locals-json-and-string.html +0 -18
- package/test/templates/components/component-locals-type.html +0 -36
- package/test/templates/components/component-locals.html +0 -7
- package/test/templates/components/component-mapped-attributes.html +0 -7
- package/test/templates/components/component-mapped-attributes2.html +0 -7
- package/test/templates/components/component-mapped-attributes3.html +0 -7
- package/test/templates/components/component-multiple-slot.html +0 -1
- package/test/templates/components/component-with-include.html +0 -1
- package/test/templates/components/component-with-module.html +0 -1
- package/test/templates/components/component-without-elements.html +0 -1
- package/test/templates/components/component.html +0 -1
- package/test/templates/components/form/index.html +0 -1
- package/test/templates/components/included-file.html +0 -1
- package/test/templates/components/modal.html +0 -1
- package/test/templates/components/module-with-extend.html +0 -1
- package/test/templates/components/module.html +0 -1
- package/test/templates/components/nested-one-slot.html +0 -5
- package/test/templates/components/nested-one.html +0 -1
- package/test/templates/components/nested-three.html +0 -1
- package/test/templates/components/nested-two-slot.html +0 -5
- package/test/templates/components/nested-two.html +0 -1
- package/test/templates/components/parent.html +0 -42
- package/test/templates/components/script-locals.html +0 -9
- package/test/templates/custom/dark/components/button.html +0 -1
- package/test/templates/custom/dark/components/label/index.html +0 -1
- package/test/templates/dark/components/button.html +0 -1
- package/test/templates/dark/components/label/index.html +0 -1
- package/test/templates/dark/layouts/base.html +0 -1
- package/test/templates/layouts/base-locals.html +0 -6
- package/test/templates/layouts/base-render-slots-locals.html +0 -8
- package/test/templates/layouts/base.html +0 -8
- package/test/templates/layouts/extend-with-module.html +0 -7
- package/test/templates/layouts/extend.html +0 -7
- package/test/templates/layouts/playground.html +0 -1
- package/test/templates/layouts/slot-condition.html +0 -8
- package/test/templates/light/components/button.html +0 -1
- package/test/templates/light/layouts/base.html +0 -1
- package/test/test-attributes.js +0 -42
- package/test/test-errors.js +0 -60
- package/test/test-locals.js +0 -74
- package/test/test-nested.js +0 -24
- package/test/test-plugins.js +0 -52
- package/test/test-slots.js +0 -85
- package/test/test-x-tag.js +0 -69
- package/xo.config.js +0 -15
package/package.json
CHANGED
package/readme.md
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
<div align="center">
|
|
6
6
|
<img width="300" title="PostHTML" src="http://posthtml.github.io/posthtml/logo.svg">
|
|
7
7
|
<h1>PostHTML Components </h1>
|
|
8
|
-
<p>HTML-friendly syntax
|
|
8
|
+
<p>A PostHTML plugin for create components with HTML-friendly syntax inspired by Laravel Blade. Slots, stack/push, props, custom tag and much more.</p>
|
|
9
9
|
</div>
|
|
10
10
|
|
|
11
11
|
## Installation
|
package/src/index.js
CHANGED
|
@@ -103,7 +103,7 @@ module.exports = (options = {}) => tree => {
|
|
|
103
103
|
function processTree(options) {
|
|
104
104
|
const filledSlots = {};
|
|
105
105
|
|
|
106
|
-
|
|
106
|
+
let processCounter = 0;
|
|
107
107
|
|
|
108
108
|
return function (tree) {
|
|
109
109
|
if (options.plugins.length > 0) {
|
|
@@ -115,31 +115,21 @@ function processTree(options) {
|
|
|
115
115
|
currentNode.attrs = {};
|
|
116
116
|
}
|
|
117
117
|
|
|
118
|
-
const
|
|
118
|
+
const componentPath = getComponentPath(currentNode, options);
|
|
119
119
|
|
|
120
|
-
if (!
|
|
120
|
+
if (!componentPath) {
|
|
121
121
|
return currentNode;
|
|
122
122
|
}
|
|
123
123
|
|
|
124
|
-
|
|
125
|
-
componentFile :
|
|
126
|
-
path.join(options.root, componentFile);
|
|
127
|
-
|
|
128
|
-
// Check if file exist only when not using x-tag
|
|
129
|
-
if (currentNode.attrs[options.attribute] && !existsSync(componentPath)) {
|
|
130
|
-
if (options.strict) {
|
|
131
|
-
throw new Error(`[components] The component was not found in ${componentPath}.`);
|
|
132
|
-
} else {
|
|
133
|
-
return currentNode;
|
|
134
|
-
}
|
|
135
|
-
}
|
|
124
|
+
console.log(`${++processCounter}) Processing component ${componentPath}`);
|
|
136
125
|
|
|
137
|
-
//
|
|
126
|
+
// log(currentNode, 'currentNode');
|
|
138
127
|
|
|
139
128
|
let nextNode = parser(readFileSync(componentPath, 'utf8'));
|
|
140
129
|
|
|
141
130
|
// Set filled slots
|
|
142
131
|
setFilledSlots(currentNode, filledSlots, options);
|
|
132
|
+
// setFilledSlots(nextNode, filledSlots, options);
|
|
143
133
|
|
|
144
134
|
// Reset previous locals with passed global and keep aware locals
|
|
145
135
|
options.expressions.locals = {...options.locals, ...options.aware};
|
|
@@ -161,6 +151,8 @@ function processTree(options) {
|
|
|
161
151
|
return currentNode.content || nextNode.content;
|
|
162
152
|
});
|
|
163
153
|
|
|
154
|
+
nextNode = processTree(options)(nextNode);
|
|
155
|
+
|
|
164
156
|
// Process <fill> tags
|
|
165
157
|
processFillContent(nextNode, filledSlots, options);
|
|
166
158
|
|
|
@@ -190,6 +182,26 @@ function processTree(options) {
|
|
|
190
182
|
};
|
|
191
183
|
}
|
|
192
184
|
|
|
185
|
+
function getComponentPath(currentNode, options) {
|
|
186
|
+
const componentFile = currentNode.attrs[options.attribute];
|
|
187
|
+
|
|
188
|
+
if (componentFile) {
|
|
189
|
+
const componentPath = path.join(options.root, componentFile);
|
|
190
|
+
|
|
191
|
+
if (!existsSync(componentPath)) {
|
|
192
|
+
if (options.strict) {
|
|
193
|
+
throw new Error(`[components] The component was not found in ${componentPath}.`);
|
|
194
|
+
} else {
|
|
195
|
+
return false;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
return componentPath;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
return findPathFromTag(currentNode.tag, options);
|
|
203
|
+
}
|
|
204
|
+
|
|
193
205
|
function applyPluginsToTree(tree, plugins) {
|
|
194
206
|
return plugins.reduce((tree, plugin) => {
|
|
195
207
|
tree = plugin(tree);
|
package/src/slots.js
CHANGED
|
@@ -21,7 +21,7 @@ function setFilledSlots(currentNode, filledSlots, {fill, slotSeparator}) {
|
|
|
21
21
|
|
|
22
22
|
const name = fillNode.tag.split(slotSeparator)[1];
|
|
23
23
|
|
|
24
|
-
const locals = omit(fillNode.attrs, [
|
|
24
|
+
const locals = omit(fillNode.attrs, ['append', 'prepend', 'aware']);
|
|
25
25
|
|
|
26
26
|
if (locals) {
|
|
27
27
|
each(locals, (value, key, attrs) => {
|
|
@@ -58,10 +58,6 @@ function processFillContent(tree, filledSlots, {fill, slotSeparator}) {
|
|
|
58
58
|
match.call(tree, {tag: fill}, fillNode => {
|
|
59
59
|
const name = fillNode.tag.split(slotSeparator)[1];
|
|
60
60
|
|
|
61
|
-
if (!filledSlots[name]) {
|
|
62
|
-
filledSlots[name] = {};
|
|
63
|
-
}
|
|
64
|
-
|
|
65
61
|
filledSlots[name].tag = fillNode.tag;
|
|
66
62
|
filledSlots[name].attrs = fillNode.attrs;
|
|
67
63
|
filledSlots[name].content = fillNode.content;
|
|
@@ -90,17 +86,21 @@ function processSlotContent(tree, filledSlots, {slot, slotSeparator}) {
|
|
|
90
86
|
|
|
91
87
|
slotNode.tag = false;
|
|
92
88
|
|
|
93
|
-
if (filledSlots[name]
|
|
89
|
+
if (!filledSlots[name]) {
|
|
90
|
+
return slotNode;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
if (filledSlots[name].rendered) {
|
|
94
94
|
slotNode.content = null;
|
|
95
|
-
} else if (slotNode.content && filledSlots[name]
|
|
96
|
-
slotNode.content = typeof filledSlots[name]
|
|
95
|
+
} else if (slotNode.content && filledSlots[name].attrs && (typeof filledSlots[name].attrs.append !== 'undefined' || typeof filledSlots[name].attrs.prepend !== 'undefined')) {
|
|
96
|
+
slotNode.content = typeof filledSlots[name].attrs.append === 'undefined' ? filledSlots[name].content.concat(slotNode.content) : slotNode.content.concat(filledSlots[name].content);
|
|
97
97
|
} else {
|
|
98
|
-
slotNode.content = filledSlots[name]
|
|
98
|
+
slotNode.content = filledSlots[name].content;
|
|
99
99
|
}
|
|
100
100
|
|
|
101
101
|
// Set rendered to true so a slot can be output only once,
|
|
102
102
|
// when not present "aware" attribute
|
|
103
|
-
if (filledSlots[name] && (!filledSlots[name]
|
|
103
|
+
if (filledSlots[name] && (!filledSlots[name].attrs || typeof filledSlots[name].attrs.aware === 'undefined')) {
|
|
104
104
|
filledSlots[name].rendered = true;
|
|
105
105
|
}
|
|
106
106
|
|
package/.c8rc
DELETED
package/.clintonrc.json
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"ignores": [
|
|
3
|
-
"test/**",
|
|
4
|
-
"tmp/**",
|
|
5
|
-
"src/**",
|
|
6
|
-
"lib/**",
|
|
7
|
-
"examples/**",
|
|
8
|
-
"docs/**",
|
|
9
|
-
".idea/**",
|
|
10
|
-
"*.{html,jpg}",
|
|
11
|
-
"cache.json"
|
|
12
|
-
],
|
|
13
|
-
"rules": {
|
|
14
|
-
"pkg-main": "off",
|
|
15
|
-
"cli": "off",
|
|
16
|
-
"xo": "off",
|
|
17
|
-
"ava": "off",
|
|
18
|
-
"use-travis": "off",
|
|
19
|
-
"pkg-schema": "off"
|
|
20
|
-
}
|
|
21
|
-
}
|
package/.editorconfig
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
root = true
|
|
2
|
-
|
|
3
|
-
[*]
|
|
4
|
-
indent_style = space
|
|
5
|
-
indent_size = 2
|
|
6
|
-
end_of_line = lf
|
|
7
|
-
charset = utf-8
|
|
8
|
-
quote_type = single
|
|
9
|
-
trim_trailing_whitespace = true
|
|
10
|
-
insert_final_newline = true
|
|
11
|
-
|
|
12
|
-
[{package.json,*.yml,*.jade,*.pss,*.css,*.js,*.md,.*,*.ts}]
|
|
13
|
-
indent_size = 2
|
|
14
|
-
|
|
15
|
-
[{changelog.md,.*}]
|
|
16
|
-
insert_final_newline = false
|
|
17
|
-
|
|
18
|
-
[*.md]
|
|
19
|
-
trim_trailing_whitespace = false
|
package/.huskyrc
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
-
<module type="WEB_MODULE" version="4">
|
|
3
|
-
<component name="NewModuleRootManager">
|
|
4
|
-
<content url="file://$MODULE_DIR$" />
|
|
5
|
-
<orderEntry type="inheritedJdk" />
|
|
6
|
-
<orderEntry type="sourceFolder" forTests="false" />
|
|
7
|
-
</component>
|
|
8
|
-
</module>
|
package/.lintstagedrc
DELETED
package/.nycrc
DELETED
package/changelog.md
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
## 1.0.0-beta.4 (2022-10-23)
|
|
2
|
-
|
|
3
|
-
* Refactor with underscore.js
|
|
4
|
-
* Optionally set attributes to any nodes not only the first one
|
|
5
|
-
* Added more docs
|
|
6
|
-
|
|
7
|
-
## 1.0.0-beta.3 (2022-10-21)
|
|
8
|
-
|
|
9
|
-
* Apply additional plugins to tree
|
|
10
|
-
|
|
11
|
-
## 1.0.0-beta.2 (2022-10-20)
|
|
12
|
-
|
|
13
|
-
* First beta release
|