From: Jonathan Leighton Date: 2006-02-17T03:51:01+09:00 Subject: Re: XML Builder - why? On Fri, 2006-02-17 at 02:50 +0900, mental@rydia.net wrote: > Quoting eastcoastcoder@gmail.com: > > > The reason I'm asking is that I see that a lot of bright, > > experienced Ruby programmers use it, and I'm wondering if I'm > > missing something or not. > > Perhaps because it's straight Ruby code -- you can apply the same > sorts of transformations/refactorings to your templates as you can > the rest of your coe. Personally I use the two in different situations. Generally I prefer to just use ERb -- I'm not especially afraid of angle brackets or anything like that, however, in some circumstances Builder is so much more sensible. For example, I'm working on a Rails application at the moment which has a particular item of data organised as a tree structure. To display this tree structure I obviously need to use a recursive method. At first I tried to do this with just plain HTML code, but it soon got very messy with strings all over the place. I also wanted indentation so the generated source code was readable, which meant passing an indentation width to the recursive function as an argument... it was all very messy. Anyway, I refactored this with Builder, which handled the indentation for me and made the code a LOT more clean and readable because I no longer had strings and angle brackets left right and centre. I'd say the above is a very logical use of Builder, although I would agree with you that using it for a *WHOLE* HTML page is going a little too far. I guess at the end of the day though it comes down to preference. Also, it goes without saying that for true XML pages (as opposed to HTML), Builder is far, far easier as it helps you keep pages well-formed and neatly laid out. -- Jonathan Leighton http://turnipspatch.com/ | http://jonathanleighton.com/ | http://digital-proof.org/