<commit_before>var escapeXml = require('raptor-util/escapeXml');
var escapeXmlAttr = escapeXml.attr;
var runtime = require('./'); // Circular dependnecy, but that is okay
var extend = require('raptor-util/extend');
var attr = require('raptor-util/attr');
var attrs = require('raptor-util/attrs');
var forEach = require('raptor-util/forEach');
var markoRegExp = /\.marko(.xml|.html)?$/;
var req = require;
var arrayFromArguments = require('raptor-util/arrayFromArguments');
var logger = require('raptor-logging').logger(module);

function notEmpty(o) {
    if (o == null) {
        return false;
    } else if (Array.isArray(o)) {
        return !!o.length;
    } else if (o === '') {
        return false;
    }

    return true;
}

var WARNED_INVOKE_BODY = 0;

module.exports = {
    s: function(str) {
        return (str == null) ? '' : str;
    },

    fv: function (array, callback) {
        if (!array) {
            return;
        }
        if (!array.forEach) {
            array = [array];
        }
        var i = 0;
        var len = array.length;
        var loopStatus = {
                getLength: function () {
                    return len;
                },
                isLast: function () {
                    return i === len - 1;
                },
                isFirst: function () {
                    return i === 0;
                },
                getIndex: function () {
                    return i;
                }
            };
        for (; i < len; i++) {
            var o = array[i];
            callback(o || '', loopStatus);
        }
    },
    f: forEach,
    fl: function (array, func) {
        if (array != null) {
            if (!Array.isArray(array)) {
                array = [array];
            }
            func(array, 0, array.length);
        }
    },
    fp: function (o, func) {
        if (!o) {
            return;
        }
        for (var k in o) {
            if (o.hasOwnProperty(k)) {
                func(k, o[k]);
            }
        }
    },
    e: function (o) {
        return !notEmpty(o);
    },
    ne: notEmpty,
    x: escapeXml,
    xa: escapeXmlAttr,
    nx: function (str) {
        return {
            toString: function () {
                return str;
            }
        };
    },
    a: attr,

    as: attrs,

    /**
     * Loads a template
     */
    l: function(path) {
        if (typeof path === 'string') {
            if (markoRegExp.test(path)) {
                return runtime.load(path);
            } else {
                return req('view-engine').load(path);
            }
        } else if (path.render) {
            // Assume it is already a pre-loaded template
            return path;
        } else {
            return runtime.load(path);
        }
    },
    /**
     * Returns the render function for a tag handler
     */
    r: function(handler) {
        var renderFunc;
        if (typeof handler === 'function') {
            renderFunc = handler;
        } else {
            renderFunc = handler.renderer || handler.render;
        }

        if (typeof renderFunc !== 'function') {
            throw new Error('Invalid handler: ' + handler);
        }

        return renderFunc;
    },

    // ----------------------------------
    // Helpers that require an out below:
    // ----------------------------------


    /**
     * Invoke a tag handler render function
     */
    t: function (out, renderFunc, input, body, hasOutParam) {
        if (!input) {
            input = {};
        }

        if (body) {
            input.renderBody = body;
            input.invokeBody = function() {
                if (!WARNED_INVOKE_BODY) {
                    WARNED_INVOKE_BODY = 1;<commit_msg>Improve how renderer is resolved<commit_after>var escapeXml = require('raptor-util/escapeXml');
var escapeXmlAttr = escapeXml.attr;
var runtime = require('./'); // Circular dependnecy, but that is okay
var extend = require('raptor-util/extend');
var attr = require('raptor-util/attr');
var attrs = require('raptor-util/attrs');
var forEach = require('raptor-util/forEach');
var markoRegExp = /\.marko(.xml|.html)?$/;
var req = require;
var arrayFromArguments = require('raptor-util/arrayFromArguments');
var logger = require('raptor-logging').logger(module);

function notEmpty(o) {
    if (o == null) {
        return false;
    } else if (Array.isArray(o)) {
        return !!o.length;
    } else if (o === '') {
        return false;
    }

    return true;
}

var WARNED_INVOKE_BODY = 0;

module.exports = {
    s: function(str) {
        return (str == null) ? '' : str;
    },

    fv: function (array, callback) {
        if (!array) {
            return;
        }
        if (!array.forEach) {
            array = [array];
        }
        var i = 0;
        var len = array.length;
        var loopStatus = {
                getLength: function () {
                    return len;
                },
                isLast: function () {
                    return i === len - 1;
                },
                isFirst: function () {
                    return i === 0;
                },
                getIndex: function () {
                    return i;
                }
            };
        for (; i < len; i++) {
            var o = array[i];
            callback(o || '', loopStatus);
        }
    },
    f: forEach,
    fl: function (array, func) {
        if (array != null) {
            if (!Array.isArray(array)) {
                array = [array];
            }
            func(array, 0, array.length);
        }
    },
    fp: function (o, func) {
        if (!o) {
            return;
        }
        for (var k in o) {
            if (o.hasOwnProperty(k)) {
                func(k, o[k]);
            }
        }
    },
    e: function (o) {
        return !notEmpty(o);
    },
    ne: notEmpty,
    x: escapeXml,
    xa: escapeXmlAttr,
    nx: function (str) {
        return {
            toString: function () {
                return str;
            }
        };
    },
    a: attr,

    as: attrs,

    /**
     * Loads a template
     */
    l: function(path) {
        if (typeof path === 'string') {
            if (markoRegExp.test(path)) {
                return runtime.load(path);
            } else {
                return req('view-engine').load(path);
            }
        } else if (path.render) {
            // Assume it is already a pre-loaded template
            return path;
        } else {
            return runtime.load(path);
        }
    },
    /**
     * Returns the render function for a tag handler
     */
    r: function(handler) {
        var renderFunc = handler.renderer;
        if (!renderFunc) {
            renderFunc = handler.render || handler;
        }

        if (typeof renderFunc !== 'function') {
            throw new Error('Invalid handler: ' + handler);
        }

        return renderFunc;
    },

    // ----------------------------------
    // Helpers that require an out below:
    // ----------------------------------


    /**
     * Invoke a tag handler render function
     */
    t: function (out, renderFunc, input, body, hasOutParam) {
        if (!input) {
            input = {};
        }

        if (body) {
            input.renderBody = body;
            input.invokeBody = function() {
                if (!WARNED_INVOKE_BODY) {
                    WARNED_INVOKE_BODY = 1;
{'fraction_non_alphanumeric': 0.14734429765435428, 'fraction_numerical': 0.0016176867080075492, 'mean_word_length': 1.2940630797773656, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1955961', 'n_tokens_mistral': 2153, 'n_tokens_neox': 2082, 'n_words': 531}