Skip to content

Support each_with_index and times in instance templates#33

Merged
sbsoftware merged 1 commit intoreleases/v1.7.0from
feature/HTML-52
Feb 11, 2026
Merged

Support each_with_index and times in instance templates#33
sbsoftware merged 1 commit intoreleases/v1.7.0from
feature/HTML-52

Conversation

@sbsoftware-agent
Copy link
Copy Markdown
Collaborator

Summary

  • Extend template iterator block handling to support each_with_index and times (receiver + block), alongside existing each.
  • Ensure iterator block bodies are evaluated through the template evaluator so nested tag calls, string literals, control flow, and to_html objects render consistently.
  • Preserve block argument behavior, including omitted args for times blocks.

Changes

  • Updated src/instance_template.cr in ToHtml.to_html_eval_exp:
  • Added allowlisted handling for each_with_index blocks.
  • Added allowlisted handling for times blocks.
  • Kept each aligned with the same block-evaluation behavior and made iterator pretty-print separation independent of injected index args (so omitted block args are safe).
  • Added spec/instance_template/iterator_blocks_spec.cr:
  • each_with_index example with nested tags, literals, and if/unless.
  • times examples covering both do |i| and do ... end forms, including nested control flow.

Testing

  • Ran: crystal spec (using CRYSTAL_CACHE_DIR=/tmp/crystal-cache-html because default cache path is not writable in this environment)
  • Result: 34 examples, 0 failures

@sbsoftware sbsoftware merged commit 808c7b0 into releases/v1.7.0 Feb 11, 2026
@sbsoftware sbsoftware deleted the feature/HTML-52 branch February 11, 2026 21:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants