[Seaside] S-Exprs

Avi Bryant avi@beta4.com
Sun, 26 May 2002 12:55:13 -0700 (PDT)


On Sun, 26 May 2002, Jim Benson wrote:

> html
> ^ #( form action: '@accept'
>  ( h1 [question] )
>  ( textarea rows: '20' cols: '80' sea:id answer  )
>  ( p (input type: submit value: 'accept' )))
>
> and things are very unhappy. My first question:
>
> How do you translate:
>
> <h1>[question]</h1>

(h1 '[question]') ... and yeah, there probably oughta be a shorthand for
that, but that breaks the orthogonality of the Sexpr parser.  Thoughts?

Note in the above that you wrote (... sea:id answer), whereas that wants
to be (... sea:id: answer).  I often make that same mistake.

> How do you translate:
>
> <form action="@accept">

(form sea:id: accept
  ...)

Although I guess what you did would work just as well, I always use
explicit sea:id attributes in S-exprs.

> <input type="submit" value="accept">

You got it right:
(input type: submit value: accept)

>Is there an easy way to get a look at what the S-Expr code translates
>into?

(IASexprParser parse: #(...)) asString

Just to be clear about how the parser operates - the first element in the
array is treated as the tag name.  Then it takes as many pairs as start
with a symbol and treats them as attribute/value.  From the first
even-numbered element that's not a symbol on, is considered the contents.

So,

#(span font: 'foo') is '<span font="foo"></span>' (note that you can use a
string as the attribute value), but #(span 'foo') is '<span>foo</span>',
and #(span font: 'foo' 'foo') is '<span font="foo">foo</span>'.