Class: Facades::Builders::TableBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/facades/builders/table.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(resources, tpl, options) ⇒ TableBuilder

Returns a new instance of TableBuilder.



6
7
8
9
# File 'lib/facades/builders/table.rb', line 6

def initialize(resources, tpl, options)
  @buffer = ""
  @template, @options, @resources = tpl, options, resources
end

Instance Attribute Details

#bufferObject (readonly)

Returns the value of attribute buffer.



4
5
6
# File 'lib/facades/builders/table.rb', line 4

def buffer
  @buffer
end

#optionsObject (readonly)

Returns the value of attribute options.



4
5
6
# File 'lib/facades/builders/table.rb', line 4

def options
  @options
end

#resourcesObject (readonly)

Returns the value of attribute resources.



4
5
6
# File 'lib/facades/builders/table.rb', line 4

def resources
  @resources
end

#templateObject (readonly)

Returns the value of attribute template.



4
5
6
# File 'lib/facades/builders/table.rb', line 4

def template
  @template
end

Instance Method Details

#bodyObject



41
42
43
44
45
46
# File 'lib/facades/builders/table.rb', line 41

def body
  return (:tbody, render_body) unless block_given?        
  (:tbody) do
    yield self
  end
end

#headObject



34
35
36
37
38
39
# File 'lib/facades/builders/table.rb', line 34

def head
  return (:thead, render_heading) unless block_given?        
  (:thead) do
    yield self
  end
end

#headingsObject

Get a list of all headings for the table Use the resource class’s table_headings method first, options hash next



17
18
19
20
# File 'lib/facades/builders/table.rb', line 17

def headings
  return resource_class.table_attributes if resource_class.respond_to?(:table_headings)
  [options[:headings]].flatten.compact
end

#inline!Object

Renders the table content immediately using the provided options



30
31
32
# File 'lib/facades/builders/table.rb', line 30

def inline!
  [head, body].map(&:to_s).join("\n")
end

#resource_classObject

The class for this resource



24
25
26
# File 'lib/facades/builders/table.rb', line 24

def resource_class
  resources.first.class
end