From: Dick Davies Date: 2004-05-10T20:14:59+09:00 Subject: redcloth and dynamic content I've sat down to write a data-driven webapp. Nice steep learning curve for me (I'm on my last week here so thought I'd waste it productively). So far FastCGI and PostGreSQL (this is an excuse for me to finally spend time learning SQL in detail, trolls please stfu). Few questions at the bottom of this, but it'd help to explain how I got into this mess first... [ Can I also place a hearty plug for Subversion here - I've changed designs three or four times over the weekend and renaming files/classes and nesting libs has been a dream with it. Definitely a refactoring-friendly VCS..] The db connection is wrapped in a class, Cnps, which I start up outside the fcgi mainloop, and is the only thing that is SQL savvy. The mainloop just calls methods on that class to get data on demand. It all works great - thanks to Carl and Ara for their rubygarden wiki discussions on fastcgi - but I'm coming to the stage where I have had enough of out=<<"EOO" #{cnps.champ} is winning with a score of #{cnps.score(cnps.champ)} EOO and want to use some kind of template thing. First go was erb. Works well enough, but pretty verbose for the Wiki Generation :) So plan B was to use redcloth and erb, to generate eruby from redcloth templates, store them in another class and eval them when the requests come in. Problem with *that* is that I need placeholders in the Textile for each thing Eruby can parse , so I end up with a lot of <% %> noise in the templates. (Doing it the other way round seemed hard to do, since I want to actually evaluate the dynamic tags at request time, but still preload the templates). So, Plan C. Use the ability of RedCloth to create id tags to hook up to Amrita. So now we have request comes in, fcgi decides what to display, asks a helper class to get the template, executes the template using Amrita and returns the output. the helper class is responsible for converting the requested template (textile, (blue|red)cloth, whatever) to Amrita-ready html. Problem here is that Amrita doesn't duck type at all, and it'd really like a Hash. I was hoping to have Cnps just quack like a Hash, but it isn't going to happen. Arse. So a few questions: Is there a way to delay evaluation of tags? In a 'do the simplest thing' frame of mind, is there a way to have ruby "" strings evaluated *after* construction? Amrita seems a bit musty, has it got a successor? Does Kwartz help me any? [ This would be my personal preference ] Is there a facility to extend RedCloth with custom tags? I could avoid the whole 'do a template from redcloth, then evaluate template' step that way, and create some kind of unholy crossbreed of erb/amrita with redcloth? Something like '>instance.method<' , then these tags get processed first and return *more* Textile, which finally gets converted... I'd need to do the evaluation during to_html(), but that's kind of neat. Obviously I don't expect anyone else to put up with that, but if I could add my own tag, that'd be great. I could see it having lots of uses for others too. Am I reinventing a wheel here? -- Plaese porrf raed. -- Prof. Michael O'Longhlin, S.U.N.Y. Purchase Rasputin :: Jack of All Trades - Master of Nuns