Skip to content

Commit

Permalink
feat: allow html-attributes in addition to attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
buschtoens committed Oct 5, 2017
1 parent da2af96 commit 4242a8c
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions lib/component-attributes-transform.js
Expand Up @@ -3,12 +3,14 @@

/*
```hbs
{{my-component (html-attributes data-qux="quax" class="horse" id="pony")}}
{{my-component (attributes data-foo="bar" class="cat" id="dog")}}
```
becomes
```hbs
{{my-component class="horse" id="pony" __HTML_ATTRIBUTES__=(hash data-qux="quax") }}
{{my-component class="cat" id="dog" __HTML_ATTRIBUTES__=(hash data-foo="bar") }}
```
*/
Expand All @@ -30,7 +32,7 @@ AttributesExpressionTransform.prototype.transform = function(ast) {
});

function transform(curly) {
if (hasAttributesExpression(curly)) {
if (hasHTMLAttributesExpression(curly)) {
let attributes = curly.params.pop();

let pairs = attributes.hash.pairs;
Expand Down Expand Up @@ -65,10 +67,13 @@ AttributesExpressionTransform.prototype.transform = function(ast) {
}
}

function hasAttributesExpression(curly) {
function hasHTMLAttributesExpression(curly) {
if (curly.params.length > 0) {
let last = curly.params[curly.params.length - 1];
if (last.type === "SubExpression" && last.path.original === "attributes") {
if (
last.type === "SubExpression" &&
(last.path.original === "html-attributes" || last.path.original === "attributes")
) {
return true;
}
}
Expand Down

0 comments on commit 4242a8c

Please sign in to comment.