Class: DisplayFor::Builder::View

Inherits:
ResourceBase show all
Defined in:
lib/display_for/builder/view.rb

Instance Attribute Summary collapse

Attributes inherited from ResourceBase

#resource

Attributes inherited from Base

#html_options, #namespace, #resource_class

Instance Method Summary collapse

Methods inherited from ResourceBase

#default_actions, #initialize

Methods inherited from Base

#action, #attribute, #html, #initialize

Constructor Details

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

Instance Attribute Details

#templateObject (readonly)

Returns the value of attribute template.



4
5
6
# File 'lib/display_for/builder/view.rb', line 4

def template
  @template
end

Instance Method Details

#build_actionsObject



22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/display_for/builder/view.rb', line 22

def build_actions
  result = []

  @actions.each do |action|
    result << action.content(resource)
  end

  (:tr) do
    (:td, result.join("&nbsp;").html_safe, :colspan => 2)
  end
  
end

#build_headerObject



6
7
8
9
10
11
12
13
# File 'lib/display_for/builder/view.rb', line 6

def build_header
  result = ''

  result << (:th, "Attribute", :class => "col_attribute")
  result << (:th, "Value", :class => "col_value")

  (:thead, (:tr, result.html_safe)) << "\n"
end

#build_row(attribute) ⇒ Object



15
16
17
18
19
20
# File 'lib/display_for/builder/view.rb', line 15

def build_row(attribute)
  result = ''.html_safe
  result << (:th, attribute.label(resource_class))
  result << (:td, attribute.content(resource))
  (:tr, result.html_safe)
end

#to_sObject



35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/display_for/builder/view.rb', line 35

def to_s
  result = build_header
  
  @attributes.each do |attribute|
    result << build_row(attribute)
  end
  
  result << build_actions

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