jade icon indicating copy to clipboard operation
jade copied to clipboard

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

Open alarbada opened this issue 3 years ago • 1 comments

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 avatar Nov 25 '22 17:11 alarbada

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.

alarbada avatar Nov 25 '22 17:11 alarbada