Calling eruby from code?

I’ve found documentation for running eruby(1) from the command line and
for configuring Apache to handle eruby templates. Do you know how to
process templates from within Ruby code?

Just to be explicit, the idea would be for example to instantiate an
eruby template engine as a Ruby object, pass to it an eruby template as
a string, pass to it in addition a handful of Ruby objects used in the
template, and have the engine process all the stuff and, say, return
the result as a string.

Is that possible? If not, would you recommend some other framework?

fxn

···


s;$;Barcelona Perl Mongers;;$/=$||gaudi||3;map$,+=(split//)(-1)**$|++,
(split)[.11_09,1.714];$.=$!!~m~erce~;$"=y~catalunya~~,$;=y~rambles~~,$

=$/^$.;$:=$.+length,$@=$$$/$%$:,$%=$/$"-$*;print+chr($<0xA?$.
."$[$
":m:^$.:?"$.$":blush:)for($
($$%-$//$/),$%-$,$,$/,$$$,$
**$,$"
$@+$
$/,$$,$;,$*$**$,$$,$.,$$",$*$,$$$
$,$.,$"
$
,$"+$.,$$,$,-$.,$"$@+$$/,$;
$/
$
,$",$.,++$@+by_fxn)

Hi,

I’ve found documentation for running eruby(1) from the command line and
for configuring Apache to handle eruby templates. Do you know how to
process templates from within Ruby code?

You can use ERB, pure Ruby implementation of eRuby.

require ‘erb’

src = “…”
print ERB.new(src).run

ERB is bundled with 1.8.0

There are other template systems registered in RAA. Go look
http://raa.ruby-lang.org/
matz.

···

In message “calling eruby from code?” on 03/07/07, Xavier Noria fxn@hashref.com writes:

I’ve found documentation for running eruby(1) from the command line and
for configuring Apache to handle eruby templates. Do you know how to
process templates from within Ruby code?

Just to be explicit, the idea would be for example to instantiate an
eruby template engine as a Ruby object, pass to it an eruby template as
a string, pass to it in addition a handful of Ruby objects used in the
template, and have the engine process all the stuff and, say, return
the result as a string.

Is that possible? If not, would you recommend some other framework?

Yes it is possible. Take a look at the “apache/eruby-run.rb” file. This ruby
handler for rhtml files demonstrates how to do exactly what you want.

···

John Long
www.wiseheartdesign.com