Quickstart

The simplest way to load templates is by using the Ruty::Template class:

require 'ruty'
t = Ruty::Template.new('Hello {{ username }}!')
puts r.render(:username => 'John Doe')

Outputs:

Hello John Doe!

By just using the Ruty::Template class you can’t use the powerful template inheritance system of ruty. To have that working you must load templates via a loader instance. Ruty ships two loaders, the Filesystem loader and MemcachedFilesystem loader:

require 'ruty'
loader = Ruty::Loaders::Filesystem.new(:dirname => './templates')
t = loader.get_template('index.html')
puts t.render(...)

In this example the loader wants you to save your templates in the folder called ’./templates’. For a list of supported arguments have a look at the module documentation of the loaders.

The Context

The template designers can just call functions that are safe, and just without arguments. It’s only possible to access symbol keys of hashes, or integer keys of hashes or integer indices of arrays. So it’s impossible for them to screw things up.

If you pass a custom class to the template and you want designers to call some getter functions on the class use this code:

class YourClass
  def foo
    42
  end
  def bar
    23
  end
  def delete
    # delete object here, not possible to do from the
    # template because not safe
  end
  def ruty_safe? name
    return [:foo, :bar].include?(name)
  end
end
last update: Sun Jan 21 21:43:59 UTC 2007