Class: DisplayFor::Builder::View
- Inherits:
-
ResourceBase
- Object
- Base
- ResourceBase
- DisplayFor::Builder::View
- Defined in:
- lib/display_for/builder/view.rb
Instance Attribute Summary collapse
-
#template ⇒ Object
readonly
Returns the value of attribute template.
Attributes inherited from ResourceBase
Attributes inherited from Base
#html_options, #namespace, #resource_class
Instance Method Summary collapse
Methods inherited from ResourceBase
Methods inherited from Base
#action, #attribute, #html, #initialize
Constructor Details
This class inherits a constructor from DisplayFor::Builder::ResourceBase
Instance Attribute Details
#template ⇒ Object (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_actions ⇒ Object
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 content_tag(:tr) do content_tag(:td, result.join(" ").html_safe, :colspan => 2) end end |
#build_header ⇒ Object
6 7 8 9 10 11 12 13 |
# File 'lib/display_for/builder/view.rb', line 6 def build_header result = '' result << content_tag(:th, "Attribute", :class => "col_attribute") result << content_tag(:th, "Value", :class => "col_value") content_tag(:thead, content_tag(: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 << content_tag(:th, attribute.label(resource_class)) result << content_tag(:td, attribute.content(resource)) content_tag(:tr, result.html_safe) end |
#to_s ⇒ Object
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 [:class] ||= "table table-bordered table-striped #{@resource_class.to_s.underscore}-view" content_tag(:table, result, ).html_safe end |