phug-php / phug

Phug - The Pug Template Engine for PHP
https://phug.selfbuild.fr
MIT License
62 stars 3 forks source link

Ternary operator #22

Closed y2us closed 6 years ago

y2us commented 6 years ago

Hello,

I encountered an issue with the following code:

          a()&attributes(isNestedFile ? {'href': '../account-orders.html'} : {'href': 'accountorders.html'})

But I actually get a parsing error. (1/1) ReaderException

Failed to read: Unexpected bracket } encountered, no brackets open Near: } : {'href': 'index. Line: 24 Offset: 63 Position: 914

I suspect the ternary operator " condition ? result : other_result " not being supported.

Thanks!

kylekatarnls commented 6 years ago

The ternary operator is supported. It's something wrong with the attributes &attributes but this works:

- attrs = isNestedFile ? {'href': '../account-orders.html'} : {'href': 'accountorders.html'}
p&attributes(attrs)

You can use this syntax while I inspect the problem.

y2us commented 6 years ago

Thank you very much for the great job and the tip. The work you have done with this library is very useful and amazing.

kylekatarnls commented 6 years ago

Hi, this has been fixed in the last version of the lexer. composer update should allow you to nest brakcets-objects in ternary expressions (your exact code has been used in unit tests so it must pass).