Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a case statement in Haml-Coffee?

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.

like image 252
Blacksad Avatar asked Feb 16 '12 15:02

Blacksad


People also ask

What is case in Ruby?

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 ...]

What is a Hamlc file?

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).


2 Answers

Before the question was edited, it's main phrase had been:

Is there a case statement in HAML?

The answer is: in vanilla Haml there indeed is case!

%p
  - case 2
  - when 1
    = "1!"
  - when 2
    = "2?"
  - when 3
    = "3."
like image 138
Vadym Tyemirov Avatar answered Oct 21 '22 19:10

Vadym Tyemirov


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.

like image 1
Chuck Avatar answered Oct 21 '22 19:10

Chuck