Module: Telm::CellsHelper

Defined in:
app/helpers/telm/cells_helper.rb

Overview

Renders Core::Rendering cells as markup. One tiny method per kind, keyed off the cell's kind — the core decides what a value is, this decides only how it looks.

Instance Method Summary collapse

Instance Method Details

#telm_cell(resource, column, record) ⇒ Object



8
9
10
11
# File 'app/helpers/telm/cells_helper.rb', line 8

def telm_cell(resource, column, record)
  cell = Telm.rendering.cell(resource, column, record)
  public_send("telm_cell_#{cell.kind}", cell)
end

#telm_cell_belongs_to(cell) ⇒ Object



69
70
71
72
73
74
75
76
# File 'app/helpers/telm/cells_helper.rb', line 69

def telm_cell_belongs_to(cell)
  if cell.meta[:label]
    link_to cell.meta[:label], resource_record_path(cell.meta[:table], cell.meta[:id]),
            class: "telm-cell-assoc"
  else
    tag.span("##{cell.meta[:id]}", class: "telm-cell-assoc is-dangling")
  end
end

#telm_cell_binary(cell) ⇒ Object



57
58
59
# File 'app/helpers/telm/cells_helper.rb', line 57

def telm_cell_binary(cell)
  tag.span("BLOB · #{number_to_human_size(cell.meta[:bytes])}", class: "telm-chip is-binary")
end

#telm_cell_boolean(cell) ⇒ Object



30
31
32
33
34
35
36
# File 'app/helpers/telm/cells_helper.rb', line 30

def telm_cell_boolean(cell)
  if cell.value
    tag.span("", class: "telm-cell-bool is-true", title: "true")
  else
    tag.span("", class: "telm-cell-bool is-false", title: "false")
  end
end

#telm_cell_class(resource, column) ⇒ Object

Numeric cells right-align; everything else leads left.



14
15
16
# File 'app/helpers/telm/cells_helper.rb', line 14

def telm_cell_class(resource, column)
  cell_kind_hint(resource, column) == :number ? "is-numeric" : nil
end

#telm_cell_date(cell) ⇒ Object



48
49
50
# File 'app/helpers/telm/cells_helper.rb', line 48

def telm_cell_date(cell)
  tag.time(cell.value.strftime("%b %-d, %Y"), datetime: cell.value.iso8601)
end

#telm_cell_datetime(cell) ⇒ Object



42
43
44
45
46
# File 'app/helpers/telm/cells_helper.rb', line 42

def telm_cell_datetime(cell)
  distance = time_ago_in_words(cell.value)
  relative = cell.value.after?(Time.current) ? "in #{distance}" : "#{distance} ago"
  tag.time(relative, datetime: cell.value.iso8601, title: cell.value.utc.strftime("%Y-%m-%d %H:%M:%S UTC"))
end

#telm_cell_empty_string(_cell) ⇒ Object



26
27
28
# File 'app/helpers/telm/cells_helper.rb', line 26

def telm_cell_empty_string(_cell)
  tag.span("\"\"", class: "telm-cell-empty", title: "empty string")
end

#telm_cell_enum(cell) ⇒ Object



38
39
40
# File 'app/helpers/telm/cells_helper.rb', line 38

def telm_cell_enum(cell)
  tag.span(cell.value, class: "telm-chip is-enum")
end

#telm_cell_json(cell) ⇒ Object



52
53
54
55
# File 'app/helpers/telm/cells_helper.rb', line 52

def telm_cell_json(cell)
  compact = cell.value.to_json
  tag.span(cell.value.is_a?(Array) ? "[…]" : "{…}", class: "telm-chip is-json", title: compact.truncate(200))
end

#telm_cell_null(_cell) ⇒ Object



22
23
24
# File 'app/helpers/telm/cells_helper.rb', line 22

def telm_cell_null(_cell)
  tag.span("", class: "telm-cell-null", title: "NULL")
end

#telm_cell_number(cell) ⇒ Object



61
62
63
# File 'app/helpers/telm/cells_helper.rb', line 61

def telm_cell_number(cell)
  tag.span(cell.value.to_s, class: "telm-cell-number")
end

#telm_cell_redacted(_cell) ⇒ Object



18
19
20
# File 'app/helpers/telm/cells_helper.rb', line 18

def telm_cell_redacted(_cell)
  tag.span(Core::Redaction::MASK, class: "telm-cell-redacted")
end

#telm_cell_string(cell) ⇒ Object



65
66
67
# File 'app/helpers/telm/cells_helper.rb', line 65

def telm_cell_string(cell)
  tag.span(cell.meta.fetch(:preview, cell.value), class: "telm-cell-string")
end

#telm_detail_cell(resource, column, record) ⇒ Object

---- Record-page variants: full text, expandable JSON; the rest reuse the table markup. ----



81
82
83
84
85
86
87
88
# File 'app/helpers/telm/cells_helper.rb', line 81

def telm_detail_cell(resource, column, record)
  cell = Telm.rendering.cell(resource, column, record)
  case cell.kind
  when :string then tag.div(cell.value, class: "telm-detail-string")
  when :json then telm_detail_json(cell)
  else public_send("telm_cell_#{cell.kind}", cell)
  end
end

#telm_detail_json(cell) ⇒ Object



90
91
92
93
94
95
# File 'app/helpers/telm/cells_helper.rb', line 90

def telm_detail_json(cell)
  tag.details(class: "telm-detail-json") do
    tag.summary(tag.span(cell.value.is_a?(Array) ? "[…]" : "{…}", class: "telm-chip is-json")) +
      tag.pre(JSON.pretty_generate(cell.value))
  end
end