aurelia / templating-binding

An implementation of the templating engine's Binding Language abstraction which uses a pluggable command syntax.
MIT License
32 stars 26 forks source link

Support static Math calls in interpolation syntax #98

Closed MeirionHughes closed 8 years ago

MeirionHughes commented 8 years ago

I'm submitting a feature request

Add Math (global static) to the context for all string interpolations

should facilitate the use of any Math function in any interpolation: i.e.

<div>${Math.sin(Math.PI/2)}<div> would output <div>1</div>

becomes far more useful in svg though.

<line class="slice" repeat.for="i of slices" 
      x1="${cx}" x2="${cx + r *  Math.sin(i * ((Math.PI * 2) / slices)) }" 
      y1="${cy}" y2="${cy + r * -Math.cos(i * ((Math.PI * 2) / slices)) }"/>

Current behavior: Math isn't found and the interpolation fails.

Expected/desired behavior:

Math can be used by interpolation and the interpolation produces the correct output.

What is the motivation / use case for changing the behavior?

Especially useful for SVG elements that require use of sin/cos for placement; without polluting view-model with presentation variables.

Workaround

Manually add Math to view-model:

  Math:Math;
  constructor()
  {
    this.Math = Math;
  }
EisenbergEffect commented 8 years ago

We aren't going to support globals in the binding language. Suggest you use the workaround or create a binding engine hook to add Math to the view's override context.