<commit_before>var _ = require('lodash');

module.exports = function(options, callback) {
  return new Construct(options, callback);
};

module.exports.Construct = Construct;

function Construct(options, callback) {
  var apos = options.apos;
  var app = options.app;
  var schemas = options.schemas;
  var self = this;
  self.widgets = {};
  self._apos = apos;
  self._app = app;
  self._schemas = schemas;
  self._options = options;
  self._pages = options.pages;
  self._apos.mixinModuleAssets(self, 'schema-widgets', __dirname, options);

  self._apos.pushGlobalData({
    schemaWidgets: _.map(options.widgets, function(info) {
      info.css = info.css || apos.cssName(info.name);
      return info;
    })
  });

  // widgetEditors.html will spit out a frontend DOM template for editing
  // each widget type we register
  self.pushAsset('template', 'widgetEditors', { when: 'user', data: options });

  self.pushAsset('script', 'editor', { when: 'user' });
  self.pushAsset('stylesheet', 'editor', { when: 'user' });

  _.each(options.widgets, function(options) {
    var widget = {};
    apos.defaultControls.push(options.name);
    widget.name = options.name;
    widget.widget = true;
    widget.label = options.label || options.name;
    widget.css = options.css || apos.cssName(options.name);
    widget.icon = options.icon;
    widget.sanitize = function(req, item, callback) {
      var object = {};
      return schemas.convertFields(req, options.schema, 'form', item, object, function(err) {
        return callback(err, object);
      });
    };
    widget.renderWidget = function(data) {
      return self.render(widget.name, data);
    };<commit_msg>schema widgets can now be tested for emptiness<commit_after>var _ = require('lodash');

module.exports = function(options, callback) {
  return new Construct(options, callback);
};

module.exports.Construct = Construct;

function Construct(options, callback) {
  var apos = options.apos;
  var app = options.app;
  var schemas = options.schemas;
  var self = this;
  self.widgets = {};
  self._apos = apos;
  self._app = app;
  self._schemas = schemas;
  self._options = options;
  self._pages = options.pages;
  self._apos.mixinModuleAssets(self, 'schema-widgets', __dirname, options);

  self._apos.pushGlobalData({
    schemaWidgets: _.map(options.widgets, function(info) {
      info.css = info.css || apos.cssName(info.name);
      return info;
    })
  });

  // widgetEditors.html will spit out a frontend DOM template for editing
  // each widget type we register
  self.pushAsset('template', 'widgetEditors', { when: 'user', data: options });

  self.pushAsset('script', 'editor', { when: 'user' });
  self.pushAsset('stylesheet', 'editor', { when: 'user' });

  _.each(options.widgets, function(options) {
    var widget = {};
    apos.defaultControls.push(options.name);
    widget.name = options.name;
    widget.widget = true;
    widget.label = options.label || options.name;
    widget.css = options.css || apos.cssName(options.name);
    widget.icon = options.icon;
    widget.sanitize = function(req, item, callback) {
      var object = {};
      return schemas.convertFields(req, options.schema, 'form', item, object, function(err) {
        return callback(err, object);
      });
    };

    widget.renderWidget = function(data) {
      return self.render(widget.name, data);
    };

    widget.empty = function(data) {
      return self._schemas.empty(options.schema, data);
    };
{'fraction_non_alphanumeric': 0.14400921658986174, 'fraction_numerical': 0.0, 'mean_word_length': 3.533942558746736, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '269692', 'n_tokens_mistral': 1080, 'n_tokens_neox': 1062, 'n_words': 246}