Class: Coradoc::Input::HTML::Converters::Td

Inherits:
Base
  • Object
show all
Defined in:
lib/coradoc/input/html/converters/td.rb

Direct Known Subclasses

Th

Instance Method Summary collapse

Methods inherited from Base

#convert, #extract_leading_trailing_whitespace, #extract_title, #node_has_ancestor?, #textnode_after_start_with?, #textnode_before_end_with?, #treat, #treat_children, #treat_children_coradoc, #treat_coradoc, #unconstrained_after?, #unconstrained_before?

Instance Method Details

#alignstyle(node) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/coradoc/input/html/converters/td.rb', line 46

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



30
31
32
# File 'lib/coradoc/input/html/converters/td.rb', line 30

def cellstyle(_node)
  ""
end

#colrow(colspan, rowspan) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
# File 'lib/coradoc/input/html/converters/td.rb', line 34

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

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



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/coradoc/input/html/converters/td.rb', line 4

def to_coradoc(node, state = {})
  # convert(node, state)
  id = node["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 | .//img[@src]") ||
    node.at(".//p") && !singlepara

  style = "a" if adoccell
  content = treat_children_coradoc(node, state)
  options = {}.tap do |hash|
    hash[:id] = id
    hash[:colrowattr] = colrowattr
    hash[:alignattr] = alignattr
    hash[:style] = style
    hash[:content] = content
  end

  Coradoc::Element::Table::Cell.new(options)
end