Module: Padrino::Helpers::RenderHelpers
- Defined in:
- lib/vendored-middleman-deps/padrino-helpers-0.11.2/lib/padrino-helpers/render_helpers.rb
Overview
Helpers related to rendering within templates (i.e partials).
Instance Method Summary collapse
-
#partial(template, options = {}) ⇒ String
(also: #render_partial)
Render a partials with collections support.
Instance Method Details
#partial(template, options = {}) ⇒ String Also known as: render_partial
Note:
If using this from Sinatra, pass explicit :engine
option
Render a partials with collections support
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/vendored-middleman-deps/padrino-helpers-0.11.2/lib/padrino-helpers/render_helpers.rb', line 34 def partial(template, ={}) .reverse_merge!(:locals => {}, :layout => false) path = template.to_s.split(File::SEPARATOR) object_name = path[-1].to_sym path[-1] = "_#{path[-1]}" explicit_engine = .delete(:engine) template_path = File.join(path).to_sym raise 'Partial collection specified but is nil' if .has_key?(:collection) && [:collection].nil? if collection = .delete(:collection) .delete(:object) counter = 0 collection.map { |member| counter += 1 [:locals].merge!(object_name => member, "#{object_name}_counter".to_sym => counter) render(explicit_engine, template_path, .dup) }.join("\n").html_safe else if member = .delete(:object) [:locals].merge!(object_name => member) end render(explicit_engine, template_path, .dup).html_safe end end |