Class: SortableBy::TableHeader

Inherits:
Object
  • Object
show all
Defined in:
lib/sortable_by/table_header.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path_helper:, context:, icon:, model: nil, params: {}) ⇒ TableHeader

Returns a new instance of TableHeader.



11
12
13
14
15
16
17
# File 'lib/sortable_by/table_header.rb', line 11

def initialize(path_helper:, context:, icon:, model: nil, params: {})
  @path_helper = path_helper
  @model = model
  @params = params
  @context = context
  @icon = icon.to_sym
end

Instance Attribute Details

#contextObject (readonly)

Returns the value of attribute context.



5
6
7
# File 'lib/sortable_by/table_header.rb', line 5

def context
  @context
end

#header_htmlObject

Returns the value of attribute header_html.



6
7
8
# File 'lib/sortable_by/table_header.rb', line 6

def header_html
  @header_html
end

Instance Method Details

#capture(block) ⇒ Object



19
20
21
22
23
# File 'lib/sortable_by/table_header.rb', line 19

def capture(block)
  @html = context.capture do
    block.call(self)
  end
end

#header(attribute, label: nil) ⇒ Object



32
33
34
35
# File 'lib/sortable_by/table_header.rb', line 32

def header(attribute, label: nil)
  label ||= translated_attribute(attribute)
   :th, label
end

#sortable(attribute, label: nil) ⇒ Object



25
26
27
28
29
30
# File 'lib/sortable_by/table_header.rb', line 25

def sortable(attribute, label: nil)
   :th, class: classes_for_attribute(attribute) do
    concat(link_to_for_attribute(attribute, label))
    concat(sort_arrow_for_attribute(attribute))
  end
end

#to_htmlObject



41
42
43
# File 'lib/sortable_by/table_header.rb', line 41

def to_html
   :thead, to_row, class: 'sortable-table-header'
end

#to_rowObject



37
38
39
# File 'lib/sortable_by/table_header.rb', line 37

def to_row
  (:tr, @html)
end