Public Instance methods
render_each(enum, template, opts=(no_opts = true; optimized_template = _cached_render_each_template_method(template); OPTS))
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 |
[show source]
# File lib/roda/plugins/render_each.rb 48 def render_each(enum, template, opts=(no_opts = true; optimized_template = _cached_render_each_template_method(template); OPTS)) 49 if optimized_template 50 return _optimized_render_each(enum, optimized_template, render_each_default_local(template), {}) 51 elsif opts.has_key?(:local) 52 as = opts[:local] 53 else 54 as = render_each_default_local(template) 55 if no_opts && optimized_template.nil? && (optimized_template = _optimized_render_method_for_locals(template, (locals = {as=>nil}))) 56 return _optimized_render_each(enum, optimized_template, as, locals) 57 end 58 end 59 60 if as 61 opts = opts.dup 62 if locals = opts[:locals] 63 locals = opts[:locals] = Hash[locals] 64 else 65 locals = opts[:locals] = {} 66 end 67 locals[as] = nil 68 69 if (opts.keys - ALLOWED_KEYS).empty? && (optimized_template = _optimized_render_method_for_locals(template, locals)) 70 return _optimized_render_each(enum, optimized_template, as, locals) 71 end 72 end 73 74 enum.map do |v| 75 locals[as] = v if as 76 render_template(template, opts) 77 end.join 78 end