Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support and test for style attributes that are strings instead … #27

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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