lib/jyt.runtime.js
function render(element, opts) {
    opts = opts || {};

    var prepend = opts.prepend;
    var model = opts.model || {};
    var indentLevel = opts.indentLevel || 0;
    var isPretty = opts.isPretty;
    var jtPrintIndent = isPretty ? '\t' : '';
    var jtPrintNewline = isPretty ? '\n' : '';
    var indent = '', i, len, prop;
    var p = [];  // p is going to be our concatenator for the HTML string

    // if no element, then no HTML so return empty string
    if (!element) { return ''; }

    // if already a string, just return it
    if (utils.isString(element)) { return element; }

    // if an array, wrap it
    if (utils.isArray(element)) { element = naked(element, null); }

    // set the indentation level to the current indent
    if (isPretty && indentLevel) {
        for (i = 0; i < indentLevel; i++) {
            indent += jtPrintIndent;
        }
    }

    // if we are prepending some string, add it first
    if (prepend) {
        p.push(indent, prepend, jtPrintNewline);
    }

    // starting tag open
    if (element.tag) {
        p.push(indent, '<', element.tag);
    }

    // all tag attributes
    if (element.attributes) {
        for (prop in element.attributes) {
            if (element.attributes.hasOwnProperty(prop)) {

                if (element.attributes[prop] === null) {
                    p.push(' ', prop);
                }
                else {
                    p.push(' ', prop, '="', element.attributes[prop], '"');
                }
            }
        }
    }

    // if no children or text, then close the tag
    if (element.tag && !element.children && (element.text === undefined || element.text === null)) {

        // for self closing we just close it, else we add the end tag
        if (selfClosing.indexOf(element.tag) > -1) {
            p.push('/>', jtPrintNewline);
        }
        else {
            p.push('></', element.tag, '>', jtPrintNewline);
        }
    }
    // else we need to add children or the inner text
    else {

        // if a tag (i.e. not just a string literal) put end bracket
        if (element.tag) { p.push('>'); }

        // if children, we will need to recurse
        if (element.children) {
            if (element.tag) { p.push(jtPrintNewline); }

            // recurse down for each child
            for (i = 0, len = element.children.length; i < len; ++i) {
                p.push(render(element.children[i], {
                    indentLevel:    element.tag ? indentLevel + 1 : indentLevel,
                    isPretty:       isPretty,
                    model:          model
                }));
            }

            if (element.tag) { p.push(indent); }
        }

        // if text, simply add it
        if (element.text !== null && element.text !== undefined) { p.push(element.text); }

        // finally if a tag, add close tag
        if (element.tag) {
            p.push('</', element.tag, '>', jtPrintNewline);
        }
    }

    return p.join('');
}
function render(element, opts) {
    opts = opts || {};

    var prepend = opts.prepend;
    var model = opts.model || {};
    var indentLevel = opts.indentLevel || 0;
    var isPretty = opts.isPretty;
    var jtPrintIndent = isPretty ? '\t' : '';
    var jtPrintNewline = isPretty ? '\n' : '';
    var indent = '', i, len, prop;
    var p = [];  // p is going to be our concatenator for the HTML string

    // if no element, then no HTML so return empty string
    if (!element) { return ''; }

    // if already a string, just return it
    if (utils.isString(element)) { return element; }

    // if an array, wrap it
    if (utils.isArray(element)) { element = naked(element, null); }

    // set the indentation level to the current indent
    if (isPretty && indentLevel) {
        for (i = 0; i < indentLevel; i++) {
            indent += jtPrintIndent;
        }
    }

    // if we are prepending some string, add it first
    if (prepend) {
        p.push(indent, prepend, jtPrintNewline);
    }

    // starting tag open
    if (element.tag) {
        p.push(indent, '<', element.tag);
    }

    // all tag attributes
    if (element.attributes) {
        for (prop in element.attributes) {
            if (element.attributes.hasOwnProperty(prop)) {

                if (element.attributes[prop] === null) {
                    p.push(' ', prop);
                }
                else {
                    p.push(' ', prop, '="', element.attributes[prop], '"');
                }
            }
        }
    }

    // if no children or text, then close the tag
    if (element.tag && !element.children && (element.text === undefined || element.text === null)) {

        // for self closing we just close it, else we add the end tag
        if (selfClosing.indexOf(element.tag) > -1) {
            p.push('/>', jtPrintNewline);
        }
        else {
            p.push('></', element.tag, '>', jtPrintNewline);
        }
    }
    // else we need to add children or the inner text
    else {

        // if a tag (i.e. not just a string literal) put end bracket
        if (element.tag) { p.push('>'); }

        // if children, we will need to recurse
        if (element.children) {
            if (element.tag) { p.push(jtPrintNewline); }

            // recurse down for each child
            for (i = 0, len = element.children.length; i < len; ++i) {
                p.push(render(element.children[i], {
                    indentLevel:    element.tag ? indentLevel + 1 : indentLevel,
                    isPretty:       isPretty,
                    model:          model
                }));
            }

            if (element.tag) { p.push(indent); }
        }

        // if text, simply add it
        if (element.text !== null && element.text !== undefined) { p.push(element.text); }

        // finally if a tag, add close tag
        if (element.tag) {
            p.push('</', element.tag, '>', jtPrintNewline);
        }
    }

    return p.join('');
}
function render ( element , opts ) { opts = opts || { } ; var prepend = opts . prepend ; var model = opts . model || { } ; var indentLevel = opts . indentLevel || 0 ; var isPretty = opts . isPretty ; var jtPrintIndent = isPretty ? '\t' : '' ; var jtPrintNewline = isPretty ? '\n' : '' ; var indent = '' , i , len , prop ; var p = [ ] ; // p is going to be our concatenator for the HTML string // if no element, then no HTML so return empty string if ( ! element ) { return '' ; } // if already a string, just return it if ( utils . isString ( element ) ) { return element ; } // if an array, wrap it if ( utils . isArray ( element ) ) { element = naked ( element , null ) ; } // set the indentation level to the current indent if ( isPretty && indentLevel ) { for ( i = 0 ; i < indentLevel ; i ++ ) { indent += jtPrintIndent ; } } // if we are prepending some string, add it first if ( prepend ) { p . push ( indent , prepend , jtPrintNewline ) ; } // starting tag open if ( element . tag ) { p . push ( indent , '<' , element . tag ) ; } // all tag attributes if ( element . attributes ) { for ( prop in element . attributes ) { if ( element . attributes . hasOwnProperty ( prop ) ) { if ( element . attributes [ prop ] === null ) { p . push ( ' ' , prop ) ; } else { p . push ( ' ' , prop , '="' , element . attributes [ prop ] , '"' ) ; } } } } // if no children or text, then close the tag if ( element . tag && ! element . children && ( element . text === undefined || element . text === null ) ) { // for self closing we just close it, else we add the end tag if ( selfClosing . indexOf ( element . tag ) > - 1 ) { p . push ( '/>' , jtPrintNewline ) ; } else { p . push ( '></' , element . tag , '>' , jtPrintNewline ) ; } } // else we need to add children or the inner text else { // if a tag (i.e. not just a string literal) put end bracket if ( element . tag ) { p . push ( '>' ) ; } // if children, we will need to recurse if ( element . children ) { if ( element . tag ) { p . push ( jtPrintNewline ) ; } // recurse down for each child for ( i = 0 , len = element . children . length ; i < len ; ++ i ) { p . push ( render ( element . children [ i ] , { indentLevel : element . tag ? indentLevel + 1 : indentLevel , isPretty : isPretty , model : model } ) ) ; } if ( element . tag ) { p . push ( indent ) ; } } // if text, simply add it if ( element . text !== null && element . text !== undefined ) { p . push ( element . text ) ; } // finally if a tag, add close tag if ( element . tag ) { p . push ( '</' , element . tag , '>' , jtPrintNewline ) ; } } return p . join ( '' ) ; }
Take a jyt element and render it to an HTML string
@param element
@param opts
Take a jyt element and render it to an HTML string