Class: Stepmod::Utils::Converters::Table

Inherits:
Base
  • Object
show all
Defined in:
lib/stepmod/utils/converters/table.rb

Direct Known Subclasses

ExpressTable

Constant Summary

Constants inherited from Base

Base::PREFIXES_REGEX

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#treat_children

Class Method Details

.pattern(state, id) ⇒ Object



7
8
9
10
11
12
13
14
# File 'lib/stepmod/utils/converters/table.rb', line 7

def self.pattern(state, id)
  if state[:schema_and_entity].nil?
    raise StandardError.new("[table]: no state given, #{id}")
  end

  schema = state[:schema_and_entity].split(".").first
  "table-#{schema}-#{id}"
end

Instance Method Details

#convert(node, state = {}) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/stepmod/utils/converters/table.rb', line 16

def convert(node, state = {})
  # If we want to skip this node
  return "" if state[:no_notes_examples]

  id = node["id"]
  anchor = id ? "[[table-#{self.class.pattern(state, id)}]]\n" : ""
  title = node["caption"].to_s
  title = ".#{title}\n" unless title.empty?
  attrs = style(node)

  <<~TABLE


    #{anchor}#{attrs}#{title}|===
    #{treat_children(node, state.merge(inside_table: true))}
    |===
  TABLE
end

#frame(node) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/stepmod/utils/converters/table.rb', line 35

def frame(node)
  case node["frame"]
  when "void"
    "frame=none"
  when "hsides"
    "frame=topbot"
  when "vsides"
    "frame=sides"
  when "box", "border"
    "frame=all"
  end
end

#rules(node) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/stepmod/utils/converters/table.rb', line 48

def rules(node)
  case node["rules"]
  when "all"
    "rules=all"
  when "rows"
    "rules=rows"
  when "cols"
    "rules=cols"
  when "none"
    "rules=none"
  end
end

#style(node) ⇒ Object



61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/stepmod/utils/converters/table.rb', line 61

def style(node)
  width = "width=#{node['width']}" if node["width"]
  attrs = []
  frame_attr = frame(node)
  rules_attr = rules(node)
  attrs += width if width
  attrs += frame_attr if frame_attr
  attrs += rules_attr if rules_attr
  return "" if attrs.empty?

  "[#{attrs.join(',')}]\n"
end