Class: DisplayFor::Builder::Table
Instance Attribute Summary
#collection
Attributes inherited from Base
#html_options, #namespace, #resource_class, #template
Instance Method Summary
collapse
#default_actions, #initialize
Methods inherited from Base
#action, #attribute, #html, #initialize
Instance Method Details
#build_actions(resource) ⇒ Object
26
27
28
29
30
31
32
33
34
|
# File 'lib/display_for/builder/table.rb', line 26
def build_actions(resource)
result = []
@actions.each do |action|
result << action.content(resource)
end
result.join(" ").html_safe
end
|
4
5
6
7
8
9
10
11
12
|
# File 'lib/display_for/builder/table.rb', line 4
def
result = ''
@attributes.each do |attribute|
result << content_tag(:th, attribute.label(@resource_class), :class => "col_#{attribute.name}".underscore)
end
result << content_tag(:th, "Actions", :class => 'actions') if @actions.any?
content_tag(:thead, content_tag(:tr, result.html_safe)) << "\n"
end
|
#build_row(resource) ⇒ Object
14
15
16
17
18
19
20
21
22
23
24
|
# File 'lib/display_for/builder/table.rb', line 14
def build_row(resource)
result = ''
@attributes.each do |attribute|
result << content_tag(:td, attribute.content(resource), attribute.html_options)
end
result << content_tag(:td, build_actions(resource)) if @actions.any?
options = {}
options[:id] = "#{@resource_class}_#{resource.id}".underscore if resource
content_tag(:tr, result.html_safe, options) << "\n"
end
|
53
54
55
56
|
# File 'lib/display_for/builder/table.rb', line 53
def
@footer = Table.new(resource_class, [], html_options, template)
yield @footer
end
|
#to_s ⇒ Object
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
# File 'lib/display_for/builder/table.rb', line 36
def to_s
result = "\n".html_safe
@collection.each do |resource|
result << build_row(resource)
end
result = + content_tag(:tbody, result)
if @footer
result << content_tag(:tfoot, @footer.build_row(nil))
end
html_options[:class] ||= "table table-bordered table-striped #{@resource_class.to_s.underscore}-table"
content_tag(:table, result, html_options).html_safe
end
|