@ -241,7 +241,7 @@
}
function makeConditionalRegex ( block ) {
return new RegExp ( "<!--[\\s]*IF " + block + "[\\s]*--> [\\s\\S]*<!--[\\s]*ENDIF " + block + "[\\s]*-->" , 'g' ) ;
return new RegExp ( "<!--[\\s]*IF " + block + "[\\s]*--> ( [\\s\\S]*?) <!--[\\s]*ENDIF " + block + "[\\s]*-->" , 'g' ) ;
}
function getBlock ( regex , block , template ) {
@ -311,25 +311,26 @@
} else {
function checkConditional ( key , value ) {
var conditional = makeConditionalRegex ( key ) ,
conditionalBlock = conditional . exec ( template ) ;
if ( conditionalBlock !== null ) {
conditionalBlock = conditionalBlock [ 0 ] . split ( /<!-- ELSE -->/ ) ;
if ( conditionalBlock [ 1 ] ) {
// there is an else statement
if ( ! value ) {
template = template . replace ( conditional , conditionalBlock [ 1 ] ) ;
matches = template . match ( conditional ) ;
if ( matches !== null ) {
for ( var i = 0 , ii = matches . length ; i < ii ; i ++ ) {
var conditionalBlock = matches [ i ] . split ( /<!-- ELSE -->/ ) ;
if ( conditionalBlock [ 1 ] ) {
// there is an else statement
if ( ! value ) {
template = template . replace ( matches [ i ] , conditionalBlock [ 1 ] ) ;
} else {
template = template . replace ( matches [ i ] , conditionalBlock [ 0 ] ) ;
}
} else {
template = template . replace ( conditional , conditionalBlock [ 0 ] ) ;
// regular if statement
if ( ! value ) {
template = template . replace ( matches [ i ] , '' ) ;
}
}
} else {
// regular if
if ( ! value ) {
template = template . replace ( conditional , '' ) ;
}
}
}
}
}
@ -341,7 +342,6 @@
checkConditional ( '@last' , blockInfo . iterator === blockInfo . total ) ;
}
template = replace ( namespace + d , data [ d ] , template ) ;
}
}