Class: Grapple::Components::HtmlBody

Inherits:
HtmlComponent show all
Defined in:
lib/grapple/components/html_body.rb

Instance Attribute Summary

Attributes inherited from BaseComponent

#builder, #columns, #params, #records, #template

Instance Method Summary collapse

Methods inherited from BaseComponent

#initialize, setting

Constructor Details

This class inherits a constructor from Grapple::Components::BaseComponent

Instance Method Details

#render(*options, &block) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/grapple/components/html_body.rb', line 12

def render(*options, &block)
  options = options[0] || {}
  
  wrap_row = if options[:tr].nil?
    self.tr
  elsif options[:tr] === false
    false
  else
    options[:tr]
  end
  
  args = {}
  html = records.collect do |data|
    if wrap_row   
      args = wrap_row.call(template) if wrap_row.is_a?(Proc)
      builder.row(capture_block { block.call(data) }, args)
    else
      indent + capture_block { block.call(data) }
    end
  end
  "<tbody>\n#{html.join("\n")}\n</tbody>\n".html_safe
end