Module: Roy::Render::InstanceMethods

Defined in:
lib/roy/render.rb

Instance Method Summary collapse

Instance Method Details

#render(engine, view_or_string, params = {}, &block) ⇒ Object

Render the given template or string with the selected engine.

Views are looked for inside the roy.conf.views directory. Files should have an extension matching the selected engine. If you want to use sub-directories, you have to use the :“subdir/file.ext” syntax.

Parameters:

  • engine (Symbol)

    the name of the rendering engine. Must be supported by Tilt.

  • view_or_string (Symbol)

    a template file.

  • view_or_string (String)

    a template string.

  • params (Hash) (defaults to: {})

    locals for Tilt::Template#render.

  • block (Proc)

    a block to execute when using yield in the template.

See Also:



83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/roy/render.rb', line 83

def render(engine, view_or_string, params={}, &block)
  options = conf.render || {}
  template = case view_or_string
    when Symbol
      file = [view_or_string.to_s, engine].map(&:to_s).join('.')
      dir = conf.views || 'views'
      Tilt.new(File.join(dir, file), nil, options)
    else
      Tilt[engine].new(nil, nil, options) { view_or_string.to_s }
    end

  template.render(app, params, &block)
end