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

Boolean attribute issues #122

Open jaydenseric opened 8 years ago

jaydenseric commented 8 years ago

It seems Tale Jade does not render boolean attributes smart like Pug does.

button(disabled=true)
button(disabled=false)

Renders:

<button disabled="true"></button>
<button disabled="false"></button>

While:

button(disabled=#{true})
button(disabled=#{false})

Crashes.

button(disabled=(true))
button(disabled=(false))

And:

- $disabled = true;
button(disabled=$disabled)
- $disabled = false;
button(disabled=$disabled)

Both render:

<button disabled="1"></button>
<button></button>

Ideally, specifying true or false would render:

<button disabled></button>
<button></button>

In my component mixins I am resorting to the rather verbose:

- $disabled = false;
button(disabled=($disabled ? 'disabled' : false))

To render:

<button disabled="disabled"></button>
<button></button>

According to the HTML5 spec, boolean attributes should only ever be valueless or contain the exact attribute to indicate true, or contain an empty string or be omitted to indicate false.

TorbenKoehn commented 8 years ago
button(disabled=#{true})
button(disabled=#{false})

These crash in Pug, too, as they are syntactially wrong. Interpolation is for strings

button(disabled="#{true}")
button(disabled="#{false}")

http://sandbox.jade.talesoft.codes/id-57ceaa51238bc.html

The stated behavior already works when using Jade without expressions.

a(disabled)

It behaves according to HTML standards http://sandbox.jade.talesoft.codes/id-57cea98756cf7.html http://sandbox.jade.talesoft.codes/id-57cea99a0b220.html http://sandbox.jade.talesoft.codes/id-57cea9a4d5c4f.html

It's controlled with the self_repeating_attributes-option of the compiler (Array of attributes to enable self-repeating on (or rather, array boolean attributes))

What is missing is that this behavior also works on expression results.

What is in already is that

$disabled = false;
a(disabled=$disabled)

will completely omit the attribute

What is missing is that

$disabled = true;
a(disabled=$disabled)

will render <a disabled="disabled"> in XHTML-Mode and <a disabled> in HTML5-mode.

I'll make a plan to implement this.

Thank your for pointing this out.

arunrreddy commented 6 years ago

Is this issue resolved?

TorbenKoehn commented 6 years ago

Hello @arunrreddy, it's more that this library isn't maintained actively anymore.

If you're looking for a stable and fresh implementation of Jade/Pug for PHP, I suggest you take a look at Phug. It's made by @kylekatarnls, which is the author of pug-php, and me :)