Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I make a haml-coffee closure which spans multiple lines?

I am trying to add a small amount of logic to one of my templates (please don't scold me on the faults of putting logic in the view) and am having a hard time getting the correct hamlc syntax.

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

The straight up coffeescript would look like:

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

I'm trying:

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

and am getting some hogwash about:

Block level too deep in line undefined

Any ideas? TIA, Billy

like image 954
Billy Avatar asked Nov 14 '22 04:11

Billy


1 Answers

I was able to get this to work by putting the closure on the same line:

- for artwork in artworks
  - unless _.find(cart_items, (ci) -> ci.id == artwork.id)
    - alert 'not in the cart'
like image 144
Billy Avatar answered Dec 31 '22 20:12

Billy