meteor-jade
meteor-jade copied to clipboard
Support for case statment
It would be good if you would implement jade's case statment support
template(name='main')
case friends
when 0
p you have no friends
when 1
p you have a friend
default
p you have #{friends} friends
Actually Blaze doesn't support case statements. Since I don't want to add some runtime overhead, the jade compiler will have to internally transform the case
block in if
/else
blocks. This is similar to what is already done to transform else if
blocks here.
I often use a logic helper to mimic a case
or switch
statement:
if is field 'ok'
span OK
else if is field 'maybe'
span Maybe
else
span Nope
I've posted my logic helpers in this gist, but the is
helper could be implemented simply like this:
Template.registerHelper("is", (first, second) => first === second);
The and
helper is great for the following little trick* that works because Blaze doesn't output falsy values – so if isOk
is false, nothing happens:
span.label(class=and(isOk 'label-success'))
And I use the tern
(ternary) helper like this:
i.icon(class=tern(isFiltered 'filter' 'world')
* relying on the parenthesis syntax from dalgard:jade