src/moostaka.js
/**
     * Render a template into a specified HTMLElement node
     * 
     * @param {HTMLElement|string} an element node or a string specifiying an
     *      HTMLElement node e.g. '#content' for <div id="content"></div> 
     * @param {string} view - the name of an .mst file in the views location
     *      to use as a template
     * @param {?object} params - additional parameters for the Mustache template
     *      renderer
     * @param {?object} options - a dictionary of options. supported keys:
     *      {array<string>} tags - a list of delimiters for Mustache to use
     *      {bool} append - if true then new content to the element's contents
     *            otherwise replace the contents of element with the render
     *            output. Default: false
     * @param {?function} callback - a callback function to invoke once the
     *      template has been rendered into place
     */
Render a template into a specified HTMLElement node

@param {HTMLElement|string} an element node or a string specifiying an
HTMLElement node e.g. '#content' for 
@param {string} view - the name of an .mst file in the views location
to use as a template
@param {?object} params - additional parameters for the Mustache template
renderer
@param {?object} options - a dictionary of options. supported keys:
{array} tags - a list of delimiters for Mustache to use
{bool} append - if true then new content to the element's contents
otherwise replace the contents of element with the render
output. Default: false
@param {?function} callback - a callback function to invoke once the
template has been rendered into place
Render a template into a specified HTMLElement node @param { HTMLElement|string } an element node or a string specifiying an HTMLElement node e . g . ' #content ' for @param { string } view - the name of an . mst file in the views location to use as a template @param { ?object } params - additional parameters for the Mustache template renderer @param { ?object } options - a dictionary of options . supported keys : { array } tags - a list of delimiters for Mustache to use { bool } append - if true then new content to the element ' s contents otherwise replace the contents of element with the render output . Default : false @param { ?function } callback - a callback function to invoke once the template has been rendered into place
render(element, view, params, options, callback) {
        let destination = null;
        if(element instanceof HTMLElement) {
            destination = element;
        } else {
            destination = document.querySelector(element);
        }
        if(!params) {
            params = {};
        }
        if(!options) {
            options = {};
        }
        if(typeof options.tags === 'undefined') {
            Mustache.tags = [ '{{', '}}' ];
        } else {
            Mustache.tags = options.tags;
        }
        if(typeof options.append === 'undefined') {
            options.append = false;
        }
        let url = this.viewLocation + '/' + view.replace('.mst', '') + '.mst';
        fetch(url).then((response) => {
            return response.text();
        }).then(template => {
            if(options.append === true) {
                destination.innerHTML += Mustache.render(template, params);
            } else {
                while(destination.firstChild) {
                    destination.removeChild(destination.firstChild);
                }
                destination.innerHTML = Mustache.render(template, params);
            }
            if(callback instanceof Function) {
                callback();
            }
        });
    }
render ( element , view , params , options , callback ) { let destination = null ; if ( element instanceof HTMLElement ) { destination = element ; } else { destination = document . querySelector ( element ) ; } if ( ! params ) { params = { } ; } if ( ! options ) { options = { } ; } if ( typeof options . tags === 'undefined' ) { Mustache . tags = [ '{{' , '}}' ] ; } else { Mustache . tags = options . tags ; } if ( typeof options . append === 'undefined' ) { options . append = false ; } let url = this . viewLocation + '/' + view . replace ( '.mst' , '' ) + '.mst' ; fetch ( url ) . then ( ( response ) => { return response . text ( ) ; } ) . then ( template => { if ( options . append === true ) { destination . innerHTML += Mustache . render ( template , params ) ; } else { while ( destination . firstChild ) { destination . removeChild ( destination . firstChild ) ; } destination . innerHTML = Mustache . render ( template , params ) ; } if ( callback instanceof Function ) { callback ( ) ; } } ) ; }
Render a template into a specified HTMLElement node
Render a template into a specified HTMLElement node