I'd like to do the following in Haml-Coffee:
- case msg.type
- when "usertext"
= msg.body
- when "direct"
= msg.content.kbcontent_body
But I get an error "Reserved word "case""
I suspect it's not supported by Haml-Coffee actually.
In Ruby, we use 'case' instead of 'switch' and 'when' instead of 'case'. The case statement matches one statement with multiple conditions just like a switch statement in other languages. Syntax: case expression. [when expression [, expression ...]
An HAML file is an HTML abstraction markup language file that contains source code written in Haml language. It can be used as a replacement for the ERB (Ruby template scripts).
Before the question was edited, it's main phrase had been:
The answer is: in vanilla Haml there indeed is case
!
%p
- case 2
- when 1
= "1!"
- when 2
= "2?"
- when 3
= "3."
There isn't a case
statement in CoffeeScript. You want switch
— the case
keyword is the JavaScript equivalent of when
, and like many dropped JavaScript keywords is reserved in CoffeeScript. Also, I'm not 100% positive and don't have Haml-Coffee to test right now, but I think you'll need to indent the body of the switch.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With