Class: DisplayFor::Builder::List

Inherits:
CollectionBase show all
Defined in:
lib/display_for/builder/list.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



17
18
19
20
21
22
23
24
25
# File 'lib/display_for/builder/list.rb', line 17

def build_actions(resource)
  result = []

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

  result.join("&nbsp;").html_safe
end

#build_row(resource) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
# File 'lib/display_for/builder/list.rb', line 5

def build_row(resource)
  result = ''
  @attributes.each do |attribute|
    result << (:span, attribute.content(resource), attribute.html_options)
  end
  result << (:span, build_actions(resource)) if @actions.any?

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

Yields:



42
43
44
45
# File 'lib/display_for/builder/list.rb', line 42

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

#to_sObject



27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/display_for/builder/list.rb', line 27

def to_s
  result = "\n".html_safe
  
  @collection.each do |resource|
    result << build_row(resource)
  end

  if @footer
    result << @footer.build_row(nil)
  end

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