From: Adam Van Den Hoven Date: 2005-09-27T07:14:25+09:00 Subject: Re: Embedded Ruby and Tag Libs I agree with DHH for the most part (I have to read it in more detail but for now, I'll grant the argument). However, he's talking about web applications that follow a MVC pattern. As it turns out, that's not the ONLY type of problem to solve with ruby. My problem is primarily one of content management. I have a client who sells widgets. They're not selling widgets online they're just doing promotional marketing pieces. Normally you'd just write the HTML directly and be done with it. However, sometimes, as a web developer, you have to write fairly complex markup in order to make things work out the way you want to. Unless you want to maintain the site yourself, a general pain in the neck, you need some mechanism to hide complexity from your clients yet allow them to edit the content themselves. In some ways this is what textile does (hiding the complexity of HTML from authors) but I need to be able to create more complex behaviors than what textile does. Actually DHH says something that I think supports my point: > Extracting complex view logic is painful: With tag libraries, it's > possible to be a good programmer and rid the views of complex logic > by extracting code and replace it by tags. That is a noble and > right path to follow. The problem is when the effort required to do > the right thing is so intense that its basically a project in > itself. Then its not something you're gently invited to do. It's a > huge barrier and easy source of procrastination ("I'll extract > later...") and guilt ("If only I had extracted sooner..."). I simply have a different view of complexity. I want to extract those things that are simple from my point of view but complex from the point of view of content authors. Adam On 26-Sep-05, at 2:53 PM, Devin Mullins wrote: > 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_table(_erbout) do |av| %> > <% 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 >> >> >> > > >