RKTUXYN/NTemplate


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

License: CC-BY-4.0

Language: C++

Keywords: addon, cplusplus, htmltemplate, javascript, node, node-js, template, template-engine


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();

Project Statistics

Sourcerank 4
Repository Size 468 KB
Stars 1
Forks 1
Watchers 0
Open issues 0
Dependencies 0
Contributors 1
Tags 0
Created
Last updated
Last pushed

Top Contributors See all

RKTUXYN

Something wrong with this page? Make a suggestion

Last synced: 2019-04-10 23:55:26 UTC

Login to resync this repository