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

It does not support children in expression #70

Closed hason closed 8 years ago

hason commented 8 years ago

This is valid jade syntax

ul
  - for ($i=0; $i<5; $i++)
    li

but tale-jade throws exception

Failed to compile Jade: Failed to parse Jade: The expression instruction can't have children
TorbenKoehn commented 8 years ago

You don't need to write the - in front of the for(). It's easier than HAML.

A correct for-loop in Tale Jade would look like this:

ul
  for $i = 0; $i < 5; $i++
    li

Tale Jade supports native for-loops (Notice: the official Jade-implementation doesn't)

Take a look at the result: http://sandbox.jade.talesoft.io/id-56e050a676d8e.html

hason commented 8 years ago

Yes, but this is a bug. What about an another php or twig expression?

- for article in articles if article.published is true
  li= article.title
TorbenKoehn commented 8 years ago

It's not a bug.

This is Jade, not HAML or Twig.

Take a look at this example: http://sandbox.jade.talesoft.io/id-56e0532c104f6.html

Even taking your first example, it compiles correctly (normally) http://sandbox.jade.talesoft.io/id-56e053a6375fc.html

Also, - initiates a code-token, not an expression token, so the error is probably not generated at this point.

Can you post your whole Jade-file?

Notice that you don't need - in most cases when working with Jade. It's meant as a backup when you don't find a Jade-construct that fits.

Tale Jade can handle do, while, if, unless, for, each, else\s*if, else, case and when without any prefixes. They are native control statements for the language.

The error you're getting is produced when you do something like this


h1= $someVar
    p Whatever

since the = (Which is an expression in Jade-terminology) doesn't allow child-elements of any kind.

To do that, you can always do

h1
    = $someVar
    p Whatever
hason commented 8 years ago

Sorry. I can't reproduce bug, that I reported.