Class: ReverseAsciidoctor::Converters::Td

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

Direct Known Subclasses

Th

Instance Method Summary collapse

Methods inherited from Base

#escape_keychars, #extract_title, #treat, #treat_children

Instance Method Details

#alignstyle(node) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/reverse_asciidoctor/converters/td.rb', line 36

def alignstyle(node)
  align = node["align"]
  valign = node["valign"]
  a = case align
        when "left" then "<"
        when "center" then "^"
        when "right" then ">"
      else
        ""
      end
  v = case valign
        when "top" then "<"
        when "middle" then "^"
        when "bottom" then ">"
      else
        ""
      end
  if align && valign
    "#{a}.#{v}"
  elsif align
    a
  elsif valign
    ".#{v}"
  else
    ""
  end
end

#cellstyle(node) ⇒ Object



20
21
22
# File 'lib/reverse_asciidoctor/converters/td.rb', line 20

def cellstyle(node)
  ""
end

#colrow(colspan, rowspan) ⇒ Object



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

def colrow(colspan, rowspan)
  if colspan && rowspan
    "#{colspan}.#{rowspan}+"
  elsif colspan
    "#{colspan}+"
  elsif rowspan
    ".#{rowspan}+"
  else
    ""
  end
end

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



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/reverse_asciidoctor/converters/td.rb', line 4

def convert(node, state = {})
  id = node['id']
  anchor = id ? "[[#{id}]]" : ""
  colrowattr = colrow(node['colspan'], node['rowspan'])
  alignattr = alignstyle(node)
  style = cellstyle(node)
  singlepara = node.elements.size == 1 && node.elements.first.name == "p"
  state[:tdsinglepara] = singlepara if singlepara
  adoccell = node.at(".//ul | .//ol | .//pre | .//blockquote | .//br | .//hr") ||
    node.at(".//p") && !singlepara
  style = "a" if adoccell
  delim = adoccell ? "\n" : " "
  content = treat_children(node, state)
  "#{colrowattr}#{alignattr}#{style}| #{anchor}#{content}#{delim}"
end