Talesoft / tale-jade

A complete and fully-functional implementation of the Jade template language for PHP

Home Page:http://jade.talesoft.codes

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Boolean attribute issues

jaydenseric opened this issue · comments

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.

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.

Is this issue resolved?

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 :)