2
0
Fork 0
tcrud/lib/plugin/auto/tentity/auto-tentity-tplural.js
2017-06-10 16:53:29 +02:00

33 lines
723 B
JavaScript

module.exports = (function () {
var makePlural = function(name) {
if (name.slice(-1) === 's') {
return name;
}
if (name.slice(-1) === 'y') {
name = name.slice(0,-1) + 'ie';
}
return name + 's';
}
return function AutoTEntityTPluralPlugin() {
this.configPlugin = function (ctx) {
ctx.key='autoTEntityTPlural';
ctx.description='Auto create tplurals from the tname/tid field.';
ctx.dependencies.push('autoTName');
};
this.fillTEntity = function(ctx) {
if (ctx.tentity.tplural === null) {
if (ctx.tentity.tname === null) {
ctx.tentity.tplural = makePlural(ctx.tentity.tid);
} else {
ctx.tentity.tplural = makePlural(ctx.tentity.tname);
}
}
};
};
})();