pug-php / pug

Pug template engine for PHP
https://www.phug-lang.com
MIT License
387 stars 42 forks source link

Nest mixin attributes confused #126

Closed Riant closed 6 years ago

Riant commented 7 years ago

Hello,

I encountered an issue with the following code:

// mixin
mixin link($text)
  a(href='#')&attributes(attributes)= $text
mixin wrap_link($text)
  span&attributes(attributes)
    +link($text)

// html
+wrap_link('Hello').span

I expected to get:

<span class="span"><a href="#">Hello</a></span>

But I actually get:

<span class="span "><a href="#" class="span ">Hello</a></span>

Thanks!

kylekatarnls commented 7 years ago

Indeed, it's a mistake, the $attributes variables seems to be kept. We will fix that in the next major version (https://github.com/phug-php). Meanwhile here is a trick to fix the problem:

// mixin
mixin link($text)
  a(href='#')&attributes(attributes)= $text
mixin wrap_link($text)
  span&attributes(attributes)
    - unset($attributes)
    +link($text)

// html
+wrap_link('Hello').span
kylekatarnls commented 6 years ago

You can update to 3.0.0-alpha2, it should be fixed. Please don't hesitate to test the new pug-php 3 and give us your feedback.