lib/index.js
function innerRender(from, template, data, callback) {
    var args, proc, out = '',
        err = '',
        base,
        strData;

    if (arguments.length < 4) {
        callback = data;
        data = {};
    }

    if (!template || template.constructor !== String) {
        return callback(new Error('"template" requires a non-empty string'));
    }

    if ('function' !== typeof callback) {
        throw new Error('"callback" requires a function');
    }

    try {
        //Make sure mock data could be stringified
        strData = JSON.stringify(data);
    } catch (e) {
        return callback(e);
    }

    base = gConfigurations.template_dirs;
    //If no template_dirs defined and is rendering a file,
    //we reset the template_dirs to the dirname of the file,
    //and set template as its basename
    //
    //e.g,
    //
    //django.configure({
    //  template_dirs: null
    // });
    //django.renderFile('test/case/index.html');
    //
    //equals
    //
    //django.configure({
    //  template_dirs: 'test/case'
    // });
    //django.renderFile('index.html')
    //
    //That affects @include tag in Django,
    //see https://docs.djangoproject.com/en/1.7/ref/templates/builtins/#include
    //
    if (('file' === from) && !base) {

        base = path.resolve(path.dirname(template));
        template = path.basename(template);
    } 

    args = (('source' === from) ? [PYTHON] : [PYTHON, base, template]).map(function(item, idx) {
        return idx ? encodeURIComponent(item) : item;
    });

    proc = childProcess.spawn('python', args);
    //We use stdin to pass the mock data to avoid long shell arguments
    proc.stdin.write(('source' === from ? (encodeURIComponent(template) +
        '\n') : '') + strData + '\n'); //For python reading a line.

    proc.stdout.on('data', function(data) {
        //Here we get no string but buffer
        out += data.toString('utf-8');
    });
    proc.stderr.on('data', function(data) {
        err += data.toString('utf-8');
    });
    //What if blocked? We ignored it because this is not for production.
    proc.on('exit', function() {
        if (err) {
            return callback(new Error(err));
        } else {
            return callback(null, out.replace(/\r(?=\r\n)/mg, '')); //A \r will always be prepend to \r\n
        }
    });
}
function innerRender(from, template, data, callback) {
    var args, proc, out = '',
        err = '',
        base,
        strData;

    if (arguments.length < 4) {
        callback = data;
        data = {};
    }

    if (!template || template.constructor !== String) {
        return callback(new Error('"template" requires a non-empty string'));
    }

    if ('function' !== typeof callback) {
        throw new Error('"callback" requires a function');
    }

    try {
        //Make sure mock data could be stringified
        strData = JSON.stringify(data);
    } catch (e) {
        return callback(e);
    }

    base = gConfigurations.template_dirs;
    //If no template_dirs defined and is rendering a file,
    //we reset the template_dirs to the dirname of the file,
    //and set template as its basename
    //
    //e.g,
    //
    //django.configure({
    //  template_dirs: null
    // });
    //django.renderFile('test/case/index.html');
    //
    //equals
    //
    //django.configure({
    //  template_dirs: 'test/case'
    // });
    //django.renderFile('index.html')
    //
    //That affects @include tag in Django,
    //see https://docs.djangoproject.com/en/1.7/ref/templates/builtins/#include
    //
    if (('file' === from) && !base) {

        base = path.resolve(path.dirname(template));
        template = path.basename(template);
    } 

    args = (('source' === from) ? [PYTHON] : [PYTHON, base, template]).map(function(item, idx) {
        return idx ? encodeURIComponent(item) : item;
    });

    proc = childProcess.spawn('python', args);
    //We use stdin to pass the mock data to avoid long shell arguments
    proc.stdin.write(('source' === from ? (encodeURIComponent(template) +
        '\n') : '') + strData + '\n'); //For python reading a line.

    proc.stdout.on('data', function(data) {
        //Here we get no string but buffer
        out += data.toString('utf-8');
    });
    proc.stderr.on('data', function(data) {
        err += data.toString('utf-8');
    });
    //What if blocked? We ignored it because this is not for production.
    proc.on('exit', function() {
        if (err) {
            return callback(new Error(err));
        } else {
            return callback(null, out.replace(/\r(?=\r\n)/mg, '')); //A \r will always be prepend to \r\n
        }
    });
}
function innerRender ( from , template , data , callback ) { var args , proc , out = '' , err = '' , base , strData ; if ( arguments . length < 4 ) { callback = data ; data = { } ; } if ( ! template || template . constructor !== String ) { return callback ( new Error ( '"template" requires a non-empty string' ) ) ; } if ( 'function' !== typeof callback ) { throw new Error ( '"callback" requires a function' ) ; } try { //Make sure mock data could be stringified strData = JSON . stringify ( data ) ; } catch ( e ) { return callback ( e ) ; } base = gConfigurations . template_dirs ; //If no template_dirs defined and is rendering a file, //we reset the template_dirs to the dirname of the file, //and set template as its basename // //e.g, // //django.configure({ //  template_dirs: null // }); //django.renderFile('test/case/index.html'); // //equals // //django.configure({ //  template_dirs: 'test/case' // }); //django.renderFile('index.html') // //That affects @include tag in Django, //see https://docs.djangoproject.com/en/1.7/ref/templates/builtins/#include // if ( ( 'file' === from ) && ! base ) { base = path . resolve ( path . dirname ( template ) ) ; template = path . basename ( template ) ; } args = ( ( 'source' === from ) ? [ PYTHON ] : [ PYTHON , base , template ] ) . map ( function ( item , idx ) { return idx ? encodeURIComponent ( item ) : item ; } ) ; proc = childProcess . spawn ( 'python' , args ) ; //We use stdin to pass the mock data to avoid long shell arguments proc . stdin . write ( ( 'source' === from ? ( encodeURIComponent ( template ) + '\n' ) : '' ) + strData + '\n' ) ; //For python reading a line. proc . stdout . on ( 'data' , function ( data ) { //Here we get no string but buffer out += data . toString ( 'utf-8' ) ; } ) ; proc . stderr . on ( 'data' , function ( data ) { err += data . toString ( 'utf-8' ) ; } ) ; //What if blocked? We ignored it because this is not for production. proc . on ( 'exit' , function ( ) { if ( err ) { return callback ( new Error ( err ) ) ; } else { return callback ( null , out . replace ( / \r(?=\r\n) / mg , '' ) ) ; //A \r will always be prepend to \r\n } } ) ; }
Render from a file or source codes.

@param  {String}   from     source|file
@param  {String}   template
@param  {Object}   data
@param  {Function} callback
@since 0.1.4
Render from a file or source codes .