DSL Support for Brail
First things first, Harris Boyce III has done all the work, my sum contribution to this feature has included some wild cheering from the side lines.
That said, this is one cool feature. Let us explore it.
There are a lot of people who consider anything resembling <html> tags to be a mess, associate them with ASP Classic mistakes, and reject them out of hand. I think that this is a mistake, but I gave up changing the whole world overnight, now I have busy formulating three steps plans that takes a week...
At any rate, consider this output:
<html> <body> <table> <tr> <th>Names</th> </tr> <tr> <td>Ayende</td> </tr> <tr> <td>Rahien</td> </tr> </table> </body> </html>
How would we generate this output using Brail? The classic approach is:
<html> <body> <?brail component Grid, {"source": names}: section header: output "<tr><th>Names</th><tr>" end section item: output "<tr><td>${item}</td><tr>" end end
?> </body> </html>
This works, but it not really Jump-Up-And-Down-All-Excited code. And, of course, some people faint dead away from having to deal with raw HTML, "Give me my components or give me death!"
Now, here is the DSL way of doing it:
<?brail dsl Html: body: component GridComponent, {"source" : names}: section header: tr: th: text "Names" end end end section item: td: text item end end end end end ?>
And this baby produces the same output as the previous one.
Now, you are probably aware that I am not really fond of raising the abstraction level needlessly, so why is this a good thing? Well, because it means that you can now do stuff like this:
dsl.Register(atom) dsl: feed: title: div: text "some content" end end end end
And it will be able to produce semantically correct ATOM feed. (To be exact, it would be if we had an AtomExtension implementation to the new IDslLanguageExtension interface, which we currently don't have).
There are some quirks in the implementation, but it is a very cool direction to go to.
Comments
Nice! And I see it is already in the trunk, I will have to play with that later today!
Still not as nice as haml:
http://haml.hamptoncatlin.com/
If i worked in monorail i would definitely create a haml view engine. And sass too
Given the fact, that html and body tags are usually part of the layout and not of the view itself, the first example is rather strange, as the bulk HTML generation is already done in a component (Grid).
Second, when I remember how much pain it is to generate a simple link with MonoRails helper, I'm fine with HTML most of the time, but as you said, there are people who start shivering when their eyes catch angled brackets...
You can use it with the layout as well, and the tests has a sample of using that.
I just wanted to show a complete example
What about attributes?
I want to like Monorail / Brail / Boo, but I just don't see the value.
I don't want to spend another n cycles learning a new programming language that is off the beaten path and seems to be champtioned by rebellious malcontents. Especially when new things that I am burning valuable time learning seem to obsolete the whole rationale behind Boo itself anyway. Things like inferred delegates, things like type inference, I'm reading the "Boo Manifesto" and it seems like this stuff has already been address by MS in .NET 3.5
Please convince me I'm wrong? I must be missing something, but what?
I take offense at that, to tell you the truth.
If you think that .Net 3.5 gives you all of that, feel free to use that, I have looked at that, and I am not seeing the option to make it work with the flexibility that I need to have. C# 3.0 has a few crumbles of this stuff, Boo has boat loads of it, and it is a significant difference.
Sorry, no offense intended at all and I didn't mean that to be written that way. I was just trying to make an observation (using the observer pattern) and didnt express myself well (I will try expression blend)
I think the main fun of this is on xml generation. I agree with Ayende that in most cases HTML does not require such hassle. But in generating hierarchical document like xml, dsl like this has a lot of value. The fact is such script is way more easy to understand and use than using XmlWriter stuff.
By the way, El, have you seen rxml from RoR? I think if you read that before you would pick up what Ayende said easier on this particular example.
My magic 8-ball says I will create a FormBuilder dsl with this.
Comment preview