<commit_before>Po.NS('Utils')

Utils.HandlebarsHelpers = Ember.Object.extend({
    /////////////////////////////////////////////////////////////////
    /////////////////////////////////////////////////////////////////
    /////////////////////////////////////////////////////////////////
    /////////////////////////////////////////////////////////////////
    debug: function (value) {
        "use strict";
        console.log(value);
    },

    ucfirst: function (value) {
        if (value) {
            value = value.charAt(0).toUpperCase() + value.slice(1);
        }
        return value;
    },

    humanFileSize: function (size) {
        var i = Math.floor(Math.log(size) / Math.log(1024));
        return ( size / Math.pow(1024, i) ).toFixed(2) * 1 + ' ' + ['B', 'kB', 'MB', 'GB', 'TB'][i];
    },

    renderMarkdown: function (string, options) {

        if (!string) {
            string = '';
        }

        marked.setOptions(Po.merge({
            gfm: true,
            tables: true,
            breaks: false,
            pedantic: false,
            sanitize: true,
            smartLists: true,
            smartypants: false
        }, options));

        return marked(string);
    },

    gravatarImg: function (email, options) {
        var cls = options.hash.class || '';
        var server = window.location.protocol + '//' + window.location.host;
        var img = 'mm';
        if (server.indexOf(':') === -1) {
            img = encodeURIComponent(server + '/static/vaultier/images/icon-avatar-grey.png');
        }

        var size = ( typeof(options.hash.size) === "undefined") ? 32 : options.hash.size;

        var result = '<img style="width:' + size + 'px; height:' + size + 'px;" class="' + cls + '" src="http://www.gravatar.com/avatar/' + CryptoJS.MD5(email) + '?s=' + size + '&d=' + img + '" />';
        return result;

    },

    printUser: function (user, options) {
        if (!user) {
            user = {
                email: '<EMAIL>',
                nickname: 'Deleted user'
            }
        }

        var email = user.email || user.get('email');
        var nickname = user.nickname || user.get('nickname');
        var size = options.hash.size || 25;
        var length = options.hash.ellipsis || 60;
        var prefix = options.hash.prefix || '';
        var disableTooltip = options.hash.disableTooltip || false;
        var disableName = options.hash.disableName || false;
        var displayEmailInsideBrackets = options.hash.displayEmailInsideBrackets || false;

        var avatar = this.gravatarImg(email, {hash: {size: size}});

        var name;
        if (options.hash.email) {
            name = email;
        } else {
            name = this.ucfirst(nickname);
        }
        var short = this.ellipsis(name, length);


        if (!disableTooltip) {
            var tooltip = 'data-toggle="tooltip" title="{prefix} {name} ({email})"'
                .replace('{prefix}', prefix)
                .replace('{name}', name)
                .replace('{email}', email)
        } else {
            tooltip = ''
        }

        if (disableName) {
            short = '';
            name = '';
        }
        if (displayEmailInsideBrackets) {
            return '<span class="vlt-user" {tooltip} >{avatar} {name} ({email})</span>'
                .replace('{tooltip}', tooltip)
                .replace('{name}', short)
                .replace('{email}', email)
                .replace('{avatar}', avatar);
        } else {
            return '<span class="vlt-user" {tooltip} >{avatar} {name}</span>'
                .replace('{tooltip}', tooltip)
                .replace('{name}', short)
                .replace('{avatar}', avatar);
        }

    },

    printAgo: function (t, options) {
        var prefix = options.hash.prefix || '';
        var a;

        try {
            a = moment(t).fromNow();
        } catch (e) {
            console.error(e.stack)<commit_msg>remove coondition at return statment and use one template for simplicity on printUser function #140<commit_after>Po.NS('Utils')

Utils.HandlebarsHelpers = Ember.Object.extend({
    /////////////////////////////////////////////////////////////////
    /////////////////////////////////////////////////////////////////
    /////////////////////////////////////////////////////////////////
    /////////////////////////////////////////////////////////////////
    debug: function (value) {
        "use strict";
        console.log(value);
    },

    ucfirst: function (value) {
        if (value) {
            value = value.charAt(0).toUpperCase() + value.slice(1);
        }
        return value;
    },

    humanFileSize: function (size) {
        var i = Math.floor(Math.log(size) / Math.log(1024));
        return ( size / Math.pow(1024, i) ).toFixed(2) * 1 + ' ' + ['B', 'kB', 'MB', 'GB', 'TB'][i];
    },

    renderMarkdown: function (string, options) {

        if (!string) {
            string = '';
        }

        marked.setOptions(Po.merge({
            gfm: true,
            tables: true,
            breaks: false,
            pedantic: false,
            sanitize: true,
            smartLists: true,
            smartypants: false
        }, options));

        return marked(string);
    },

    gravatarImg: function (email, options) {
        var cls = options.hash.class || '';
        var server = window.location.protocol + '//' + window.location.host;
        var img = 'mm';
        if (server.indexOf(':') === -1) {
            img = encodeURIComponent(server + '/static/vaultier/images/icon-avatar-grey.png');
        }

        var size = ( typeof(options.hash.size) === "undefined") ? 32 : options.hash.size;

        var result = '<img style="width:' + size + 'px; height:' + size + 'px;" class="' + cls + '" src="http://www.gravatar.com/avatar/' + CryptoJS.MD5(email) + '?s=' + size + '&d=' + img + '" />';
        return result;

    },

    printUser: function (user, options) {
        if (!user) {
            user = {
                email: '<EMAIL>',
                nickname: 'Deleted user'
            }
        }

        var email = user.email || user.get('email');
        var nickname = user.nickname || user.get('nickname');
        var size = options.hash.size || 25;
        var length = options.hash.ellipsis || 60;
        var prefix = options.hash.prefix || '';
        var disableTooltip = options.hash.disableTooltip || false;
        var disableName = options.hash.disableName || false;
        var displayEmailInsideBrackets = options.hash.displayEmailInsideBrackets || false;

        var avatar = this.gravatarImg(email, {hash: {size: size}});

        var name;
        if (options.hash.email) {
            name = email;
        } else {
            name = this.ucfirst(nickname);
        }
        var short = this.ellipsis(name, length);


        if (!disableTooltip) {
            var tooltip = 'data-toggle="tooltip" title="{prefix} {name} ({email})"'
                .replace('{prefix}', prefix)
                .replace('{name}', name)
                .replace('{email}', email)
        } else {
            tooltip = ''
        }

        if (disableName) {
            short = '';
            name = '';
        }
        return '<span class="vlt-user" {tooltip} >{avatar} {name} {email}</span>'
            .replace('{tooltip}', tooltip)
            .replace('{name}', short)
            .replace('{avatar}', avatar)
            .replace('{email}', function () {
                if (displayEmailInsideBrackets) {
                    return '(' + email + ')';
                }
                return '';
            });

    },

    printAgo: function (t, options) {
        var prefix = options.hash.prefix || '';
        var a;

        try {
            a = moment(t).fromNow();
        } catch (e) {
            console.error(e.stack)
{'fraction_non_alphanumeric': 0.21244444444444444, 'fraction_numerical': 0.0054603174603174605, 'mean_word_length': 1.4248768472906403, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '3425076', 'n_tokens_mistral': 2227, 'n_tokens_neox': 2142, 'n_words': 471}