Module: Roda::RodaPlugins::RenderEach::InstanceMethods
- Defined in:
- lib/roda/plugins/render_each.rb
Constant Summary collapse
- EMPTY_STRING =
''.freeze
Instance Method Summary collapse
-
#render_each(enum, template, opts = {}) ⇒ Object
For each value in enum, render the given template using the given opts.
Instance Method Details
#render_each(enum, template, opts = {}) ⇒ Object
For each value in enum, render the given template using the given opts. The template and options hash are passed to render
. Additional options supported:
- :local
-
The local variable to use for the current enum value inside the template. An explicit
nil
value does not set a local variable. If not set, uses the template name.
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/roda/plugins/render_each.rb', line 35 def render_each(enum, template, opts={}) if as = opts.has_key?(:local) as = opts[:local] else as = template.to_s.to_sym end if as opts = opts.dup if locals = opts[:locals] locals = opts[:locals] = locals.dup else locals = opts[:locals] = {} end end enum.map do |v| locals[as] = v if as render(template, opts) end.join end |