<commit_before>var Handlebars = require("handlebars"),
    _ = require("underscore");

var registerHelpers = function() {
    /**
     * Basic list helper example
     * @param  {Array} items
     * @param  {Object} options
     * @return {Undef}
     */
    Handlebars.registerHelper('list', function(items, options) {
        var out = "<ul>";

        for(var i=0, l=items.length; i<l; i++) {
            out = out + "<li>" + options.fn(items[i]) + "</li>";
        }

        return out + "</ul>";
    });

    /**
     * Basic list helper example
     * @param  {Array} items
     * @param  {Object} options
     * @return {Undef}
     */
    Handlebars.registerHelper('bootstrapBasicList', function(items, options) {
        var out = "<ul class=\"list-group\">";

        for(var i = 0; i < items.length; i++) {
            if (_.isObject(items[i])) {
                out = out + "<li  class=\"list-group-item\">" + options.fn(items[i]) + "</li>";
            } else {
                out = out + "<li  class=\"list-group-item\">" + items[i] + "</li>";
            }
        }

        return out + "</ul>";
    });

    /**
     * Make list of book tags.
     */
    Handlebars.registerHelper('bookTags', function(items, options) {
        var out = "<div class=\"book-tags\">";

        for (var i = 0; i < items.length; i++) {
            out = out + "<span class=\"label label-pill label-primary\">" + items[i] + "</span>&nbsp;";
        }

        return out + "</div>";
    });
};

module.exports = registerHelpers;
<commit_msg>Add comparison operator Handlebars helper<commit_after>var Handlebars = require("handlebars"),
    _ = require("underscore");

var registerHelpers = function() {
    /**
     * Basic list helper example
     * @param  {Array} items
     * @param  {Object} options
     * @return {Undef}
     */
    Handlebars.registerHelper('list', function(items, options) {
        var out = "<ul>";

        for(var i=0, l=items.length; i<l; i++) {
            out = out + "<li>" + options.fn(items[i]) + "</li>";
        }

        return out + "</ul>";
    });

    /**
     * Basic list helper example
     * @param  {Array} items
     * @param  {Object} options
     * @return {Undef}
     */
    Handlebars.registerHelper('bootstrapBasicList', function(items, options) {
        var out = "<ul class=\"list-group\">";

        for(var i = 0; i < items.length; i++) {
            if (_.isObject(items[i])) {
                out = out + "<li  class=\"list-group-item\">" + options.fn(items[i]) + "</li>";
            } else {
                out = out + "<li  class=\"list-group-item\">" + items[i] + "</li>";
            }
        }

        return out + "</ul>";
    });

    /**
     * Make list of book tags.
     */
    Handlebars.registerHelper('bookTags', function(items, options) {
        var out = "<div class=\"book-tags\">";

        for (var i = 0; i < items.length; i++) {
            out = out + "<span class=\"label label-pill label-primary\">" + items[i] + "</span>&nbsp;";
        }

        return out + "</div>";
    });

    /**
     * Comparison operator
     * Examples::
     *
     *   {#compare Database.Tables.Count ">" 5}}
         There are more than 5 tables
         {{/compare}}

         {{#compare "Test" "Test"}}
         Default comparison of "==="
         {{/compare}}

     * Courtesy http://doginthehat.com.au/2012/02/comparison-block-helper-for-handlebars-templates/#comment-44
     */
    Handlebars.registerHelper('compare', function (lvalue, operator, rvalue, options) {
        var operators, result;
        
        if (arguments.length < 3) {
            throw new Error("Handlerbars Helper 'compare' needs 2 parameters");
        }
        
        if (options === undefined) {
            options = rvalue;
            rvalue = operator;
            operator = "===";
        }
        
        operators = {
            '==': function (l, r) { return l == r; },
            '===': function (l, r) { return l === r; },
            '!=': function (l, r) { return l != r; },
            '!==': function (l, r) { return l !== r; },
            '<': function (l, r) { return l < r; },
            '>': function (l, r) { return l > r; },
            '<=': function (l, r) { return l <= r; },
            '>=': function (l, r) { return l >= r; },
            'typeof': function (l, r) { return typeof l == r; }
        };
        
        if (!operators[operator]) {
            throw new Error("Handlerbars Helper 'compare' doesn't know the operator " + operator);
        }
        
        result = operators[operator](lvalue, rvalue);
        
        if (result) {
            return options.fn(this);
        } else {
            return options.inverse(this);
        }

    });
};

module.exports = registerHelpers;

{'fraction_non_alphanumeric': 0.17882451021258858, 'fraction_numerical': 0.003751563151313047, 'mean_word_length': 1.7982507288629737, 'pattern_counts': {'":': 0, '<': 42, '<?xml version=': 0, '>': 36, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, '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': '6511570', 'n_tokens_mistral': 1461, 'n_tokens_neox': 1427, 'n_words': 359}