mirror of
https://github.com/marko-js/marko.git
synced 2025-12-08 19:26:05 +00:00
Fixes #267 - Shorthand CSS class name cannot be combined with object/array class names
This commit is contained in:
parent
2b4310a03d
commit
c6bb49d554
@ -35,14 +35,32 @@ function notEmpty(o) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
function classListArray(classList) {
|
function classListHelper(arg, classNames) {
|
||||||
|
var len;
|
||||||
|
|
||||||
|
if (arg) {
|
||||||
|
if (typeof arg === 'string') {
|
||||||
|
classNames.push(arg);
|
||||||
|
} else if (typeof (len = arg.length) === 'number') {
|
||||||
|
for (var i=0; i<len; i++) {
|
||||||
|
classListHelper(arg[i], classNames);
|
||||||
|
}
|
||||||
|
} else if (typeof arg === 'object') {
|
||||||
|
for (var name in arg) {
|
||||||
|
if (arg.hasOwnProperty(name)) {
|
||||||
|
var value = arg[name];
|
||||||
|
if (value) {
|
||||||
|
classNames.push(name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function classList(classList) {
|
||||||
var classNames = [];
|
var classNames = [];
|
||||||
for (var i=0, len=classList.length; i<len; i++) {
|
classListHelper(classList, classNames);
|
||||||
var cur = classList[i];
|
|
||||||
if (cur) {
|
|
||||||
classNames.push(cur);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return classNames.join(' ');
|
return classNames.join(' ');
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -247,21 +265,8 @@ module.exports = {
|
|||||||
|
|
||||||
if (typeof classNames === 'string') {
|
if (typeof classNames === 'string') {
|
||||||
return attr(CLASS_ATTR, classNames, false);
|
return attr(CLASS_ATTR, classNames, false);
|
||||||
} else if (isArray(classNames)) {
|
|
||||||
return attr(CLASS_ATTR, classListArray(classNames), false);
|
|
||||||
} else if (typeof classNames === 'object') {
|
|
||||||
var classList = [];
|
|
||||||
for (var name in classNames) {
|
|
||||||
if (classNames.hasOwnProperty(name)) {
|
|
||||||
var value = classNames[name];
|
|
||||||
if (value) {
|
|
||||||
classList.push(name);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return attr(CLASS_ATTR, classListArray(classList), false);
|
|
||||||
} else {
|
} else {
|
||||||
return '';
|
return attr(CLASS_ATTR, classList(classNames), false);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -361,6 +366,6 @@ module.exports = {
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
cl: function() {
|
cl: function() {
|
||||||
return classListArray(arguments);
|
return classList(arguments);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
1
test/fixtures/render/autotest/shorthand-class-plus-class-obj/expected.html
vendored
Normal file
1
test/fixtures/render/autotest/shorthand-class-plus-class-obj/expected.html
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
<div class="foo bar"></div>
|
||||||
1
test/fixtures/render/autotest/shorthand-class-plus-class-obj/template.marko
vendored
Normal file
1
test/fixtures/render/autotest/shorthand-class-plus-class-obj/template.marko
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
div.foo class={bar: true, baz: false}
|
||||||
3
test/fixtures/render/autotest/shorthand-class-plus-class-obj/test.js
vendored
Normal file
3
test/fixtures/render/autotest/shorthand-class-plus-class-obj/test.js
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
exports.templateData = {
|
||||||
|
name: 'Marko'
|
||||||
|
};
|
||||||
Loading…
x
Reference in New Issue
Block a user