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

Tag name interpolation not working #97

Closed jaydenseric closed 8 years ago

jaydenseric commented 8 years ago

Picking up from comments in #95.

I found a comment revealing that tag name interpolation has actually been suported in Jade/Pug since at least 2013.

Here is an example of what we use it for (in JS Pug):

mixin button(tag)
  #{tag}.button&attributes(attributes)
    block

+button('a')(href='http://google.com') Link button text
+button('button') Ordinary button text

A work around would be if statements and a bit of duplication. This would restrict you to a whitelist of options though. In this usage example we only need to support two tags anyway.

TorbenKoehn commented 8 years ago

Ugh, now I have to implement it haha.

Thanks for the hint, I'll check if this is possible

jaydenseric commented 8 years ago

Rad! You're doing amazing work :)

This project is saving our bacon on a last-minute Node -> PHP refactor. If I see the chance I'll try to make some contributions.

TorbenKoehn commented 8 years ago

Official Jade can't handle #{tagName + 'def'}yzd.someItem.

Do we need it? It seems official Jade only likes #{...}-tags, without anything around it. It's easier to lex, but in reality I could do both.

What do you think?

jaydenseric commented 8 years ago

We only need the simpler Pug implementation. More thorough interpolation from what I can tell would only enhance, not break the Pug syntax so if it's not too hard it would be nice to have.

Perhaps we could raise an issue in the Pug project and see what they think.

jaydenseric commented 8 years ago

It's nice to take for granted compatibility though, maybe someone will find themselves refactoring PHP Jade components back to Pug and will hit issues.

TorbenKoehn commented 8 years ago

Too late :P

TorbenKoehn commented 8 years ago

The syntax is pretty basic, but you can use abc#{$someVar}def, abc#{$someVar}, just #{$someVar} and #{$someVar}def. Inside the {}, complete expressions (should) be allowed (including function calls etc.). Just using {} inside the {} (e.g. code blocks) should fail, the regex is too basic for that :)

I will make another re-release, so clear your composer-cache and delete the vendor directory, then update again (in like 10 minutes!)

TorbenKoehn commented 8 years ago

Also, Tale Jade contains many features that are not compatible to Node.js Jade, just the other way around is compatible :)