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

Per Melin per.melin@REDACTED
Thu Mar 15 19:54:05 CET 2012


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.




More information about the erlang-questions mailing list