Skip to content

Commit

Permalink
Merge pull request #74 from QuickCorp/v2.3
Browse files Browse the repository at this point in the history
repeat() && component() template processors
  • Loading branch information
jeanmachuca committed Jun 20, 2021
2 parents 70ab776 + 09a3bb9 commit e2a7ae4
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions QCObjects.js
Original file line number Diff line number Diff line change
Expand Up @@ -3362,6 +3362,37 @@

ClassFactory("Processor").setProcessor(layout);

let component = function () {
/*
* component processor
* @usage
* $component(name=<name>, componentClass=<componentClass>, ...)
* Returns a component tag declaration like:
* <component name=<name> ...></component>
*/
let arg = [...arguments].map(function (a){ return {[a.split("=")[0]]:a.split("=")[1]}}).reduce(function (k1, k2) {return Object.assign(k1, k2)});
let attrs = [...Object.keys(arg)].map(function (a) {return `${a}=${arg[a]}`}).join(" ");
return `<component ${attrs}></component>`;
};

ClassFactory("Processor").setProcessor(component);

let repeat = function (length, text) {
/*
* Repeat processor
* @usage
* $repeat(<length>, <text>)
* Where length is the number of occurrences of text
*/
return range(length).map(
function (index) {
return text.replace("{{index}}",index.toString());
}
).join("");
};

ClassFactory("Processor").setProcessor(repeat);


})(_top);

Expand Down

0 comments on commit e2a7ae4

Please sign in to comment.