Class: DisplayFor::Builder::Table

Inherits:
CollectionBase show all
Defined in:
lib/display_for/builder/table.rb

Instance Attribute Summary

Attributes inherited from CollectionBase

#collection

Attributes inherited from Base

#html_options, #namespace, #resource_class, #template

Instance Method Summary collapse

Methods inherited from CollectionBase

#default_actions, #initialize

Methods inherited from Base

#action, #attribute, #html, #initialize

Constructor Details

This class inherits a constructor from DisplayFor::Builder::CollectionBase

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("&nbsp;").html_safe
end

#build_headerObject



4
5
6
7
8
9
10
11
12
# File 'lib/display_for/builder/table.rb', line 4

def build_header
  result = ''
  @attributes.each do |attribute|
    result << (:th, attribute.label(@resource_class), :class => "col_#{attribute.name}".underscore)
  end
  result << (:th, "Actions", :class => 'actions') if @actions.any?

  (:thead, (: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 << (:td, attribute.content(resource), attribute.html_options)
  end
  result << (:td, build_actions(resource)) if @actions.any?

  options = {}
  options[:id] = "#{@resource_class}_#{resource.id}".underscore if resource
  (:tr, result.html_safe, options) << "\n"
end

Yields:



53
54
55
56
# File 'lib/display_for/builder/table.rb', line 53

def footer
  @footer = Table.new(resource_class, [], html_options, template)
  yield @footer
end

#to_sObject



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 = build_header + (:tbody, result)

  if @footer
    result << (:tfoot, @footer.build_row(nil))
  end

  html_options[:class] ||= "table table-bordered table-striped #{@resource_class.to_s.underscore}-table"
  (:table, result, html_options).html_safe
end