How to make a haml coffee closure that spans multiple lines?

I am trying to add a small amount of logic to one of my templates (please do not scold me about errors in the presentation of logic in the presentation), and it is difficult for me to get the correct hamlc syntax.

I iterate over a collection and want to skip elements that exist in another collection

A direct coffee pot will look like this:

for artwork in artworks
  unless _.find(cart_items, (ci) ->
    ci.id == artwork.product_code
      alert 'artwork not in cart'

I'm trying to:

- for artwork in artworks
  - unless _.find(cart_items, (ci) -> | # < multiline, right?
    ci.id == artwork.product_code
    - alert 'artwork not in cart'

and I get some garbage about:

Block level too deep in line undefined

Any ideas? TIA, Billy

+5
source share
1 answer

I managed to get this to work by placing the closure on one line:

- for artwork in artworks
  - unless _.find(cart_items, (ci) -> ci.id == artwork.id)
    - alert 'not in the cart'
+1
source

All Articles