Skip to content

Commit 346ae05

Browse files
Fix attributes not string
1 parent f2c68f3 commit 346ae05

10 files changed

+44
-7
lines changed

changelog.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 1.0.0-beta.14 (2022-11-03)
2+
3+
* Fix node attributes not string
4+
15
## 1.0.0-beta.13 (2022-11-03)
26

37
* Remove attributes that have "undefined" or "null" value

docs-src/md/changelog.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 1.0.0-beta.14 (2022-11-03)
2+
3+
* Fix node attributes not string
4+
15
## 1.0.0-beta.13 (2022-11-03)
26

37
* Remove attributes that have "undefined" or "null" value

docs-src/pages/index.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ <h1 class="display-1 fw-bold mb-4">Build the web with PostHTML</h1>
1414
</div>
1515

1616
<p class="text-muted">
17-
Currently <strong>v1.0.0-beta.13</strong>
17+
Currently <strong>v1.0.0-beta.14</strong>
1818
<span class="px-1">·</span>
1919
<a href="#" class="link-secondary" data-bs-toggle="modal" data-bs-target="#modalWithComponents">Changelog</a>
2020
</p>

docs/demo.html

+7
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,13 @@ <h5 class="modal-title" id="modalWithComponentsLabel">Changelog</h5>
7777
</div>
7878
<!-- /.modal-header -->
7979
<div class="modal-body">
80+
<h2 id="1.0.0-beta.14-(2022-11-03)" tabindex="-1">
81+
<a class="header-anchor" href="#1.0.0-beta.14-(2022-11-03)">#</a>
82+
1.0.0-beta.14 (2022-11-03)
83+
</h2>
84+
<ul>
85+
<li>Fix node attributes not string</li>
86+
</ul>
8087
<h2 id="1.0.0-beta.13-(2022-11-03)" tabindex="-1">
8188
<a class="header-anchor" href="#1.0.0-beta.13-(2022-11-03)">#</a>
8289
1.0.0-beta.13 (2022-11-03)

docs/docs.html

+7
Original file line numberDiff line numberDiff line change
@@ -1488,6 +1488,13 @@ <h5 class="modal-title" id="modalWithComponentsLabel">Changelog</h5>
14881488
</div>
14891489
<!-- /.modal-header -->
14901490
<div class="modal-body">
1491+
<h2 id="1.0.0-beta.14-(2022-11-03)" tabindex="-1">
1492+
<a class="header-anchor" href="#1.0.0-beta.14-(2022-11-03)">#</a>
1493+
1.0.0-beta.14 (2022-11-03)
1494+
</h2>
1495+
<ul>
1496+
<li>Fix node attributes not string</li>
1497+
</ul>
14911498
<h2 id="1.0.0-beta.13-(2022-11-03)" tabindex="-1">
14921499
<a class="header-anchor" href="#1.0.0-beta.13-(2022-11-03)">#</a>
14931500
1.0.0-beta.13 (2022-11-03)

docs/index.html

+8-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ <h1 class="display-1 fw-bold mb-4">Build the web with PostHTML</h1>
5959
</div>
6060
<p class="text-muted">
6161
Currently
62-
<strong>v1.0.0-beta.13</strong>
62+
<strong>v1.0.0-beta.14</strong>
6363
<span class="px-1">·</span>
6464
<a href="#" class="link-secondary" data-bs-toggle="modal" data-bs-target="#modalWithComponents">Changelog</a>
6565
</p>
@@ -93,6 +93,13 @@ <h5 class="modal-title" id="modalWithComponentsLabel">Changelog</h5>
9393
</div>
9494
<!-- /.modal-header -->
9595
<div class="modal-body">
96+
<h2 id="1.0.0-beta.14-(2022-11-03)" tabindex="-1">
97+
<a class="header-anchor" href="#1.0.0-beta.14-(2022-11-03)">#</a>
98+
1.0.0-beta.14 (2022-11-03)
99+
</h2>
100+
<ul>
101+
<li>Fix node attributes not string</li>
102+
</ul>
96103
<h2 id="1.0.0-beta.13-(2022-11-03)" tabindex="-1">
97104
<a class="header-anchor" href="#1.0.0-beta.13-(2022-11-03)">#</a>
98105
1.0.0-beta.13 (2022-11-03)

docs/test.html

+8-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
<div class="col-lg-8">
4949
<h1 class="display-1 fw-bold mb-4">Playground</h1>
5050
<div class="wrapper">
51-
<div class="demo my-demo" computed:acomputed="" something="alocal">
51+
<div class="demo my-demo" computed:acomputed="true" something="alocal">
5252
{"title":"PostHTML Components","close":true,"$slots":{},"aStringOverride":"My override string changed","anObjectOverride":{"third":"Third override item","fourth":"Fourth override item"},"computed:aComputed":true,"class":"my-demo","anObjectMerged":{"third":"Third merged item","fourth":"Fourth merged item","anObjectMerged1":{"third":"Third merged item (UPDATED?)","fourth1":"Fourth merged item"}},"post":{"title":"My post title","body":"My post body","comments":[{"id":1,"body":"My comment 1 new"},{"id":3,"body":"My comment 3"}]},"anArrayOfObjects":[{"id":1,"title":"My new title 1"},{"id":2,"title":"My new title 2","somethingnew":"New"}],"anArray":["first","third","fourth","ten"],"something":"alocal"}
5353
<div>
5454
<a href="/my-page.html">
@@ -221,6 +221,13 @@ <h5 class="modal-title" id="modalWithComponentsLabel">Changelog</h5>
221221
</div>
222222
<!-- /.modal-header -->
223223
<div class="modal-body">
224+
<h2 id="1.0.0-beta.14-(2022-11-03)" tabindex="-1">
225+
<a class="header-anchor" href="#1.0.0-beta.14-(2022-11-03)">#</a>
226+
1.0.0-beta.14 (2022-11-03)
227+
</h2>
228+
<ul>
229+
<li>Fix node attributes not string</li>
230+
</ul>
224231
<h2 id="1.0.0-beta.13-(2022-11-03)" tabindex="-1">
225232
<a class="header-anchor" href="#1.0.0-beta.13-(2022-11-03)">#</a>
226233
1.0.0-beta.13 (2022-11-03)

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "posthtml-component",
3-
"version": "1.0.0-beta.13",
3+
"version": "1.0.0-beta.14",
44
"description": "PostHTML Components Blade-like with slots, attributes as props and custom tag",
55
"license": "MIT",
66
"repository": "thewebartisan7/posthtml-components",

src/process-attributes.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const union = require('lodash/union');
99
const each = require('lodash/each');
1010
const has = require('lodash/has');
1111
const extend = require('lodash/extend');
12+
const isString = require('lodash/isString');
1213
const isObject = require('lodash/isObject');
1314

1415
/**
@@ -66,7 +67,7 @@ module.exports = (currentNode, attributes, props, options) => {
6667
each(nodeAttrs, (value, key) => {
6768
if (['undefined', 'null'].includes(value)) {
6869
delete nodeAttrs[key];
69-
} else if (!isObject(nodeAttrs[key])) {
70+
} else if (key !== 'compose' && !isObject(nodeAttrs[key]) && !isString(nodeAttrs[key])) {
7071
nodeAttrs[key] = nodeAttrs[key].toString();
7172
}
7273
});

test/test-attributes.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ test('Must override class and style attributes', async t => {
5151
});
5252

5353
test('Must remove an attributes that has "undefined" or "null" value', async t => {
54-
const actual = `<component src="components/remove-attributes.html">My button</component>`;
55-
const expected = `<button class="btn btn-primary" data-bs-dismiss="true" data-bs-backdrop="false">My button</button>`;
54+
const actual = `<component src="components/remove-attributes.html" tabindex="-1">My button</component>`;
55+
const expected = `<button class="btn btn-primary" data-bs-dismiss="true" data-bs-backdrop="false" tabindex="-1">My button</button>`;
5656

5757
const html = await posthtml([plugin({root: './test/templates', tag: 'component'})]).process(actual).then(result => clean(result.html));
5858

0 commit comments

Comments
 (0)