SE7ENSKY / jade2php

Unlock Jade for PHP! Convert Jade templates into raw PHP templates. CLI tool and JavaScript API. Test covered.
43 stars 10 forks source link

fix dynamic classes and attributes issue #36

Closed domtra closed 8 years ago

domtra commented 8 years ago

This is a fix for the mentioned bug in the discussion of #19.

I do not know if there needs to be some extra escaping for dynamic classes. Maybe we can discuss if this is a general solution or just works in our case when we have something like

mixin mymixin()
  - foo = 'bar'
  div(class=foo)&attributes(attributes)
    block
ivankravchenko commented 8 years ago

:+1: Thank you for the contribution!

janwirth commented 8 years ago

@domtra I am currently writing a test for this and found a bug:

div(class=foo).foo&attributes(dynamicAttributes)

will compile to

<div<?php
attr_class($foo, 'foo');
?>></div><div<?php
attrs(array(
    "class" => "$foo foo"
), $dynamicAttributes);
?>></div>

Which are two div tag, the second wrong with a $-prefixed classname. @ivankravchenko I created this test so far: https://gist.github.com/FranzSkuffka/d8db91ffa1bdaeef25eecc40240d2146

I think the result should look something like this but I am not sure about the associative array comprehension of the attrs function, but it does combines attributes with identic names, right?

When we remove any of the three components .foo, class=foo or &attributes(...) in jade the output looks right as it does not add multiple classes within at attrs() call in php div(class=foo).foo&attributes(dynamicAttributes)

@domtra maybe you can look into it and add a test as well. :+1: