Allow testing for model property values

13 views
Skip to first unread message

sanjay

unread,
Mar 29, 2012, 2:21:49 PM3/29/12
to seren...@googlegroups.com
Hi All,
I would like to have a more capable version of the "if" condition so that I can write a "switch" like statement:
div
  h3 "Posts"
  ul
    - collection @posts
      - if @type = "photo"
        - view "photo_entry"
      - if @type = "post"
        - view "post_entry"
Just testing for "truthy" values of a model property is not sufficient. I have to preprocess the model property before generating the template by creating properties like: hasPhoto, hasPost, etc.
Maybe introduce a statement like: 
- case @type = "photo"
Is there a better way to do this?
Thanks
Sanjay

Jonas Nicklas

unread,
Mar 29, 2012, 6:36:37 PM3/29/12
to seren...@googlegroups.com
The if statement is pretty deficient as is, to be honest. There isn't
even an else statement :( There's some work left to be done there for
sure. I like the idea of a case-like statement. Not sure what the
syntax should be.

/Jonas

sanjay

unread,
Mar 30, 2012, 3:05:07 PM3/30/12
to seren...@googlegroups.com
I was able to implement the case statement support quite easily.

see:

spec:

But I agree with you that it still does not handle all conditionals. My next step nix case statement but allow
the if statement to handle case like semantics in addition to "truthy" booleans:

- if @type "photo"

This is also trivial to do in a couple of lines.

Maybe longer term solution is to do something like helper utility function, but without a requirement to always return an element.

Sanjay

Jonas Nicklas

unread,
Mar 30, 2012, 10:09:44 PM3/30/12
to seren...@googlegroups.com
The limitation that helpers must return an element is there for a
reason. All that crazy auto-update magic in Serenade is very easily
broken when something strange happens. I don't think we will ever have
an API that allows helpers to circumvent this restriction, it's just
too dangerous.

/Jonas

Rodrigo Rosenfeld Rosas

unread,
Jun 26, 2012, 3:12:19 PM6/26/12
to seren...@googlegroups.com
Would it be possible to add some simple helper like below?

- ifEq @type 'special'
 .description "Some description"
Reply all
Reply to author
Forward
0 new messages