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

Add Twig Compiler #69

Closed hason closed 8 years ago

hason commented 8 years ago

Great work! I would like to add a compiler for Twig, like MtHaml. Should I create a new project or PR for this repository?

TorbenKoehn commented 8 years ago

I'd suggest you wait for the 1.5 update and then we attack this!

If it's something that should be handled by Tale Jade natively, it should be a PR, if not it should be an own repository (e.g. bridges to other libraries/frameworks) So it will probably be an own repository.

If you like you can add it as an own repository and create a PR for the Readme. The API won't change with 1.5 (it will be extended, tho).

TorbenKoehn commented 8 years ago

On a second guess, can you tell me what exactly you mean?

I was about to implement a :twig and :haml filter so that you can process Twig and HAML with Tale Jade (optionally).

I don't know if this is really needed, but it is possible haha

hason commented 8 years ago

I want to create new compiler that create a Twig template. For example, the jade template

ul
  - for article in articles if article.published is true
    li= article.name

would be transformed into

<ul>
  {% for article in articles if article.published is true %}
    <li>{{ article.name }}</li>
  {% endfor %}
</ul>

Jade would be a preprocessor for Twig. Look at https://github.com/arnaud-lb/MtHaml.

TorbenKoehn commented 8 years ago

I wouldn't suggest that.

Look what Tale Jade can handle natively, without any fancy Twig-Syntax:

http://sandbox.jade.talesoft.io/id-56e144c6b1718.html

Tale Jade Block Expansion is different from official Jade's. It can handle all kinds of statements. If you need a : in the expression, you can surround the expression with brackets

if ($x ? $x : $y): if ($z): p= $something

Block Expansion works as many levels deep as you got memory and recursion limit :)

Jade is made for PHTML, it would be possible to write a Twig-compiler, but it would be the same as writing a JavaScript-transpiler that transpiles JavaScript into CoffeeScript and expects you to run the CoffeeScript haha

If you want to create that compiler, of course, it's your choice to do so and I'll support it :)

If you think Jade's syntax is more lightweight than Twig's, just use Tale Jade alone, without Twig and tell your friends to do the same ;)

TorbenKoehn commented 8 years ago

Can this be closed or do you have any further questions?

hason commented 8 years ago

I am waiting for a new version. I will create a PR.