Module: IsoDoc::Function::Table

Included in:
Common
Defined in:
lib/isodoc/function/table.rb

Constant Summary collapse

SW =
"solid windowtext".freeze

Instance Method Summary collapse

Instance Method Details

#make_table_attr(node) ⇒ Object



43
44
45
46
47
48
49
50
51
# File 'lib/isodoc/function/table.rb', line 43

def make_table_attr(node)
  {
    id: node["id"],
    class: "MsoISOTable",
    border: 1,
    cellspacing: 0,
    cellpadding: 0,
  }
end

#make_tr_attr(td, row, totalrows) ⇒ Object

def make_tr_attr(td, row, totalrows, cols, totalcols, header) border-left:#? “#{SW 1.5pt;” : “none;”} border-right:#SW #== totalcols && !header ? “1.5” : “1.0”pt;



73
74
75
76
77
78
79
80
81
82
# File 'lib/isodoc/function/table.rb', line 73

def make_tr_attr(td, row, totalrows)
  style = td.name == "th" ? "font-weight:bold;" : ""
  rowmax = td["rowspan"] ? row + td["rowspan"].to_i - 1 : row
  style += <<~STYLE
    border-top:#{row.zero? ? "#{SW} 1.5pt;" : 'none;'}
    border-bottom:#{SW} #{rowmax == totalrows ? '1.5' : '1.0'}pt;
  STYLE
  { rowspan: td["rowspan"], colspan: td["colspan"],
    align: td["align"], style: style.gsub(/\n/, "") }
end

#table_parse(node, out) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/isodoc/function/table.rb', line 53

def table_parse(node, out)
  @in_table = true
  table_title_parse(node, out)
  out.table **make_table_attr(node) do |t|
    thead_parse(node, t)
    tbody_parse(node, t)
    tfoot_parse(node, t)
    (dl = node.at(ns("./dl"))) && parse(dl, out)
    node.xpath(ns("./note")).each { |n| parse(n, out) }
  end
  @in_table = false
  # out.p { |p| p << "&nbsp;" }
end

#table_title_parse(node, out) ⇒ Object



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

def table_title_parse(node, out)
  name = node.at(ns("./name"))
  out.p **{ class: "TableTitle", align: "center" } do |p|
    p << l10n("#{@table_lbl} #{get_anchors[node['id']][:label]}")
    p << l10n("&nbsp;&mdash; #{name.text}") if name
  end
end

#tbody_parse(node, t) ⇒ Object



23
24
25
26
27
28
29
30
# File 'lib/isodoc/function/table.rb', line 23

def tbody_parse(node, t)
  tbody = node.at(ns("./tbody"))
  t.tbody do |h|
    tbody.element_children.each_with_index do |n, i|
      tr_parse(n, h, i, tbody.element_children.size, false)
    end
  end
end

#tfoot_parse(node, t) ⇒ Object



32
33
34
35
36
37
38
39
40
41
# File 'lib/isodoc/function/table.rb', line 32

def tfoot_parse(node, t)
  tfoot = node.at(ns("./tfoot"))
  if tfoot
    t.tfoot do |h|
      tfoot.element_children.each_with_index do |n, i|
        tr_parse(n, h, i, tfoot.element_children.size, false)
      end
    end
  end
end

#thead_parse(node, t) ⇒ Object



12
13
14
15
16
17
18
19
20
21
# File 'lib/isodoc/function/table.rb', line 12

def thead_parse(node, t)
  thead = node.at(ns("./thead"))
  if thead
    t.thead do |h|
      thead.element_children.each_with_index do |n, i|
        tr_parse(n, h, i, thead.element_children.size, true)
      end
    end
  end
end

#tr_parse(node, out, ord, totalrows, _header) ⇒ Object



84
85
86
87
88
89
90
91
92
93
94
# File 'lib/isodoc/function/table.rb', line 84

def tr_parse(node, out, ord, totalrows, _header)
  out.tr do |r|
    node.elements.each do |td|
      attrs = make_tr_attr(td, ord, totalrows - 1)
      # i, node.elements.size - 1, header)
      r.send td.name, **attr_code(attrs) do |entry|
        td.children.each { |n| parse(n, entry) }
      end
    end
  end
end