Module: Noventius::ColumnsHelper

Defined in:
app/helpers/noventius/columns_helper.rb

Instance Method Summary collapse

Instance Method Details

#class_for_column_header(column) ⇒ Object



27
28
29
30
31
32
33
34
35
# File 'app/helpers/noventius/columns_helper.rb', line 27

def class_for_column_header(column)
  css_class = if column.is_a?(Column)
                'column-header'
              elsif column.is_a?(ColumnsGroup)
                'column-group-header'
              end

  [column.html_options[:class], css_class].compact.join(' ')
end

#column_table_header_tag(column) ⇒ Object



5
6
7
8
9
10
11
12
# File 'app/helpers/noventius/columns_helper.rb', line 5

def column_table_header_tag(column)
  options = column.html_options.deep_merge(colspan: column.html_options.fetch(:colspan, 1),
                                           rowspan: column.html_options.fetch(:rowspan, 1),
                                           class:   class_for_column_header(column),
                                           data:    data_for_column_header(column))

  (:th, column.label, options)
end

#data_for_column_header(column) ⇒ Object



37
38
39
40
41
42
43
# File 'app/helpers/noventius/columns_helper.rb', line 37

def data_for_column_header(column)
  if column.is_a?(Column)
    { type: column.type }
  elsif column.is_a?(ColumnsGroup)
    {}
  end
end

#header_columns_for_level(columns, level) ⇒ Object



18
19
20
21
22
23
24
25
# File 'app/helpers/noventius/columns_helper.rb', line 18

def header_columns_for_level(columns, level)
  if level == 0
    columns
  else
    columns.select { |column| column.is_a?(ColumnsGroup) }
      .flat_map { |column| column.columns_for_level(level) }
  end
end

#number_of_header_levels(columns) ⇒ Object



14
15
16
# File 'app/helpers/noventius/columns_helper.rb', line 14

def number_of_header_levels(columns)
  columns.map(&:depth).max
end