hsp/compiler/jsgenerator/processors.js
function formatTextBlock (node, nextExprIndex, walker) {
    var content = node.content, item, exprArray = [], args = [], index = 0; // idx is the index in the $text array
                                                                                // (=args)
    for (var i = 0; i < content.length; i++) {
        item = content[i];
        if (item.type === "text") {
            if (index % 2 === 0) {
                // even index: arg must be a string
                args[index] = '"' + escapeNewLines(item.value.replace(/"/g, "\\\"")) + '"';
                index++;
            } else {
                // odd index: arg must be an expression - so add the text to the previous item
                if (index > 0) {
                    args[index - 1] = args[index - 1].slice(0, -1) + escapeNewLines(item.value.replace(/"/g, "\\\"")) + '"';
                } else {
                    // we should never get there as index is odd !
                    walker.logError("Invalid textblock structure", node);
                }
            }
        } else if (item.type === "expression") {
            if (index % 2 === 0) {
                // even index: arg must be a string
                args[index] = '""';
                index++;
            }
            var expr = formatExpression(item, nextExprIndex, walker);
            nextExprIndex = expr.nextIndex;
            if (expr.code) {
                if (expr.ast instanceof Array) {
                    //it is a multi-statement expression that is not allowed in this context
                    walker.logError("Invalid expression: " + item.value, item);
                    args[index] = 0; // invalid expression
                } else {
                    exprArray.push(expr.code);
                    args[index] = expr.exprIdx; // expression index
                }
            } else {
                args[index] = 0; // invalid expression
            }
            index++;
        }
    }

    return {
        exprArg : exprArray.length ? '{' + exprArray.join(",") + '}' : "0",
        nextIndex : nextExprIndex,
        blockArgs : args.length ? '[' + args.join(',') + ']' : "[]"
    };
}
function formatTextBlock (node, nextExprIndex, walker) {
    var content = node.content, item, exprArray = [], args = [], index = 0; // idx is the index in the $text array
                                                                                // (=args)
    for (var i = 0; i < content.length; i++) {
        item = content[i];
        if (item.type === "text") {
            if (index % 2 === 0) {
                // even index: arg must be a string
                args[index] = '"' + escapeNewLines(item.value.replace(/"/g, "\\\"")) + '"';
                index++;
            } else {
                // odd index: arg must be an expression - so add the text to the previous item
                if (index > 0) {
                    args[index - 1] = args[index - 1].slice(0, -1) + escapeNewLines(item.value.replace(/"/g, "\\\"")) + '"';
                } else {
                    // we should never get there as index is odd !
                    walker.logError("Invalid textblock structure", node);
                }
            }
        } else if (item.type === "expression") {
            if (index % 2 === 0) {
                // even index: arg must be a string
                args[index] = '""';
                index++;
            }
            var expr = formatExpression(item, nextExprIndex, walker);
            nextExprIndex = expr.nextIndex;
            if (expr.code) {
                if (expr.ast instanceof Array) {
                    //it is a multi-statement expression that is not allowed in this context
                    walker.logError("Invalid expression: " + item.value, item);
                    args[index] = 0; // invalid expression
                } else {
                    exprArray.push(expr.code);
                    args[index] = expr.exprIdx; // expression index
                }
            } else {
                args[index] = 0; // invalid expression
            }
            index++;
        }
    }

    return {
        exprArg : exprArray.length ? '{' + exprArray.join(",") + '}' : "0",
        nextIndex : nextExprIndex,
        blockArgs : args.length ? '[' + args.join(',') + ']' : "[]"
    };
}
function formatTextBlock ( node , nextExprIndex , walker ) { var content = node . content , item , exprArray = [ ] , args = [ ] , index = 0 ; // idx is the index in the $text array // (=args) for ( var i = 0 ; i < content . length ; i ++ ) { item = content [ i ] ; if ( item . type === "text" ) { if ( index % 2 === 0 ) { // even index: arg must be a string args [ index ] = '"' + escapeNewLines ( item . value . replace ( / " / g , "\\\"" ) ) + '"' ; index ++ ; } else { // odd index: arg must be an expression - so add the text to the previous item if ( index > 0 ) { args [ index - 1 ] = args [ index - 1 ] . slice ( 0 , - 1 ) + escapeNewLines ( item . value . replace ( / " / g , "\\\"" ) ) + '"' ; } else { // we should never get there as index is odd ! walker . logError ( "Invalid textblock structure" , node ) ; } } } else if ( item . type === "expression" ) { if ( index % 2 === 0 ) { // even index: arg must be a string args [ index ] = '""' ; index ++ ; } var expr = formatExpression ( item , nextExprIndex , walker ) ; nextExprIndex = expr . nextIndex ; if ( expr . code ) { if ( expr . ast instanceof Array ) { //it is a multi-statement expression that is not allowed in this context walker . logError ( "Invalid expression: " + item . value , item ) ; args [ index ] = 0 ; // invalid expression } else { exprArray . push ( expr . code ) ; args [ index ] = expr . exprIdx ; // expression index } } else { args [ index ] = 0 ; // invalid expression } index ++ ; } } return { exprArg : exprArray . length ? '{' + exprArray . join ( "," ) + '}' : "0" , nextIndex : nextExprIndex , blockArgs : args . length ? '[' + args . join ( ',' ) + ']' : "[]" } ; }
Format the textblock content for textblock and attribute nodes.
@param {Node} node the current Node object as built by the treebuilder.
@param {Integer} nextExprIndex the index of the next expression.
@param {TreeWalker} walker the template walker instance.
@return {Object} a snippet of Javascript code built from the node.
Format the textblock content for textblock and attribute nodes .