Skip to content

Latest commit

 

History

History
85 lines (83 loc) · 2.28 KB

README.md

File metadata and controls

85 lines (83 loc) · 2.28 KB

NTemplate

Nested Template Parser for Node.js (Populate data and add multiple attachment and template in single page)

Example:
#Add library:

var tparser = require( './build/release/ntemplate' );

#Run Javascript:

tparser.runScript( `for(let p=0; p<10; p++)console.log('Script is running...' + p)` );

#Parse & Run Nested Template without async

var html = tparser.parse( __dirname, __dirname + "\\test\\nested_template.html.html" );
console.log( html );

#Parse & Run Script Template without async

html = tparser.parse( __dirname, __dirname + "\\test\\script_template.html.html", this );
console.log( html );

#Performance Check Nested Template without async

for ( let i = 0; i < 10000; i++ ) {
    let _html = tparser.parse( __dirname, __dirname + "\\test\\nested_template.html" );
    console.log( _html );
};

#Parse Template with data without or with async
Settings:

let settings = {
    root_dir: "SERVER ROOT DIRECTORY",
    page_path: "REQUIST PAGE PATH",
    data: "array/object/undefined",
    isAsync: "boolean [true/false]",
    callback: function ( rsp ) { }
};

Response should be:

resp = {
    is_error: false,
    err_msg: "NOPE",
    result: "HTML RESULT HERE!!!"
};

Send async request to VM:

let example = async () =>{
    let resp = await tparser.parseo( {
        root_dir: __dirname,
        page_path: __dirname + "\\test\\script_template.html",
        data: this,
        isAsync: true,
        callback: function ( rsp ) {
            if ( rsp.is_error ) {
                console.log( rsp.err_msg );
            } else {
                console.log( rsp.result.length );
            }
        }
    } );
    console.log( resp );
    for ( let x = 0; x < 100; x++ ) {
        let copy = x;
        await tparser.async( {
            root_dir: __dirname,
            page_path: __dirname + "\\test\\script_template.html",
            data: this,
            callback: function ( rsp ) {
                console.log( copy );
                if ( rsp.is_error ) {
                    console.log( rsp.err_msg );
                } else {
                    console.log( rsp.result.length );
                }
            }
        } );
    }

};
example();