Halfway through in refactoring the report generation to a separate process running asynchronously of the Express server.
This commit is contained in:
parent
2056645023
commit
e7d12f1dbc
10 changed files with 319 additions and 206 deletions
46
lib/handlebars-helpers.js
Normal file
46
lib/handlebars-helpers.js
Normal file
|
@ -0,0 +1,46 @@
|
|||
'use strict';
|
||||
|
||||
const _ = require('../lib/translate')._;
|
||||
|
||||
module.exports.registerHelpers = (handlebars) => {
|
||||
// {{#translate}}abc{{/translate}}
|
||||
handlebars.registerHelper('translate', function (context, options) { // eslint-disable-line prefer-arrow-callback
|
||||
if (typeof options === 'undefined' && context) {
|
||||
options = context;
|
||||
context = false;
|
||||
}
|
||||
|
||||
let result = _(options.fn(this)); // eslint-disable-line no-invalid-this
|
||||
|
||||
if (Array.isArray(context)) {
|
||||
result = util.format(result, ...context);
|
||||
}
|
||||
return new handlebars.SafeString(result);
|
||||
});
|
||||
|
||||
|
||||
/* Credits to http://chrismontrois.net/2016/01/30/handlebars-switch/
|
||||
|
||||
{{#switch letter}}
|
||||
{{#case "a"}}
|
||||
A is for alpaca
|
||||
{{/case}}
|
||||
{{#case "b"}}
|
||||
B is for bluebird
|
||||
{{/case}}
|
||||
{{/switch}}
|
||||
*/
|
||||
handlebars.registerHelper("switch", function(value, options) {
|
||||
this._switch_value_ = value;
|
||||
var html = options.fn(this); // Process the body of the switch block
|
||||
delete this._switch_value_;
|
||||
return html;
|
||||
});
|
||||
|
||||
handlebars.registerHelper("case", function(value, options) {
|
||||
if (value == this._switch_value_) {
|
||||
return options.fn(this);
|
||||
}
|
||||
});
|
||||
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue