soy icon indicating copy to clipboard operation
soy copied to clipboard

Support @param syntax in templates

Open rehmsen opened this issue 6 years ago • 4 comments

The documentation for Closure Templates has examples of the param syntax:

{template .helloName}
  {@param name: string}
  Hello {$name}!
{/template}

This parser does not seem to support that though - I get:

lexical error: unrecognized character in action: U+0040 '@'

I think an older syntax for the same was to use comments:

/** 
 * @param name
 */

But that is no longer supported by some other parsers we use, and this one which does not support the new one. I think I would be great to add support for this.

I might be able to contribute something - is somebody already aware of this issue or has tried to fix it? Any pointers?

rehmsen avatar Mar 14 '19 11:03 rehmsen

When I initially wrote this project, I thought Soy was in stable maintenance mode, but it turned out that the team has continued to add features / change existing ones, and I haven't even tried to keep pace.

I'd certainly be happy to work with you on pull requests adding parity features if you're interested to work on it. In full disclosure, I also wanted to point out that there's an alternative which uses the official JS implementation on otto (a js interpreter in Go): https://code.taxi/socialworkout/soyotto. That repo also has a reference to Google's internal Go soy renderer. It looks like he's opted out of Github, but maybe @hochhaus could weigh in on if there's any interest on Google's part in open source it.

robfig avatar Mar 26 '19 12:03 robfig

Hi @rehmsen and @robfig. Glad to see interest in go closure templates. I left Google in 2008 so I can't comment on their interest level in open sourcing pure go closure templates code. If I had to guess, chances are low since we have not seen any code thus far. Unfortunately, I also can't recommend using soyotto as I am no longer maintaining it and it is not in active use for any projects (as far as I am aware).

hochhaus avatar Mar 26 '19 13:03 hochhaus

Thanks for the response, @robfig and @hochhaus. We have in the meanwhile found another work around. We are only using this library for a small development server and it was not worth it on our end to update the lexer/parser to work with the new feature. So feel free to keep this open or close it, as you see fit.

rehmsen avatar Mar 26 '19 16:03 rehmsen

For what it's worth, I've quickly hacked together non-soydoc (gonna call it 'native' from now on) parameter syntax in templates over at https://github.com/q3k/soy/tree/q3k/non-soydoc-params .

If there's interest, I can spend a bit more time to support default parameters and generally clean this up, and send a PR.

q3k avatar Nov 11 '19 23:11 q3k