Module: Tabledata::Rails::ViewHelpers

Defined in:
lib/tabledata/rails/view_helpers.rb

Instance Method Summary collapse

Instance Method Details

#render_tabledata(table, i18n_scope: nil) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/tabledata/rails/view_helpers.rb', line 4

def render_tabledata(table, i18n_scope: nil)
  (:table, class: "table table-striped".freeze) {
    concat(
      (:thead) {
        (:tr) {

          table.headers.each_with_index { |header_name, index|
            next unless is_column_displayed?(table.column_definition(index))

            concat(
              (
                :th,
                t(
                  i18n_head_key(
                    table.column_definition(index).accessor,
                    i18n_scope
                  )
                ),
                class: ["tabledata-header", table.column_definition(index).accessor],
              )
            )
          }
        }
      }
    ).concat(
      (:tbody) {
        table.body.each { |row|
          concat(
            (:tr) {
              row.present(:view).each_with_index { |column, index|
                column_definition = table.column_definition(index)
                next unless is_column_displayed?(column_definition)

                concat(
                  (:td, class: error_classes(row, column_definition)) {
                    concat(column)
                    concat(
                      (
                        :i,
                        "".freeze,
                        class: "error-hint icon-info-sign alert".freeze,
                        data: {toggle: "tooltip".freeze, html: true},
                        title: error_text(row, column_definition, i18n_scope),
                      )
                    ) if column_has_error?(row, column_definition)
                  }
                )
              }
            }
          )
        }
      }
    )
  }
end