Class: ReverseAsciidoctor::Converters::Table

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

Instance Method Summary collapse

Methods inherited from Base

#escape_keychars, #treat, #treat_children

Instance Method Details

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



4
5
6
7
8
9
10
11
# File 'lib/reverse_asciidoctor/converters/table.rb', line 4

def convert(node, state = {})
  id = node['id']
  anchor = id ? "[[#{id}]]\n" : ""
  title = extract_title(node)
  title = ".#{title}\n" unless title.empty?
  attrs = style(node)
  "\n\n#{anchor}#{attrs}#{title}|===\n" << treat_children(node, state) << "\n|===\n"
end

#extract_title(node) ⇒ Object



13
14
15
16
17
# File 'lib/reverse_asciidoctor/converters/table.rb', line 13

def extract_title(node)
  title = node.at("./caption")
  return "" if title.nil?
  treat_children(title, {})
end

#frame(node) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/reverse_asciidoctor/converters/table.rb', line 19

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

#rules(node) ⇒ Object



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

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

#style(node) ⇒ Object



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

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