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



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/grapple/components/html_body.rb', line 15

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 = {}
	if records.empty? && !options[:no_rows_html].nil?
		html = ["<tr><td colspan=\"#{columns.length}\">#{options[:no_rows_html]}</td></tr>"]
	else
		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
	end
	"<tbody>\n#{html.join("\n")}\n</tbody>\n".html_safe
end