jdiamond / Nustache

Logic-less templates for .NET
MIT License
596 stars 125 forks source link

Add integer support in the method IsTrusthy() #133

Closed aloisdg closed 6 years ago

aloisdg commented 6 years ago

Hello,

I would like to add integer support to IsTrusthy like this:

if (value is int)
{
    return (int)value != 0;
}

Example of use:

public static void Main()
{
    Console.WriteLine(Render.StringToString(@"
    {{#if count}}q{{count}}q{{/if}}
    {{#if count2}}q{{count2}}q{{/if}}", new { count = 1, count2 = 0 }));
}

output would be

    q1q

Try it Online!

I am willing to write the PR. @Romanx, If I can help in any way, fell free to ping me.

Cheers,

Romanx commented 6 years ago

Hi there,

Thanks for the issue and PR. I'm going to have to think about accepting this since Nustache is mainly in maintenance mode since most of my time has been taken up with it's replacement Stubble. This also seems to be missing the same truthy check for int's however provides a way to add to the checks in a structured manner.

The main reason for having to think about this is that it may break people's existing templates when they update. It may be worth doing a minor version to fix this since the change is minor and as long as we clearly document the change hoepfully we shouldn't cause too many issues.

aloisdg commented 6 years ago

I understand the problem. No problem, there is no urge. I made a custom C# helper to handle the case for now. I will close the issue. Fill free to open it again, if you made the change.

Las time I checked Stubble, the v1 wasn't ready. Now, I think I should check it again. Is there a guide to switch from Nustache to Stubble? Is a guide even needed?

Thank you for your work on both project by the way.

Romanx commented 6 years ago

Hey @aloisdg,

The migration should be as simple as dropping your templates in provided they are standard mustache templates. If you're using helpers or custom tags there's still some work that has to be done. I'm currently working on a helpers extension for stubble much like the Nustache one but as more of an opt-in functionality.

You should find it quite a bit faster and .net core compliant. If you do try it out please feel free to open any issues if you run into things not well documented. Either way i'll let you know if i decide to make the leap on this change.

Thanks,

aloisdg commented 6 years ago

Hi!

We use a small dozen of homemade template, so I think we will not make the move for now.

Thank you for the reply,

Cheers :)