Skip to content

Commit d9dd85c

Browse files
authored
Merge pull request #100 from posthtml/milestone-1.5.0
Milestone 1.5.0
2 parents 2db3daa + 3e74fed commit d9dd85c

File tree

8 files changed

+116
-49
lines changed

8 files changed

+116
-49
lines changed

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
# [1.5.0](https://github.com/posthtml/posthtml-expressions/compare/v1.4.7...v1.5.0) (2020-09-21)
2+
3+
4+
### Features
5+
6+
* attribute as param, close [#99](https://github.com/posthtml/posthtml-expressions/issues/99) ([74c2b32](https://github.com/posthtml/posthtml-expressions/commit/74c2b3201f1492c4115e0e4b8f71e228f0e70370))
7+
8+
9+
110
## [1.4.7](https://github.com/posthtml/posthtml-expressions/compare/v1.4.6...v1.4.7) (2020-08-28)
211

312

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,17 +53,19 @@ You have full control over the delimiters used for injecting locals, as well as
5353
You can inject locals into any piece of content in your html templates, other than overwriting tag names. For example, if you passed the following config to the expressions plugin:
5454

5555
```js
56-
locals: { className: 'intro', name: 'Marlo' }
56+
locals: { className: 'intro', name: 'Marlo', 'status': 'checked' }
5757
```
5858

5959
```html
6060
<div class="{{ className }}">
61+
<input type="radio" {{ status }}>
6162
My name is {{ name }}
6263
</div>
6364
```
6465

6566
```html
6667
<div class="intro">
68+
<input type="radio" checked="">
6769
My name is Marlo
6870
</div>
6971
```

lib/index.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,13 @@ function walk (opts, nodes) {
200200
.replace(unescapeDelimitersReplace, delimitersSettings[0].text[0])
201201
.replace(delimitersReplace, delimitersSettings[1].text[0])
202202
}
203+
204+
// if key is parametr
205+
const _key = placeholders(key, ctx, delimitersSettings)
206+
if (key !== _key) {
207+
node.attrs[_key] = node.attrs[key]
208+
delete node.attrs[key]
209+
}
203210
}
204211
}
205212

package-lock.json

Lines changed: 88 additions & 45 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "posthtml-expressions",
3-
"version": "1.4.7",
3+
"version": "1.5.0",
44
"description": "Expressions Plugin for PostHTML",
55
"engines": {
66
"node": ">=10"
@@ -20,7 +20,7 @@
2020
"posthtml-render": "^1.2.3"
2121
},
2222
"devDependencies": {
23-
"ava": "^3.11.1",
23+
"ava": "^3.12.1",
2424
"coveralls": "^3.1.0",
2525
"jsdoc-to-markdown": "^6.0.1",
2626
"nyc": "^15.1.0",

test/expect/attr_param.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<input type="radio" checked="">

test/fixtures/attr_param.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<input type="radio" {{param}}/>

test/test-core.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,12 +90,16 @@ test('Boolean attribute', (t) => {
9090
return process(t, 'boolean_attr', null, false, [beautify(), expressions()])
9191
})
9292

93+
test('Attribute as param', (t) => {
94+
return process(t, 'attr_param', null, false, [beautify(), expressions({ locals: { param: 'checked' } })])
95+
})
96+
9397
test('Directives options', (t) => {
9498
return process(t, 'directives', null, false, [expressions()], {
9599
directives: [{
96100
name: '?php',
97101
start: '<',
98-
end: '>',
102+
end: '>'
99103
}]
100104
})
101105
})

0 commit comments

Comments
 (0)