Converting ChangeSubject from velocity to soy

198 views
Skip to first unread message

Orgad Shaneh

unread,
May 24, 2017, 8:01:18 AM5/24/17
to Repo and Gerrit Discussion, Paladox none
Hi,

I want to convert the ChangeSubject.vm template from here to soy.

If I understand correctly, closure doesn't have local variables.

Can you suggest an alternative?

Thanks.

thomasmu...@yahoo.com

unread,
May 24, 2017, 10:48:12 AM5/24/17
to Repo and Gerrit Discussion, thomasmu...@yahoo.com
Hi, please see https://stackoverflow.com/questions/7039426/how-to-declare-local-variable-in-closure-javascript-template

Wikimedia have also converted one of it's mail templates to soy. See https://github.com/wikimedia/puppet/blob/production/modules/gerrit/files/etc/mail/ChangeSubject.soy

Though the template is pretty similar to gerrit's one.

Orgad Shaneh

unread,
May 25, 2017, 5:33:20 AM5/25/17
to Repo and Gerrit Discussion, thomasmu...@yahoo.com
Hi,


and got the following error:
ChangeSubject.soy:28: error: Unknown data key 'messageClass'.
    {switch $messageClass}
     ^
1 error

at com.google.template.soy.SoyFileSet.throwIfErrorsPresent(SoyFileSet.java:1334)
at com.google.template.soy.SoyFileSet.compileForServerRendering(SoyFileSet.java:927)
at com.google.template.soy.SoyFileSet.compileToTofu(SoyFileSet.java:845)
...

Any ideas?

thomasmu...@yahoo.com

unread,
May 25, 2017, 1:29:49 PM5/25/17
to Repo and Gerrit Discussion, thomasmu...@yahoo.com, wya...@google.com
Im not sure how to use custom variables in soy in gerrit, just was pointing to an site that said it's possible. wyatt may know how to do this.

Orgad Shaneh

unread,
May 26, 2017, 3:15:30 AM5/26/17
to Repo and Gerrit Discussion, thomasmu...@yahoo.com, wya...@google.com
That's not where the error is. The soy engine claims that messageClass is undefined.

thomasmu...@yahoo.com

unread,
May 26, 2017, 4:09:51 AM5/26/17
to Repo and Gerrit Discussion
It should probably be

{let $subjectPrefix : $messageClass}
{switch $subjectPrefix}

thomasmu...@yahoo.com

unread,
May 26, 2017, 4:11:06 AM5/26/17
to Repo and Gerrit Discussion

Orgad Shaneh

unread,
May 26, 2017, 4:39:10 AM5/26/17
to Repo and Gerrit Discussion
I found that I don't need the variable at all. Ended up with https://gist.github.com/orgads/d8a61a1c10efeb7a4fafbcb6374167c3

Thanks for your help!
Reply all
Reply to author
Forward
0 new messages