scriban / scriban

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

When model has Upper case properties, Render emits empty string #33

Closed jhonnycano closed 6 years ago

jhonnycano commented 6 years ago

When model has Upper case properties, Render emits empty string.

This is the test I've done.

                var template = Template.Parse("Hello {{Name}}!");
                var result = template.Render(new { Name = "World" }); // => "Hello !" 
xoofx commented 6 years ago

It is because by default it is following a ruby like syntax for member accessor by transforming them to lower case and adding a _ previously to a change of upper case (not on the first one). So in your case only the name property is used. It is explained in the Member renamer

matbarker commented 6 years ago

This is rather unexpected and non-obvious behaviour. I would have expected that automatic member renaming would not be the default, at least for non-liquid style parsing.

matbarker commented 6 years ago

The documentation linked is also incorrect, MemberRenamerDelegate expects a string to be returned, not a MemberInfo.

xoofx commented 6 years ago

This is rather unexpected and non-obvious behaviour. I would have expected that automatic member renaming would not be the default, at least for non-liquid style parsing.

scriban is following how liquid templates are behaving by default. If you want to improve the documentation on this matter, PR welcome.

The documentation linked is also incorrect, MemberRenamerDelegate expects a string to be returned, not a MemberInfo.

Indeed, will fix that. At some point, the MemberRenamerDelegate was taking a string instead of a MemberInfo.