stencilproject / Stencil

Stencil is a simple and powerful template language for Swift.
https://stencil.fuller.li
BSD 2-Clause "Simplified" License
2.34k stars 223 forks source link

Range variables #179

Closed ilyapuchka closed 6 years ago

ilyapuchka commented 6 years ago

This PR introduces new syntax for for loops - {% for i in a to b %}. a to b will produce a range variable which will render itself as closed range a...b. Values can be number literals or context variables, they will be resolved while rendering range variable.

AliSoftware commented 6 years ago

I suggest for i from a to b instead?

ilyapuchka commented 6 years ago

I was thinking about that, but we already use in and I didn't want to create another variation for this syntax. After this is merged we may extend it to allow use of {% if i in a to b %}, where in is an operator and not just separator like in for. So it will feel more consistent between those two tags if we use in, I think. But I have no problems with doing it with from.

AliSoftware commented 6 years ago

Btw why use the init(uncheckedBounds:)? Can't we use from...to directly?