Joker / jade

Jade.go - pug template engine for Go (golang)
BSD 3-Clause "New" or "Revised" License
352 stars 36 forks source link

mixins arguments don't include the '$' dollar sign at variable instantiation when outputing std text templates #49

Open alarbada opened 1 year ago

alarbada commented 1 year ago

So, the following mixin, gotten from the tests:

//- Declaration
mixin pet(name)
  li.pet= name
//- Use
ul
  +pet('cat')
  +pet('dog')
  +pet('pig')

Converts to this:

<ul>{{ $name := "cat" }} 
    <li class="pet">{{ name }}</li>
    {{ $name := "dog" }} 
    <li class="pet">{{ name }}</li>
    {{ $name := "pig" }} 
    <li class="pet">{{ name }}</li>
</ul>

But this is not valid text template code, it needs the dollar sign, so it will result in an error.

I expected the following output:

<ul>{{ $name := "cat" }} 
    <li class="pet">{{ $name }}</li>
    {{ $name := "dog" }} 
    <li class="pet">{{ $name }}</li>
    {{ $name := "pig" }} 
    <li class="pet">{{ $name }}</li>
</ul>
alarbada commented 1 year ago

Mmm, maybe these lines: https://github.com/Joker/jade/blob/master/config.go#L33-L34

Shouldn't they be like this:

    code__buffered  = "{{ $%s }}"
    code__unescaped = "{{ $%s }}"

I see that I can change the replace behaviour at runtime, so I can deal with this situation.