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
--
I tend to view "truly flexible" by another term: "Make everything
equally hard". -- DHH
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
--
Austin Ziegler * halos...@gmail.com
* Alternate: aus...@halostatue.ca
>
> 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
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
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
Here's an example to get you started:
require 'erb'
def do_erb(str, erb_binding, trim_mode = '%')
str.untaint
erb = ERB.new(str, $SAFE, trim_mode)
erb.result(erb_binding)
end
class Foo
attr_accessor :greeting
end
foo = Foo.new
foo.greeting = "Hello"
template = <<EOT
<%= greeting %> from simple erb template
% 1.upto(10) do |i|
item <%= 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