Fixed support for using native for loops

This commit is contained in:
Patrick Steele-Idem 2015-02-04 17:26:18 -07:00
parent df86ec83ae
commit 2ac6d56a8e
4 changed files with 19 additions and 6 deletions

View File

@ -44,7 +44,7 @@ function parseForEach(value) {
'in': match[2]
};
} else if ((match = value.match(forEachPropRegEx))) {
return {
'nameVar': match[1],
@ -103,9 +103,9 @@ function parseForEach(value) {
step = -1;
}
} else {
step = 1;
step = 1;
}
}
return {
@ -146,8 +146,8 @@ ForNode.prototype = {
if (parts.hasOwnProperty('from')) {
// This is a range loop
var nameVar = parts.nameVar;
var from = parts.from;
var to = parts.to;
@ -234,7 +234,9 @@ ForNode.prototype = {
}
}, this).line('});');
} else {
if (this.getProperty('forLoop') === true) {
var forLoopProp = this.getProperty('forLoop');
if (forLoopProp && forLoopProp.toString() === 'true') {
forEachParams = [
'__array',
'__index',

View File

@ -159,6 +159,10 @@ describe('marko/marko' , function() {
testRender("test-project/html-templates/looping.marko", {}, done);
});
it.only("should allow for looping (native for-loop)", function(done) {
testRender("test-project/html-templates/looping-native-for-loop.marko", {}, done);
});
it("should allow for looping over properties", function(done) {
testRender("test-project/html-templates/looping-props.marko", {}, done);
});

View File

@ -0,0 +1,6 @@
<for each="item in ['a', 'b', 'c']" for-loop="true">
${item}
</for>
<div for="item in ['red', 'green', 'blue']; for-loop=true" >
${item}
</div>

View File

@ -0,0 +1 @@
abc<div>red</div><div>green</div><div>blue</div>