Handlebars-Net / Handlebars.Net.Helpers

Handlebars.Net helpers in the categories: 'Boolean', 'Constants', 'Enumerable', 'Environment', 'Math', 'Regex', 'String', 'DateTime' and 'Url'.
MIT License
40 stars 15 forks source link

Question - Math comparison? #29

Closed Zulu-Inuoe closed 3 years ago

Zulu-Inuoe commented 3 years ago

Hi, this is more of a question/maybe feature request.

Do you think it'd be reasonable to implement some sort of math-based comparisons (<, <=, ==, >=, >) in the math category?

I received a requirement to apply styling on elements on a list past a certain index eg

{{#each Items}}
<div class="{{#if (Math.Greater @index 5)}}hide{{/if}}">
 ...
</div>
{{/each}}

I'm wondering if this sort of thing might be useful in a general case, given there's already other useful math functions.

Zulu-Inuoe commented 3 years ago

And for the record, one can technically achieve this right now with a little math trickery & the fact that 0 is falsy:

<div class="{{#if (Math.Max 0 (Math.Sign (Math.Subtract @index 5)))}}hide{{/if}}">
</div>

But that might be a bit too clever.

StefH commented 3 years ago

@Zulu-Inuoe , a new NuGet will be released shortly.

With: Equal, NotEqual, GreaterThan, GreaterThanEqual, LessThan, LessThanEqual

StefH commented 3 years ago

30

Zulu-Inuoe commented 3 years ago

Sorry in being late responding to this. Thank you so much!

We pulled the latest version and the math puzzle from before is now gone 😄