phug-php / phug

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

Parsing error using JsPhpizePhug #59

Closed BananaAcid closed 4 years ago

BananaAcid commented 4 years ago

Hello,

Since I am not sure, where this goes, I cross-posted it here: https://github.com/pug-php/js-phpize/issues/31

Working on pugjs, I get with Phug

image

and

image

[].concat, Object.keys() does not seem to work ...

Thanks!

kylekatarnls commented 4 years ago

Indeed, we don't have Object.* polyfill at all. But you can rely on PHP functions:

- tags = array_merge(tags, array_keys(attributes))

I know this make the mixin not compatible in JS env, but I would argue you should avoid having multiple ways of doing the same thing and attributes are not supposed to be used this way.

BananaAcid commented 4 years ago

Doing the php line you mentioned, I would need to change everything to PHP? It won't cross compile anymore, I believe.

kylekatarnls commented 4 years ago

It's still PHP behind to make you benefit of direct access to objects and functions of your application. We won't rewrite the whole node.js engine in PHP to make every possible JS code compatible inside pug templates. That's not the purpose. We provide basic polyfills to make simple expressions in JS syntax.

That should be enough because templates are meant to be just display and formatting, algorithm and more complex logic should be handled behind in your controllers and services. In your case you could have a function "merge_attributes_keys" doing this and implement the same function in JS to use concat. And so the template would compile in both JS and PHP env.

BananaAcid commented 4 years ago

polyfills to make simple expressions in JS syntax

I undersand, ES5/ES6 would be out of scrope.

"merge_attributes_keys" doing this and implement the same function in JS to use concat. And so the template would compile in both JS and PHP env."

Ok, this would be the solution, since "JS Style vaiables and function calls" are handled

Thank you!!