Skip to content

Commit

Permalink
Added support and test for style attributes that are strings instead …
Browse files Browse the repository at this point in the history
…of objects
  • Loading branch information
virtualpatterns committed Jan 23, 2017
1 parent 6999583 commit 632d759
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
2 changes: 1 addition & 1 deletion create-attribute.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,4 @@ function memoizeString(callback) {
return cache[string] = callback.call(this, string);
}
};
}
}
14 changes: 9 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,16 @@ function openTag(node) {
}

if (name == 'style') {
var css = '';
value = extend({}, value);
for (var styleProp in value) {
css += paramCase(styleProp) + ': ' + value[styleProp] + '; ';
if (typeof value === 'string') {
// do nothing, string style values are good as-is
} else {
var css = '';
value = extend({}, value);
for (var styleProp in value) {
css += paramCase(styleProp) + ': ' + value[styleProp] + '; ';
}
value = css.trim();
}
value = css.trim();
}

if (value instanceof softHook || value instanceof attrHook) {
Expand Down
11 changes: 9 additions & 2 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ describe('toHTML()', function () {
assert.equal(toHTML(node), '<web-component></web-component>');
});

it('should render CSS for style property', function () {
it('should render CSS for style property (if not a string)', function () {
var node = new VNode('div', {
style: {
background: 'black',
Expand All @@ -66,7 +66,14 @@ describe('toHTML()', function () {
assert.equal(toHTML(node), '<div style="background: black; color: red;"></div>');
});

it('should convert style property to param-case', function () {
it('should render CSS for style property (if a string)', function () {
var node = new VNode('div', {
style: 'background: black; color: red;'
});
assert.equal(toHTML(node), '<div style="background: black; color: red;"></div>');
});

it('should convert style property to param-case (if not a string)', function () {
var node = new VNode('div', {
style: {
background: 'black',
Expand Down

0 comments on commit 632d759

Please sign in to comment.