[erlang-questions] [ANN] Brim - HTML templating library

Bob Ippolito <>
Thu Mar 15 21:42:14 CET 2012


On Thu, Mar 15, 2012 at 11:54 AM, Per Melin <> wrote:

> I wrote:
>
> > I'd happily do away with selectors for Erlang, but I doubt I could
> create an API that would be nearly as expressive in a way that takes any
> less effort to learn.
>
> I wish I hadn't been quite so quick to make that statement.
>
>
> > E.g. "div#foo span.bar:first-child" matches any <span> with class "bar"
> that is the first child of its parent element and also a descendant of a
> <div> with id "foo".
>
> This (expressing the same rule as above) would arguably take less effort
> to learn at least:
>
>  brim:descendant(
>   brim:id(foo, brim:element(div)),
>   brim:first_child(brim:class(bar, brim:element(span)))
>  )
>
> But it is too verbose.
>
> So we are tempted to start down this road (Jack Moffitt saw it coming):
>
>  {descendant,
>  {id, foo, {element, div}}},
>  {first_child, {class, bar, {element, span}}}
>
> If either is easier to read comes down to whether you know the (small)
> grammar of selectors, I guess.
>
> We'd do away with the string parsing, and both of the above are
> composable. Double big win. But still too long I think, even if we shorten
> the keywords. On the other hand, because they are composable we would not
> have to write the full thing every time.


You could also consider going down the road of parse transforms to keep the
string syntax but get rid of the runtime string parsing.

Personally I like the CSS selector syntax. It's terse but not hard to
understand, and you already know it if you've done pretty much any
client-side web development. Even with an alternative syntax you're still
going to need to learn a subset of the same keywords (id, first_child,
etc.) which is I think much more work than picking up the grammar.

-bob
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20120315/44736ae8/attachment.html>


More information about the erlang-questions mailing list