Class: ReverseAdoc::Converters::Table

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

Instance Method Summary collapse

Methods inherited from Base

#constrained?, #escape_keychars, #node_has_ancestor?, #textnode_before_end_with?, #treat, #treat_children, #treat_children_coradoc, #treat_coradoc, #unconstrained_after?, #unconstrained_before?

Instance Method Details

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



12
13
14
# File 'lib/reverse_adoc/converters/table.rb', line 12

def convert(node, state = {})
  Coradoc::Generator.gen_adoc(to_coradoc(node, state))
end

#extract_title(node) ⇒ Object



16
17
18
19
20
21
# File 'lib/reverse_adoc/converters/table.rb', line 16

def extract_title(node)
  title = node.at("./caption")
  return "" if title.nil?

  treat_children(title, {})
end

#frame(node) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/reverse_adoc/converters/table.rb', line 23

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

#rules(node) ⇒ Object



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

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

#style(node) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/reverse_adoc/converters/table.rb', line 49

def style(node)
  attrs = Coradoc::Element::AttributeList.new
  # Width is disabled on tables for now. (From #88)
  # attrs.add_named("width", node["width"]) if node["width"]

  frame_attr = frame(node)
  attrs.add_named("frame", frame_attr) if frame_attr

  rules_attr = rules(node)
  attrs.add_named("rules", rules_attr) if rules_attr

  # This line should be removed.
  return "" if attrs.empty?

  attrs
end

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



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

def to_coradoc(node, state = {})
  id = node["id"]
  title = extract_title(node)
  attrs = style(node)
  content = treat_children_coradoc(node, state)
  Coradoc::Element::Table.new(title, content, { id: id, attrs: attrs })
end