generic, non web based templating engine?

M

Michael Campbell

Is there a generic templating engine for ruby, a la Freemarker for
Java? What I'm looking for is something that can take a ruby "model"
(object graph, hashes, lists, etc.), a template, merge the 2 and spit
out the result.

I'd like this *NOT* specifically for Web usage; that is, it doesn't
take .rhtml, or any html necessarily, doesn't need to be run as part
of mod_ruby inside apache, etc., and ideally would be pure ruby.

I like the erb syntax, and would love to have the full power of ruby
inside the template, if possible. Something like OGNL is for java...

A quick glance at rubyforge and RAA didn't yield much, but I'm
probably missing something.

Or, failing that, a reason I'm obviously overlooking as to why
something like this isn't necessary and what to do instead.

Thanks
 
A

Austin Ziegler

Is there a generic templating engine for ruby, a la Freemarker for
Java? What I'm looking for is something that can take a ruby "model"
(object graph, hashes, lists, etc.), a template, merge the 2 and spit
out the result.

Look at the work in Ruwiki's templating engine. It's based on the RDoc
templating engine. Both work well with web pages but are not
restricted to web pages. The Ruwiki modifications to that engine are
perhaps more appropriate to non-webpage items because I did some work
to make sure that single-line replacements work very well.

It should be extractable, but I haven't taken the time to do so as a
separate download.

-austin
 
J

James Edward Gray II

Is there a generic templating engine for ruby, a la Freemarker for
Java? What I'm looking for is something that can take a ruby "model"
(object graph, hashes, lists, etc.), a template, merge the 2 and spit
out the result.

I'd like this *NOT* specifically for Web usage; that is, it doesn't
take .rhtml, or any html necessarily, doesn't need to be run as part
of mod_ruby inside apache, etc., and ideally would be pure ruby.

I like the erb syntax, and would love to have the full power of ruby
inside the template, if possible.

ERb is a standard Ruby library and can be used for anything (not just
HTML), so if that's what you want, you can have it. :)

James Edward Gray II
 
A

Alex Fenton

Michael said:
Is there a generic templating engine for ruby, a la Freemarker for
Java? What I'm looking for is something that can take a ruby "model"
(object graph, hashes, lists, etc.), a template, merge the 2 and spit
out the result.

Perhaps PageTemplate:
http://rubyforge.org/projects/pagetemplate/

mature; stricter separation of code and template in that it doesn't involve embedding any ruby code in templates and doesn't even allow any parameter passing to loop functions. good if that's the sort of templating you want.

alex
 
K

Kirk Haines

Is there a generic templating engine for ruby, a la Freemarker for
Java? What I'm looking for is something that can take a ruby "model"
(object graph, hashes, lists, etc.), a template, merge the 2 and spit
out the result.

I'd like this *NOT* specifically for Web usage; that is, it doesn't
take .rhtml, or any html necessarily, doesn't need to be run as part
of mod_ruby inside apache, etc., and ideally would be pure ruby.

I like the erb syntax, and would love to have the full power of ruby
inside the template, if possible. Something like OGNL is for java...

You can just use erb. It doesn't have to be used for web things, if you like
the syntax.

There are a bunch of other plain old templating packages out there. Given
what you describe, maybe xtemplate or amrita2 might interest you? Kwartz is
interesting.

I also use IOWA for generic content generation. On demand reports, CSV files
for import into Excel, and customized email generation, primarily, but that's
probably not what you want.


Kirk Haines
 
S

Sean O'Halpin

I like the erb syntax, and would love to have the full power of ruby
inside the template, if possible. Something like OGNL is for java...
If you like erb, why not use it? ;)

Here's an example to get you started:

require 'erb'

def do_erb(str, erb_binding, trim_mode =3D '%')
str.untaint
erb =3D ERB.new(str, $SAFE, trim_mode)
erb.result(erb_binding)
end

class Foo
attr_accessor :greeting
end

foo =3D Foo.new
foo.greeting =3D "Hello"
template =3D <<EOT
<%=3D greeting %> from simple erb template
% 1.upto(10) do |i|
item <%=3D i %>
% end
EOT

puts do_erb(template, foo.instance_eval{binding})

--- OUTPUT ---
Hello from simple erb template
item 1
item 2
item 3


Regards,

Sean
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top