scriban / scriban

A fast, powerful, safe and lightweight scripting language and engine for .NET
BSD 2-Clause "Simplified" License
3.15k stars 350 forks source link

Why does "wrap" require a parameter when a "func" may not need one? #177

Closed deanebarker closed 5 years ago

deanebarker commented 5 years ago

Say I have an HTML construct that I put in function:

{{ func aside }}
  <aside class="whatever">
    {{ $$ }}
  </aside>
{{ end }}

I want to call it like this:

{{ wrap aside }}
  This is some content for the aside.
{{ end }}

However, this throws a parsing error because there is no extra parameter on the wrap call, even though I don't need one:

Expecting a direct function instead of the expression 'aside/variable'

Why is this? I don't need any extra parameters except what's in the wrap block itself. What I end up doing is calling it like this:

{{ wrap aside '' }}

Essentially, I pass an extra parameter as an empty string, and just don't do anything with it. But, clearly, this is hack-ish and not something I want to get in the habit of doing.

What am I not understanding here?

xoofx commented 5 years ago

Maybe that's just a bug

deanebarker commented 5 years ago

I'll leave that to you to judge, but if so, it's a fairly benign one, because there's a workaround.

But, good to know.

deanebarker commented 5 years ago

Here's the line it's coming from:

https://github.com/lunet-io/scriban/blob/master/src/Scriban/Syntax/ScriptWrapStatement.cs#L26

xoofx commented 5 years ago

Right, it's not a bug but the documentation is actually wrong as you need to add a @ before the function: wrap @caption

deanebarker commented 5 years ago

I assumed that the only thing that could go there is a function name, so what is the @ meant to represent? That makes it seem that the function name is meant to be differentiated from something else -- what would that something else be?

deanebarker commented 5 years ago

Also, this didn't seem to work. This code...

{{ wrap @aside }}

...now throws this error:

Expecting a direct function instead of the expression `FunctionAliasaside/unary expression`
xoofx commented 5 years ago

I assumed that the only thing that could go there is a function name, so what is the @ meant to represent? That makes it seem that the function name is meant to be differentiated from something else -- what would that something else be?

Not exactly, you could have a function that returns a function pointer. Maybe things got broken after I introduced function pointers.

Also, this didn't seem to work. This code...

Yeah, sorry, I don't know what's going on. I'm on a business trip for the next 2 weeks and I can't check more deeply that issue for now, unless you go into it before.

deanebarker commented 5 years ago

No worries. I have a workaround.

I did try to look into the code, but I got lost fairly quickly. Just know that I tried.

xoofx commented 5 years ago

Actually got a chance to have a look at it and it should be fixed by commit 287d936

xoofx commented 5 years ago

The fix will be available in an upcoming release