<commit_before>/*global escapeHTMLComponent,encodeJSONHTML */
'use strict';
if (!module.parent) console.error('Please don\'t call me directly.I am just the main app\'s minion.') || process.process.exit(1);
require('nodestrum');
var Class = require('sji'),
    util = require('util'),
    cloudinary = require('cloudinary'),
    _ = require('lodash');

var GOOGLE_MAPS_API_KEY = process.env.GOOGLE_MAPS_API_KEY || '<KEY>';

var Widget = exports.Widget = Class.extend({
    init: function (options) {
        this.options = options;
        this.limit = options.limit || 50;
        this.validators = options.validators || [];
        this.attrs = _.assign({class: []}, options.attrs);
        this.attrs.class.push(options.required || options.attrs.required ? 'required' : 'optional');
        this.data = options.data || {};
        this.name = '';
        this.value = null;
        this.head = [];
    },

    pre_render: function (callback) {
        callback();
    },

    render: function () {
        return this;
    },

    render_attributes: function (res) {
        var self = this;
        var longString = _(this.data)
            .pairs()
            .forEach(function(pair) {pair[0] = 'data-' + pair[0];})
            .concat(_.pairs(this.attrs), [['name', self.name], ['id','id_' + self.name]])
            .map(function (pair) {
                var name = pair[0];
                var value = pair[1];
                if (name in {required:1, selected:1, hidden:1} && !value) return '';
                value = Array.isArray(value) ? value.join(' ') : value;
                return util.format('%s="%s"', escapeHTMLComponent(name), escapeHTMLComponent(value));
            })
            .join(' ');

        res.write(' ' + longString + ' ');
        return this;
    }
});


exports.InputWidget = Widget.extend({
    init: function (type, options) {
        options.attrs.type = options.attrs.type || type;
        this._super(options);
    },
    render: function (res) {
        var value_str = 'value' in this ? ' value="' + escapeHTMLComponent(this.value) + '" ' : ' ';
        res.write('\n<input' + value_str );
        this.render_attributes(res);
        res.write(' />\n');
        return this;
    }
});


exports.HiddenWidget = exports.InputWidget.extend({
    init: function (options) {
        this._super('hidden', options);
    }
});


exports.TextWidget = exports.InputWidget.extend({
    init: function (options) {
        this._super('text', options);
    }
});


exports.PasswordWidget = exports.InputWidget.extend({
    init: function (options) {
        this._super('password', options);
    }
});


exports.TextAreaWidget = Widget.extend({
    render: function (res) {
        var value = this.value;
        delete this.value;
        res.write('\n<textarea ');
        this.render_attributes(res);
        res.write(' >\n');
        res.write(escapeHTMLComponent(value));
        res.write('\n</textarea>\n');
        return this;
    }
});


exports.RichTextAreaWidget = exports.TextAreaWidget.extend({
    init: function (options) {
        this._super(options);
        this.attrs.class.push('ckeditor');
    },
    render: function (res) {
        res.write('\n<div class="nf_widget">\n');<commit_msg>Close #55<commit_after>/*global escapeHTMLComponent,encodeJSONHTML */
'use strict';
if (!module.parent) console.error('Please don\'t call me directly.I am just the main app\'s minion.') || process.process.exit(1);
require('nodestrum');
var Class = require('sji'),
    util = require('util'),
    cloudinary = require('cloudinary'),
    _ = require('lodash');

var GOOGLE_MAPS_API_KEY = process.env.GOOGLE_MAPS_API_KEY || '<KEY>FTc32E';

var Widget = exports.Widget = Class.extend({
    init: function (options) {
        this.options = options;
        this.limit = options.limit || 50;
        this.validators = options.validators || [];
        this.attrs = _.assign({class: []}, options.attrs);
        this.attrs.class.push(options.required || options.attrs.required ? 'required' : 'optional');
        this.data = options.data || {};
        this.name = '';
        this.value = null;
        this.head = [];
    },

    pre_render: function (callback) {
        callback();
    },

    render: function () {
        return this;
    },

    render_attributes: function (res) {
        var self = this;
        var longString = _(this.data)
            .pairs()
            .forEach(function(pair) {pair[0] = 'data-' + pair[0];})
            .concat(_.pairs(this.attrs), [['name', self.name], ['id','id_' + self.name]])
            .map(function (pair) {
                var name = pair[0];
                var value = pair[1];
                if (name in {required:1, selected:1, hidden:1} && !value) return '';
                value = Array.isArray(value) ? value.join(' ') : value;
                return util.format('%s="%s"', escapeHTMLComponent(name), escapeHTMLComponent(value));
            })
            .join(' ');

        res.write(' ' + longString + ' ');
        return this;
    }
});


exports.InputWidget = Widget.extend({
    init: function (type, options) {
        options.attrs.type = options.attrs.type || type;
        this._super(options);
    },
    render: function (res) {
        var value_str = 'value' in this ? ' value="' + escapeHTMLComponent(this.value) + '" ' : ' ';
        res.write('\n<input' + value_str );
        this.render_attributes(res);
        res.write(' />\n');
        return this;
    }
});


exports.HiddenWidget = exports.InputWidget.extend({
    init: function (options) {
        this._super('hidden', options);
    }
});


exports.TextWidget = exports.InputWidget.extend({
    init: function (options) {
        this._super('text', options);
    }
});


exports.PasswordWidget = exports.InputWidget.extend({
    init: function (options) {
        this._super('password', options);
    }
});


exports.TextAreaWidget = Widget.extend({
    render: function (res) {
        var value = this.value;
        delete this.value;
        res.write('\n<textarea ');
        this.render_attributes(res);
        res.write(' >');
        res.write(escapeHTMLComponent(value));
        res.write('</textarea>\n');
        return this;
    }
});


exports.RichTextAreaWidget = exports.TextAreaWidget.extend({
    init: function (options) {
        this._super(options);
        this.attrs.class.push('ckeditor');
    },
    render: function (res) {
        res.write('\n<div class="nf_widget">\n');
{'fraction_non_alphanumeric': 0.16584539574992302, 'fraction_numerical': 0.0036957191253464737, 'mean_word_length': 2.4040880503144653, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, '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': '2444439', 'n_tokens_mistral': 1965, 'n_tokens_neox': 1929, 'n_words': 383}