sablierapp / theme-editor

A theme editor for Sablier
https://editor.sablierapp.dev/
GNU General Public License v3.0
2 stars 0 forks source link

GoTemplate parser doesn't recognize some functions. #1

Open ArKam opened 4 weeks ago

ArKam commented 4 weeks ago

Hi Alexis,

First of all, thanks for the editor link, it help me a lot to embed my css for the theme that I'm looking to contribute.

Now, I think I either missed something, or the GoTemplate parser doesn't support some function. Indeed, I have the following conditional function on my template:

<section class="settings">
  <h2>application settings:</h2>
  <ol>
    <li>traffic inactivity timeout duration: <span>{{ .SessionDuration }}</span></li>
    {{- range $i, $instance := .InstanceStates }}
      {{- if ( gt $instance.DesiredReplicas 1 ) }}
    <li>{{ $instance.Name }} availability model: <span>high-availability</span></li>
      {{- else }}
    <li>{{ $instance.Name }} availability model: <span>standalone</span></li>
      {{- end}}
    {{end -}}
  </ol>
</section>

This condition end up triggering an exception as follow on the editor: image

error executing template: template: base:216:23: executing "base" at : error calling gt: incompatible types for comparison

However, this condition does work within sablier itself.

acouvreur commented 3 weeks ago

Hello @ArKam

Can you show me your JSON data ?

it might be due to the JSON data numbers being strings?

ArKam commented 3 weeks ago

Hi @acouvreur, I just used the default data, but you may be right, I’ll check that out on monday.

ArKam commented 3 weeks ago

Ok, I finally had time to check that out, it seems related to the type of data used as the following kinda works (let me explain):

{{- if gt "$instance.DesiredReplicas" "1" }}

It works as the data type error message disappear and the theme does render, however, it doesn't work as, if I update the json value of DesiredReplicas with 4 for instance, it doesn't work as the renderer always choose the else path as it works in terms of "types compatibility" issue, it clearly doesn't work as the comparison doesn't match.

This is weird as gt is a int comparison function, not a string comparison one, so it should throw an error like "Unexpected data type for comparison".