StackGenVis: Alignment of Data, Algorithms, and Models for Stacking Ensemble Learning Using Performance Metrics https://doi.org/10.1109/TVCG.2020.3030352
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
StackGenVis/frontend/node_modules/templates/lib/helpers/singular.js

75 lines
2.0 KiB

4 years ago
'use strict';
var debug = require('debug')('base:templates:helper');
var utils = require('../utils');
module.exports = function(app, collection) {
var single = collection.options.inflection;
/**
* Create an async helper for getting a view from a collection.
*
* ```html
* <%%= page("foo.tmpl") %>
* ```
* @param {String} `name` The name or path of the view to get.
* @param {String} `singular` Singular name of the collection.
* @api public
*/
app.asyncHelper(single, function viewHelper(name, locals, options, cb) {
this.app.emit('helper', single + ' helper > rendering "' + name + '"');
debug('"%s" searching for "%s"', single, name);
if (typeof locals === 'function') {
return viewHelper.call(this, name, {}, {}, locals);
}
if (typeof options === 'function') {
return viewHelper.call(this, name, locals, {}, options);
}
options = options || {};
locals = locals || {};
var opts = helperOptions.call(this, locals, options);
var views = this.app[collection.options.plural] || app[collection.options.plural];
var view = views.getView(name, opts);
if (!view) {
utils.helperError(this.app, single, name, cb);
return;
}
debug('"%s" pre-rendering "%s"', single, name);
view._context = this.ctx(view, locals, opts);
view.render(function(err, res) {
if (err) return cb(err);
debug('"%s" rendered "%s"', single, name);
cb(null, res.content);
});
});
};
/**
* Create an options object from:
*
* - helper `locals`
* - helper `options`
* - options `hash` if it's registered as a handlebars helper
* - context options (`this.options`), created from options define on `app.option()`.
*
* @param {Object} `locals`
* @param {Object} `options`
* @return {Object}
*/
function helperOptions(locals, options) {
var hash = options.hash || locals.hash || {};
var opts = utils.merge({}, this.options, hash);
opts.hash = hash;
return opts;
}