Talesoft / tale-jade

A complete and fully-functional implementation of the Jade template language for PHP
http://jade.talesoft.codes
MIT License
88 stars 10 forks source link

Official Jade has different whitespace handling #89

Closed lensco closed 8 years ago

lensco commented 8 years ago

Considering this:

span foo
| bar

The offical Jade engine compiles this to:

<span>foo</span>bar

While Tale Jade gives me this (regardless of the pretty output setting):

<span>
  foo
</span>
bar

So Tale Jade makes it rather hard to have the two parts joined without a space. One of the reasons I love Jade is that it always flattens whitespace, and you have to explicitly add spaces if you want them.

TorbenKoehn commented 8 years ago

This is true. I implemented that in order to keep things like

a(href='#')
    i.fa.fa-fw.fa-gear
    | Some Title

working correctly (Fucken inline-block auto-spacing...sometimes it makes sense, sometimes it's pretty annoying (e.g. navs)). The pretty-output works fine, what Tale Jade does is adding a space in front of such elements on purpose when not in pretty mode.

Any ideas for a way to have both possibilities? I'd not put it into an option for the compiler, since it restricts you globally.

I'd go for some kind of operator you put in front or at the end of something.

TorbenKoehn commented 8 years ago

How about we use Node.js Jade's / operator to force /-style closing.

span/ foo
| bar

Tale Jade does that automatically with doctype-handling and a set of options.

Using it would avoid the auto-spacing. We could also make it activate auto-spacing.

lensco commented 8 years ago

What I do in regular Jade when I want a space is either 2 spaces after the pipe character:

span foo
|  bar

Or like this:

span foo
= ' '
| bar

In the end it's a personal preference, but I quite like the default behavior of stripping whitespace. And since you're going for a complete port of Jade, I would expect them to behave the same?

TorbenKoehn commented 8 years ago

Yep, that's exactly what I want to achieve, that's why the default behaviour will be changed to stripping whitespaces completely. I will patch it in this weekend. There will be no option and no new operator.

Sometimes you miss the forest for the trees, I actually didn't think once about just adding a damn space after the pipe.

Thank you :)


Meanwhile, feel free to use str_replace('> ', '', $phtml) as a quick fix :)

lensco commented 8 years ago

👌🏼

TorbenKoehn commented 8 years ago

I removed automatic space-insertion in 83eee44f49ec0550cc2899b2dfb06a907e0b6ef5, I guess you can test it already, the release will come soon (I will implement some more fixes first)

TorbenKoehn commented 8 years ago

1.4.3 is released now, can you check if this is fixed for you please?

lensco commented 8 years ago

Cool. The whitespace is stripped now, but the double space trick doesn't work?

TorbenKoehn commented 8 years ago

Okay, I re-released 1.4.3

You might need to clear your composer cache and delete your vendor directory.

Please try again :)

lensco commented 8 years ago

Yes, works now, thanks. But it seems setting the cache path no longer works? I have this, yet it still renders them to ./cache?

$renderer = new Jade\Renderer([
    'paths' => [__DIR__.'/build/views']
]);
TorbenKoehn commented 8 years ago

The paths variable is for the include paths of the jade files, to set the cache path use cache_path or cache_dir (I prefer path, symfony prefers dir, that's why it allows both :))

lensco commented 8 years ago

Right. All good now!