autogen/autogen-core.js
function processNextAutogenBlock(autogenContext, allData, commentInfo, pos, callback) {

    //Update the position of the next block. If there isn't one, call the callback and break the recursion.
    pos = utils.regexIndexOf(allData, commentInfo.start, pos);

    if (pos == -1) {
        callback(allData);
        return;
    }

    //Extract the information from the autogen definition
    var matchInfo = commentInfo.start.exec(allData.substring(pos));

    //Skip over the start tag
    pos += matchInfo[0].length;

    //Get the data from the autogen tag
    var tagContent = matchInfo[1];
    var autogenTagData = utils.parseAutogenTag(tagContent);

    //Make file name in to a full path
    var filename = path.resolve(autogenContext.templateDir, autogenTagData.templateFileName + ".liquid");

    //Find the end of the line (and the start of content)
    //    Handle both styles of line endings
    var endOfAutogenLine = utils.regexIndexOf(allData, /[\r|\n]/, pos);
    var startBlock = utils.regexIndexOf(allData, /[\n]/, endOfAutogenLine) + 1;
    var endBlock = allData.indexOf(commentInfo.end, startBlock);

    //Prepare and load the required data
    var loadedLiquid = fs.readFileSync(filename);
    //Deep-copy the spec data so that we can add context
    var dataContext = utils.extend({}, autogenContext.specData);

    //Populate the autogen data context with property mappings from autogen tag
    for (var mappingIndex in autogenTagData.propertyMappings) {
        var propertyMapping = autogenTagData.propertyMappings[mappingIndex];

        var propValue = utils.getProp(dataContext, propertyMapping.sourceString);
        utils.setProp(dataContext, propertyMapping.destString, propValue);
    }

    //Populate the autogen data context with value mappings from autogen tag
    for (var mappingIndex in autogenTagData.valueMappings) {
        var valueMapping = autogenTagData.valueMappings[mappingIndex];

        utils.setProp(dataContext, valueMapping.destString, valueMapping.sourceString);
    }

    function insertTemplatedAndContinue(result) {
        //Replace the old contents of the output block with the result from the liquid engine
        var newData =
            allData.substring(0, startBlock)
            + result
            + os.EOL
            + allData.substring(endBlock);

        //Start/continue the recursion, and update the position for the next iteration
        processNextAutogenBlock(autogenContext, newData, commentInfo,
            startBlock
            + result.length
            + os.EOL.length
            + commentInfo.end.length, callback);
    }

    if (autogenContext.clearTemplatedSections)
        insertTemplatedAndContinue('');
    else {
        //Parse and render the liquid using the spec data
        autogenContext.liquidEngine
            .parseAndRender(loadedLiquid, dataContext)
            .then(insertTemplatedAndContinue);
    }
}
function processNextAutogenBlock(autogenContext, allData, commentInfo, pos, callback) {

    //Update the position of the next block. If there isn't one, call the callback and break the recursion.
    pos = utils.regexIndexOf(allData, commentInfo.start, pos);

    if (pos == -1) {
        callback(allData);
        return;
    }

    //Extract the information from the autogen definition
    var matchInfo = commentInfo.start.exec(allData.substring(pos));

    //Skip over the start tag
    pos += matchInfo[0].length;

    //Get the data from the autogen tag
    var tagContent = matchInfo[1];
    var autogenTagData = utils.parseAutogenTag(tagContent);

    //Make file name in to a full path
    var filename = path.resolve(autogenContext.templateDir, autogenTagData.templateFileName + ".liquid");

    //Find the end of the line (and the start of content)
    //    Handle both styles of line endings
    var endOfAutogenLine = utils.regexIndexOf(allData, /[\r|\n]/, pos);
    var startBlock = utils.regexIndexOf(allData, /[\n]/, endOfAutogenLine) + 1;
    var endBlock = allData.indexOf(commentInfo.end, startBlock);

    //Prepare and load the required data
    var loadedLiquid = fs.readFileSync(filename);
    //Deep-copy the spec data so that we can add context
    var dataContext = utils.extend({}, autogenContext.specData);

    //Populate the autogen data context with property mappings from autogen tag
    for (var mappingIndex in autogenTagData.propertyMappings) {
        var propertyMapping = autogenTagData.propertyMappings[mappingIndex];

        var propValue = utils.getProp(dataContext, propertyMapping.sourceString);
        utils.setProp(dataContext, propertyMapping.destString, propValue);
    }

    //Populate the autogen data context with value mappings from autogen tag
    for (var mappingIndex in autogenTagData.valueMappings) {
        var valueMapping = autogenTagData.valueMappings[mappingIndex];

        utils.setProp(dataContext, valueMapping.destString, valueMapping.sourceString);
    }

    function insertTemplatedAndContinue(result) {
        //Replace the old contents of the output block with the result from the liquid engine
        var newData =
            allData.substring(0, startBlock)
            + result
            + os.EOL
            + allData.substring(endBlock);

        //Start/continue the recursion, and update the position for the next iteration
        processNextAutogenBlock(autogenContext, newData, commentInfo,
            startBlock
            + result.length
            + os.EOL.length
            + commentInfo.end.length, callback);
    }

    if (autogenContext.clearTemplatedSections)
        insertTemplatedAndContinue('');
    else {
        //Parse and render the liquid using the spec data
        autogenContext.liquidEngine
            .parseAndRender(loadedLiquid, dataContext)
            .then(insertTemplatedAndContinue);
    }
}
function processNextAutogenBlock ( autogenContext , allData , commentInfo , pos , callback ) { //Update the position of the next block. If there isn't one, call the callback and break the recursion. pos = utils . regexIndexOf ( allData , commentInfo . start , pos ) ; if ( pos == - 1 ) { callback ( allData ) ; return ; } //Extract the information from the autogen definition var matchInfo = commentInfo . start . exec ( allData . substring ( pos ) ) ; //Skip over the start tag pos += matchInfo [ 0 ] . length ; //Get the data from the autogen tag var tagContent = matchInfo [ 1 ] ; var autogenTagData = utils . parseAutogenTag ( tagContent ) ; //Make file name in to a full path var filename = path . resolve ( autogenContext . templateDir , autogenTagData . templateFileName + ".liquid" ) ; //Find the end of the line (and the start of content) //    Handle both styles of line endings var endOfAutogenLine = utils . regexIndexOf ( allData , / [\r|\n] / , pos ) ; var startBlock = utils . regexIndexOf ( allData , / [\n] / , endOfAutogenLine ) + 1 ; var endBlock = allData . indexOf ( commentInfo . end , startBlock ) ; //Prepare and load the required data var loadedLiquid = fs . readFileSync ( filename ) ; //Deep-copy the spec data so that we can add context var dataContext = utils . extend ( { } , autogenContext . specData ) ; //Populate the autogen data context with property mappings from autogen tag for ( var mappingIndex in autogenTagData . propertyMappings ) { var propertyMapping = autogenTagData . propertyMappings [ mappingIndex ] ; var propValue = utils . getProp ( dataContext , propertyMapping . sourceString ) ; utils . setProp ( dataContext , propertyMapping . destString , propValue ) ; } //Populate the autogen data context with value mappings from autogen tag for ( var mappingIndex in autogenTagData . valueMappings ) { var valueMapping = autogenTagData . valueMappings [ mappingIndex ] ; utils . setProp ( dataContext , valueMapping . destString , valueMapping . sourceString ) ; } function insertTemplatedAndContinue ( result ) { //Replace the old contents of the output block with the result from the liquid engine var newData = allData . substring ( 0 , startBlock ) + result + os . EOL + allData . substring ( endBlock ) ; //Start/continue the recursion, and update the position for the next iteration processNextAutogenBlock ( autogenContext , newData , commentInfo , startBlock + result . length + os . EOL . length + commentInfo . end . length , callback ) ; } if ( autogenContext . clearTemplatedSections ) insertTemplatedAndContinue ( '' ) ; else { //Parse and render the liquid using the spec data autogenContext . liquidEngine . parseAndRender ( loadedLiquid , dataContext ) . then ( insertTemplatedAndContinue ) ; } }
Recursively updates the autogen blocks
Recursively updates the autogen blocks