zen0wu / topcoder-greed

greedy editor for topcoder arena
Apache License 2.0
229 stars 48 forks source link

Change the syntax of named renderer #85

Closed wookayin closed 10 years ago

wookayin commented 10 years ago

Related to wiki page [[Template-Engine]], section Named Renderers.

I suggest that we change the syntax of named renderers in the template engine. Currently we have

${data;renderer(param),renderer(param),...}
${Contest.Name;abbr,}

and my suggestion is:

${data | renderer(param) | renderer(..)}

This is like a pipe semantic in unix shells. I think this is very intuitive and looks clear. Some other template engine syntax uses this style (they call them filter usually).

Well, of course, I know the previously defined templates are using the legacy style {data;renderer}. But the new greed can inintroduce this syntax, and we can keep backward compatibilities but encouraging use of the new style.

Feedbacks are welcome. If acceptable, I'll submit a patch.

Just a note - related changes that can be followed:

wookayin commented 10 years ago

Oops, I got a little mistake, the current syntax is not as above. I'll polish the issue later, sorry.

zen0wu commented 10 years ago

This is a good idea. So the pipe behavior is like a sequential one right? Like in ${X | Y | W} I have a "X", feed into "Y" and resulting "Z", then "Z" is further fed into W instead of X?

How are you going to implement this? The behaviour is built in into the template engine.

wookayin commented 10 years ago

Yeap, the lexer of jmte is hard-coded and seems to unconfigurable. What a pity :( AFAIK There is no way to apply multiple renderers in chain -- unless we fork and customize it.

BTW, do we indeed need the chaining? And I wonder why contest category renderer (#77) is included in the string render. It is a parameterized thing, so what about split it into another renderer, as long as the other string filters are required for it. @vexorian please give your help and feedback for me. Thanks!

UPD1: I found a sample usage in 3e9b05b.

zen0wu commented 10 years ago

Yes, that actually is a good choice. We can split the contest render apart from the string. @vexorian What do you think?

vexorian commented 10 years ago

Sorry I didn't notice this before.

contest category renderer is included in string because lazyness.

I have been considering to make it whole renderer. It could also use more parameters too. Like separating TCO category by year.