pug-php / pug

Pug template engine for PHP
https://www.phug-lang.com
MIT License
391 stars 42 forks source link

Extra space added when echoing value using #{} syntax. #64

Closed esiao closed 8 years ago

esiao commented 8 years ago

Hello, might be related to the other issue also but if I use this notation

'#{$bar->foo}'

The content is outputted like so 'Hello world '. It's not really problematic as I remove the space later in Javascript (the goal is to pass variables).

But when trying to concatenate to get a file url it can become problematic. Something along the lines of '#{base}/file.png' even if here I use the notation $base.'/file.png' as a workaround.

Maybe it's related to the other issue I raised? Thanks in advance, hope it's nothing too hard to fix.

kylekatarnls commented 8 years ago

This seem to only happen with prettyprint setting to true. I will try to fix it but meanwhile you can set this option to false (it can also be caused by phpSingleLine if you set it to true).

esiao commented 8 years ago

It's strange because I didn't pass any other options than the basedir to pug. And it's set to false by default for both of this options. Anyway for now my fix is to trim the variables coming from there nothing problematic and if you update it won't conflict.

kylekatarnls commented 8 years ago

Maybe it's only fixed on my dev branch (I tested it on js-phpize that will be soon merged). But are you sure your value $bar->foo does not contains any trailing spaces in the first place?

esiao commented 8 years ago

Yes if I use =$foo->bar it returns "Hello World". I did some more tests and it's actually linked to the fact it's inside the Javascript block.

So

p #{$foo->bar}/test

Will output 'Hello world/test'

But

script #{$foo->bar}/test

Will output 'Hello world /test'

kylekatarnls commented 8 years ago

Thanks a lot for this big clue. I confirm the bug, it will be fixed soon.

kylekatarnls commented 8 years ago

Fixed and merged in Version 2.4.0.