Ruby Baby wrote:
>> I am looking for a templating system for my forum
>> (http://rforum.rubyforge.org). ..  I can't use most of the templating
>> engines is that I want to make the forum multi-language, so that I can't
>> write:
>> [%if logged_in%]
>> Logged in as [%var username%]
>> [%endif%]
>> but would have to write something like
>> [%if logged_in%]
>> [%var text_logged_in_as(username)%]
>> [%endif%]
>> Does anyone know a templating system I could use?
> 
> I'm just about to do the same thing (mutli-language), and here's the solution 
> I came up with (so far)...
> 
> If your output is going to be multi-language and filled with variables, then 
> your HTML template is going to be way more template than HTML.   Like your 
> example above.
> 
> At that point, it seems smarter to shift your focus from "HTML templates to 
> put my Ruby in" to "Ruby class that puts out HTML".

The problem is that the methods generating html could end up containing
more and more of the functional core of the application, so that they
aren't easily exchangeable. But I will think about it again...

> ## QUICK UNTESTED EXAMPLE:
> 
> ## HTML_Template.rb
> class HTML_Template
> 	def initialize(lang)
> 		@lang=lang
> 	end
> 	def header(pagetitle)
> 		'<html><head><title>%s - %s</title><head><body>' % [@lang['sitename'], 
> pagetitle]
> 	end
> 	def loginbox_loggedin(username)
> 		'<div class="loginbox">%s %s</div>' % [@lang['logged_in_as'], username]
> 	end

It seems to be far more comfortable to keep things like pagetitle,
username etc. in attributes instead of local variables. It might seem
like a "dirty" coding style, but as these methods get always called with
exactly the same arguments it seems acceptable IMO (what do the Ruby
gurus think?).