habitat-sh / habitat

Modern applications with built-in automation
https://www.habitat.sh
Apache License 2.0
2.61k stars 315 forks source link

Add string comparison helper in Handlebars #5077

Closed qubitrenegade closed 1 year ago

qubitrenegade commented 6 years ago

How to Reproduce

Attempt to compare two strings using handlebar helpers:

{{#unless "A" == "B"}}

(Syntax error)

{{#unless "a" eq "b"}}

(always evaluates statement inside unless clause)

Expected Output

{{# unless "a" eq "b"}}

Should not evaluate anything inside the "unless" clause.

More likely this would be used when comparing svc or package variables. The use case I imagined was:

{{#unless member.sys.ip == svc.me.sys.ip}}

I think this particular use case would be better solved with a different helper, but it still serves as a good example of string that we may want to compare in a plan.

Thanks!

qubitrenegade commented 6 years ago

I'm of a few minds on this. I think making it letters would be a good way to delineate between string and numeric comparison. e.g.:

I'm not sure what lt/gt would mean as far as string comparison, and maybe for string comparison it's just eq and ne (or eql and neq), because then we don't need a "less/greater than or equal to" string comparison operator (which again, I struggle to think of a sane "less than" comparison of strings... alphabetical?)

This provides good delineation from mathematic operators, e.g.:

In other languages there's been some confusion between string and numeric operator precedence, and in other languages the overloading of operators causes further confusion. I think be defining "use these to compare numbers, use these to compare strings" we provide obvious segregation between functions and their expected behavior.

Anyway, I'm mostly just thinking out loud.

adamhjk commented 6 years ago

I suspect the syntax here has to change, since we would be dealing with adding helpers that have to be functions. It would be something more like if Eq(a, b).

adamhjk commented 6 years ago

This would be tough. Something like this thread is theoretically possible, but we would need to understand the types of the values in Rust.

https://gist.github.com/pheuter/3515945

adamhjk commented 6 years ago

Now that Rust's ecosystem is more mature, if we really want a more fully featured language, we should consider Tera: https://tera.netlify.com/

christophermaier commented 6 years ago

+1 for looking into something like Tera... I've never been a huge fan of Handlebars and its limitations.

adamhjk commented 6 years ago

another option would be getting something like duktape embedded, and then using real Handlebars. It would make it easier to do dynamic extension.

jsirex commented 5 years ago

According to documentation: https://docs.rs/handlebars/1.1.0/handlebars/#built-in-helpers eq must be build-in helper. But it doesn't work: Error rendering "index.html" line 24, col 7: Helper not defined: "eq"

Lacking of basic functions in templating. Working with habitat templates makes me cry ;(

stale[bot] commented 4 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. We value your input and contribution. Please leave a comment if this issue still affects you.

qubitrenegade commented 4 years ago

I'd argue that this is still valid if not high priority...

On Sat, Apr 4, 2020 at 7:49 PM stale[bot] notifications@github.com wrote:

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. We value your input and contribution. Please leave a comment if this issue still affects you.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/habitat-sh/habitat/issues/5077#issuecomment-609115574, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADSBHCI27WKGOUSZDA64KPTRK7PRPANCNFSM4E77D36A .

jsirex commented 4 years ago

New rust handlebars library has embedded compare helpers: https://docs.rs/handlebars/3.0.1/handlebars/#built-in-helpers

stale[bot] commented 2 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. We value your input and contribution. Please leave a comment if this issue still affects you.

stale[bot] commented 1 year ago

This issue has been automatically closed after being stale for 400 days. We still value your input and contribution. Please re-open the issue if desired and leave a comment with details.