From: jason r tibbetts Date: 2004-01-17T05:31:34+09:00 Subject: Re: HTML templating that works in more than one language? Quoting messju mohr : > On Fri, Jan 16, 2004 at 11:46:14PM +0900, Lothar Scholz wrote: > > Hello Ruby, > > > > Friday, January 16, 2004, 4:29:56 AM, you wrote: > > > > RB> Do you think a Ruby class could ever parse Smarty templates, > > RB> including basic 'each' logic like this:? > > RB> http://smarty.php.net/manual/en/language.function.foreach.php > > > > RB> Any other advice appreciated. > > RB> This is just for HTML templates, that need logic and loops, > > RB> but we might have a project that uses both Ruby and PHP, > > RB> and of course we don't want to re-write HTML templates > > RB> for each. > > > > > > I doubt that this is usefull because you must embedd a complete > > php interpreter in ruby. > > smarty converts templates written in it's own language to php-code and > runs this php-code. there is no php-code in a smarty-template. > > if a ruby class converts the same template to ruby-code no > php-interpreter is needed. > > but smarty was written with 100% php in mind. the structures may not > map that nicely to ruby. but i'm sure it's possible if somebody want > to put the effort in it. And it wouldn't have to be that much effort, especially if the OP's suggestion (foreach) is an indication of the complexity. In fact, the example that's listed on the OP's link is a dead-simple mapping to Ruby: Smarty: {foreach name=outer item=contact from=$contacts} {foreach key=key item=item from=$contact} {$key}: {$item}
{/foreach} {/foreach} Ruby: contacts.each() do | contact | contact.each_pair() do | key, item | puts "#{ key }: #{ item }
" end end In fact, if this is as tough as it gets, writing a Ruby interpreter for Smarty's syntax should take no time at all, even for a beginner in the language (like me). -- jason :wq ___________________________________________________________ This mail sent using ToadMail -- Web based e-mail @ ToadNet