Skip to content

Commit

Permalink
Support index in repeat
Browse files Browse the repository at this point in the history
  • Loading branch information
tatut committed Jan 16, 2024
1 parent be00f95 commit 68f39aa
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/LiveWeb-Developer/LWDevHTMLCompiler.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ LWDevHTMLCompiler >> compileAttr: attrCode [
"If there are multiple blocks, emit code to append string."
^ String streamContents: [ :out |
out << '(String streamContents: [ :__lw_attr | '.
blocks do: [ :b | out << '__lw_attr << '; << b; << '. ' ]
out << ')'.
blocks do: [ :b | out << '__lw_attr << ('; << b; << '). ' ].
out << '])'.
].
]

Expand All @@ -96,10 +96,11 @@ LWDevHTMLCompiler >> compileContent: content [

{ #category : #compiling }
LWDevHTMLCompiler >> compileRepeat: lwRepeat tag: tagName attrs: tagAttrs with: content [
| binding |
| binding idx |
"split on first space to separate binding name and code for collection, eg. x items "
binding := lwRepeat splitOnFirst: $ .
code << '('; << binding second; << ') do: [ :'; << binding first; << ' | ';cr.
idx := tagAttrs removeKey: 'lw:index' ifAbsent: [ '__lw_index' ].
code << '('; << binding second; << ') doWithIndex: [ :'; << binding first; << ' :'; << idx; << ' | ';cr.
self compileTag: tagName attrs: tagAttrs with: content.
code << '].'; cr.
^ true
Expand Down

0 comments on commit 68f39aa

Please sign in to comment.