From: Devin Mullins Date: 2005-09-27T06:53:35+09:00 Subject: Re: Embedded Ruby and Tag Libs Hi, Adam, First, DHH's opinion on this matter might be of interest to you: http://www.loudthinking.com/arc/000408.html (DHH = The Rails Guy, btw) Second, the best way I can think of to achieve something like what you're talking about in ERB would look like this: class AvTable def initialize(out) @out = out; @side = :odd end def trow @out << %Q{} yield @out << "\n" @side = (@side == :odd) ? :even : :odd end end def av_table(out) out << "\n" yield AvTable.new(out) out << "
\n" end a = ERB.new < <% av.trow do %>...<% end %> <% av.trow do %>...<% end %> <% av.trow do %>...<% end %> <% av.trow do %>...<% end %> <% av.trow do %>...<% end %> <% end %> RHTML a.result.display Not sure how you would take care of "last", though (without writing an internal iterator for your data), but I'm no expert, and this is probably a crappy way of achieving what you're after. (I, for instance, am not a fan of passing around _erbout.) Devin Adam Van Den Hoven wrote: > Hey guys, > > I've been dabbling with ruby on and off for a year or so and recently > more often. At work we do Java development and I keep thinking that > it would be nice to be able to bring some of the stuff I designed > there into my own work, which I want to do in ruby. > > I was wondering if anyone had thought about adding something like the > Java TagLibs to ruby (I guess it would embedded ruby). In my case, it > would make long term maintenance of files MUCH easier as I can give > it to a non-technical person without much documentation. In most > cases people who don't understand programming do understand parts of > HTML markup. If I could hide what is currently inline code behind > things that look like tags, its easier to give maintenance over to > non-technical folks. > > Here's a simple example. Often you want to do tiger striping on > tables (alternate background color on each row). Because there isn't > sufficiently wide spread support for CSS2 and CSS3 selectors, you > tend to do the following: > > > > > > > > >
...
...
...
...
...
...
> > Unfortunately, if you want to add something between rows 4 and 5 you > need to reset all your classes. This can get complicated. However, if > I had a taglib I could ask my content authors to write the following: > > > ... > ... > ... > ... > ... > ... > > > And leave the generation up to the code. > > I can think of hundreds of specific tags I might create, depending on > the situation, which would make authoring content easier and would > give me better control over the rendering of a page. It could also > make writing code easier in general. It would also be useful to have > many of the tags defined in the JSTL. > > Just a thought I had. > Adam > >