2
0
Fork 0
tcrud/lib/plugin/auto/tentity/auto-tentity-tplural.js

33 lines
723 B
JavaScript
Raw Normal View History

2017-06-10 14:53:29 +00:00
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);
}
}
};
};
})();