Marko v3: Allow status-var to be quoted string or identifier

This commit is contained in:
Patrick Steele-Idem 2016-02-22 15:23:58 -07:00
parent 7890ec74ec
commit f3886a77cf
4 changed files with 11 additions and 2 deletions

View File

@ -297,9 +297,13 @@ module.exports = function(str) {
varName = buildIdentifier(varName, 'Invalid variable name');
}
if (statusVarName) {
statusVarName = buildIdentifier(statusVarName, 'Invalid status-var option');
statusVarName = compiler.builder.parseExpression(statusVarName);
if (statusVarName.type === 'Literal') {
statusVarName = compiler.builder.identifier(statusVarName.value);
} else if (statusVarName.type !== 'Identifier') {
throwError('Invalid status-var option');
}
}
if (forInit) {

View File

@ -0,0 +1 @@
<div>red - true - false - 0 - 3</div>, <div>green - false - false - 1 - 3</div>, <div>blue - false - true - 2 - 3</div>

View File

@ -0,0 +1,3 @@
<div for(item in ['red', 'green', 'blue'] | separator=', ' status-var="loop")>
${item} - ${loop.isFirst()} - ${loop.isLast()} - ${loop.getIndex()} - ${loop.getLength()}
</div>

View File

@ -0,0 +1 @@
exports.templateData = {};