Module: IsoDoc::ITU::BaseConvert

Included in:
HtmlConvert, WordConvert
Defined in:
lib/isodoc/itu/ref.rb,
lib/isodoc/itu/terms.rb,
lib/isodoc/itu/cleanup.rb,
lib/isodoc/itu/base_convert.rb

Constant Summary collapse

FRONT_CLAUSE =
"//*[parent::preface]" \
"[not(local-name() = 'abstract')]".freeze

Instance Method Summary collapse

Instance Method Details

#acknowledgements(clause, out) ⇒ Object



28
29
30
# File 'lib/isodoc/itu/base_convert.rb', line 28

def acknowledgements(clause, out)
  introduction(clause, out)
end

#annex(node, out) ⇒ Object



79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/isodoc/itu/base_convert.rb', line 79

def annex(node, out)
  @meta.get[:doctype_original] == "recommendation-annex" or
    page_break(out)
  out.div **attr_code(id: node["id"], class: "Section3") do |s|
    annex_name(node, nil, s) unless node.at(ns("./title"))
    node.elements.each do |c1|
      if c1.name == "title" then annex_name(node, c1, s)
      else
        parse(c1, s)
      end
    end
  end
end

#annex_name(annex, name, div) ⇒ Object



62
63
64
65
66
67
68
69
# File 'lib/isodoc/itu/base_convert.rb', line 62

def annex_name(annex, name, div)
  r_a = @meta.get[:doctype_original] == "recommendation-annex"
  div.h1 class: r_a ? "RecommendationAnnex" : "Annex" do |t|
    name&.children&.each { |c2| parse(c2, t) }
  end
  @meta.get[:doctype_original] == "resolution" or
    annex_obligation_subtitle(annex, div)
end

#annex_obligation_subtitle(annex, div) ⇒ Object



71
72
73
74
75
76
77
# File 'lib/isodoc/itu/base_convert.rb', line 71

def annex_obligation_subtitle(annex, div)
  info = annex["obligation"] == "informative"
  div.p class: "annex_obligation" do |p|
    p << (info ? @i18n.inform_annex : @i18n.norm_annex)
      .sub("%", @meta.get[:doctype] || "")
  end
end

#biblio_list(clause, div, biblio) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/isodoc/itu/ref.rb', line 22

def biblio_list(clause, div, biblio)
  div.table class: "biblio", border: "0" do |t|
    i = 0
    t.tbody do |tbody|
      clause.elements.each do |b|
        if b.name == "bibitem"
          next if implicit_reference(b)

          i += 1
          nonstd_bibitem(tbody, b, i, biblio)
        else
          unless %w(title clause references).include? b.name
            tbody.tx { |tx| parse(b, tx) }
          end
        end
      end
    end
  end
  clause.xpath(ns("./clause | ./references")).each do |x|
    parse(x, div)
  end
end

#bracket_if_num(num) ⇒ Object



45
46
47
48
49
50
# File 'lib/isodoc/itu/ref.rb', line 45

def bracket_if_num(num)
  return nil if num.nil?

  num = num.text.sub(/^\[/, "").sub(/\]$/, "")
  "[#{num}]"
end

#bracket_opt(text) ⇒ Object



32
33
34
35
36
37
# File 'lib/isodoc/itu/terms.rb', line 32

def bracket_opt(text)
  return text if text.nil?
  return text if /^\[.+\]$/.match?(text)

  "[#{text}]"
end

#clause(clause, out) ⇒ Object

can have supertitle in resolution



139
140
141
142
143
144
145
146
147
148
# File 'lib/isodoc/itu/base_convert.rb', line 139

def clause(clause, out)
  out.div **attr_code(clause_attrs(clause)) do |s|
    clause.elements.each do |c1|
      if c1.name == "title" then clause_name(clause, c1, s, nil)
      else
        parse(c1, s)
      end
    end
  end
end

#clause_attrs(node) ⇒ Object



131
132
133
134
135
136
# File 'lib/isodoc/itu/base_convert.rb', line 131

def clause_attrs(node)
  if node["type"] == "keyword"
    super.merge(class: "Keyword")
  else super
  end
end

#clausedelimObject



36
37
38
# File 'lib/isodoc/itu/base_convert.rb', line 36

def clausedelim
  ""
end

#cleanup(docxml) ⇒ Object



4
5
6
7
8
9
# File 'lib/isodoc/itu/cleanup.rb', line 4

def cleanup(docxml)
  super
  term_cleanup(docxml)
  refs_cleanup(docxml)
  title_cleanup(docxml)
end

#dl1(dlist) ⇒ Object



156
157
158
159
160
161
162
163
# File 'lib/isodoc/itu/base_convert.rb', line 156

def dl1(dlist)
  ret = dl2tbody(dlist)
  n = dlist.at(ns("./colgroup")) and ret = "#{n.remove.to_xml}#{ret}"
  n = dlist.at(ns("./name")) and ret = "#{n.remove.to_xml}#{ret}"
  dlist.name = "table"
  dlist["class"] = "dl"
  dlist.children.first.previous = ret
end

#dl2tbody(dlist) ⇒ Object



165
166
167
168
169
170
171
172
173
174
175
# File 'lib/isodoc/itu/base_convert.rb', line 165

def dl2tbody(dlist)
  ret = ""
  dlist.elements.select { |n| %w{dt dd}.include? n.name }
    .each_slice(2) do |dt, dd|
      ret += "<tr><th width='20%'>#{dt.children.to_xml}</th>" \
       "<td width='80%'>#{dd.children.to_xml}</td></tr>"
      dt.replace(" ")
      dd.remove
    end
  "<tbody>#{ret}</tbody>"
end

#dl_parse(node, out) ⇒ Object



150
151
152
153
154
# File 'lib/isodoc/itu/base_convert.rb', line 150

def dl_parse(node, out)
  node.ancestors("table, formula, figure").empty? or return super
  dl1(node)
  table_parse(node, out)
end

#foreword(clause, out) ⇒ Object



24
25
26
# File 'lib/isodoc/itu/base_convert.rb', line 24

def foreword(clause, out)
  introduction(clause, out)
end

#info(isoxml, out) ⇒ Object



93
94
95
96
97
98
# File 'lib/isodoc/itu/base_convert.rb', line 93

def info(isoxml, out)
  @meta.ip_notice_received isoxml, out
  @meta.techreport isoxml, out
  @meta.contribution isoxml, out
  super
end

#introduction(clause, out) ⇒ Object



14
15
16
17
18
19
20
21
22
# File 'lib/isodoc/itu/base_convert.rb', line 14

def introduction(clause, out)
  title = clause.at(ns("./title"))
  out.div **attr_code(clause_attrs(clause)) do |s|
    clause_name(clause, title, s, class: "IntroTitle")
    clause.elements.reject { |c1| c1.name == "title" }.each do |c1|
      parse(c1, s)
    end
  end
end

#nonstd_bibitem(list, bibitem, _ordinal, biblio) ⇒ Object



8
9
10
11
12
13
14
15
16
# File 'lib/isodoc/itu/ref.rb', line 8

def nonstd_bibitem(list, bibitem, _ordinal, biblio)
  list.tr **attr_code(iso_bibitem_entry_attrs(bibitem, biblio)) do |ref|
    ref.td style: "vertical-align:top" do |td|
      tag = bibitem.at(ns("./biblio-tag"))
      tag&.children&.each { |n| parse(n, td) }
    end
    ref.td { |td| reference_format(bibitem, td) }
  end
end

#note_delimObject



40
41
42
# File 'lib/isodoc/itu/base_convert.rb', line 40

def note_delim
  " &#x2013; "
end

#note_p_parse(node, div) ⇒ Object



100
101
102
103
104
105
106
107
108
109
110
# File 'lib/isodoc/itu/base_convert.rb', line 100

def note_p_parse(node, div)
  name = node.at(ns("./name"))&.remove
  div.p do |p|
    name and p.span class: "note_label" do |s|
      name.children.each { |n| parse(n, s) }
      s << note_delim
    end
    node.first_element_child.children.each { |n| parse(n, p) }
  end
  node.element_children[1..-1].each { |n| parse(n, div) }
end

#note_parse(node, out) ⇒ Object



126
127
128
129
# File 'lib/isodoc/itu/base_convert.rb', line 126

def note_parse(node, out)
  node["type"] == "title-footnote" and return
  super
end

#note_parse1(node, div) ⇒ Object



112
113
114
115
116
117
118
119
120
# File 'lib/isodoc/itu/base_convert.rb', line 112

def note_parse1(node, div)
  name = node.at(ns("./name"))&.remove
  div.p do |p|
    name and p.span class: "note_label" do |s|
      name.children.each { |n| parse(n, s) }
    end
  end
  node.children.each { |n| parse(n, div) }
end

#ol_depth(node) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
# File 'lib/isodoc/itu/base_convert.rb', line 50

def ol_depth(node)
  node["class"] == "steps" ||
    node.at(".//ancestor::xmlns:ol[@class = 'steps']") or return super
  depth = node.ancestors("ul, ol").size + 1
  type = :arabic
  type = :alphabet if [2, 7].include? depth
  type = :roman if [3, 8].include? depth
  type = :alphabet_upper if [4, 9].include? depth
  type = :roman_upper if [5, 10].include? depth
  ol_style(type)
end

#para_class(node) ⇒ Object



44
45
46
47
48
# File 'lib/isodoc/itu/base_convert.rb', line 44

def para_class(node)
  return "supertitle" if node["class"] == "supertitle"

  super
end

#pref_ref_code(bibitem) ⇒ Object



52
53
54
55
56
# File 'lib/isodoc/itu/ref.rb', line 52

def pref_ref_code(bibitem)
  ret = bibitem.xpath(ns("./docidentifier[@type = 'ITU']"))
  ret.empty? and ret = super
  ret
end

#preface_normal(clause, out) ⇒ Object



32
33
34
# File 'lib/isodoc/itu/base_convert.rb', line 32

def preface_normal(clause, out)
  introduction(clause, out)
end

#refs_cleanup(docxml) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
# File 'lib/isodoc/itu/cleanup.rb', line 42

def refs_cleanup(docxml)
  docxml.xpath("//tx[following-sibling::tx]").each do |tx|
    tx << tx.next_element.remove.children
  end
  docxml.xpath("//tx").each do |tx|
    tx.name = "td"
    tx["colspan"] = "2"
    tx.wrap("<tr></tr>")
  end
  docxml
end

#std_bibitem_entry(list, bibitem, ordinal, biblio) ⇒ Object



18
19
20
# File 'lib/isodoc/itu/ref.rb', line 18

def std_bibitem_entry(list, bibitem, ordinal, biblio)
  nonstd_bibitem(list, bibitem, ordinal, biblio)
end

#table_footnote_reference_format(node) ⇒ Object



122
123
124
# File 'lib/isodoc/itu/base_convert.rb', line 122

def table_footnote_reference_format(node)
  node.content += ")"
end

#term_cleanup(docxml) ⇒ Object



19
20
21
22
23
# File 'lib/isodoc/itu/cleanup.rb', line 19

def term_cleanup(docxml)
  term_cleanup1(docxml)
  term_cleanup2(docxml)
  docxml
end

#term_cleanup1(docxml) ⇒ Object



25
26
27
28
29
30
31
32
# File 'lib/isodoc/itu/cleanup.rb', line 25

def term_cleanup1(docxml)
  docxml.xpath("//p[@class = 'Terms']").each do |d|
    h2 = d.at("./preceding-sibling::*[@class = 'TermNum'][1]")
    d.children.first.previous = "<b>#{h2.children.to_xml}</b>&#xa0;"
    d["id"] = h2["id"]
    h2.remove
  end
end

#term_cleanup2(docxml) ⇒ Object



34
35
36
37
38
39
40
# File 'lib/isodoc/itu/cleanup.rb', line 34

def term_cleanup2(docxml)
  docxml.xpath("//p[@class = 'TermNum']").each do |d|
    (d1 = d.next_element and d1.name == "p") or next
    d1.children.each { |e| e.parent = d }
    d1.remove
  end
end

#termdef_parse(node, out) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/isodoc/itu/terms.rb', line 17

def termdef_parse(node, out)
  defn = node.at(ns("./definition"))
  source = node.at(ns("./termsource/origin/@citeas"))
  out.div **attr_code(id: node["id"]) do |div|
    termdef_parse1(node, div, defn, source)
    set_termdomain("")
    node.children.each do |n|
      next if %w(preferred definition termsource title
                 name).include? n.name

      parse(n, out)
    end
  end
end

#termdef_parse1(node, div, defn, source) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
# File 'lib/isodoc/itu/terms.rb', line 4

def termdef_parse1(node, div, defn, source)
  div.p **{ class: "TermNum", id: node["id"] } do |p|
    p.b do |b|
      node&.at(ns("./name"))&.children&.each { |n| parse(n, b) }
      insert_tab(b, 1)
      node&.at(ns("./preferred"))&.children&.each { |n| parse(n, b) }
    end
    p << ": "
    source and p << "#{bracket_opt(source.value)} "
  end
  defn&.children&.each { |n| parse(n, div) }
end

#termnote_delimObject



39
40
41
# File 'lib/isodoc/itu/terms.rb', line 39

def termnote_delim
  " &#x2013; "
end

#title_cleanup(docxml) ⇒ Object



11
12
13
14
15
16
17
# File 'lib/isodoc/itu/cleanup.rb', line 11

def title_cleanup(docxml)
  docxml.xpath("//h1[@class = 'RecommendationAnnex']").each do |h|
    h.name = "p"
    h["class"] = "h1Annex"
  end
  docxml
end

#unbracket(ident) ⇒ Object



58
59
60
61
62
63
64
# File 'lib/isodoc/itu/ref.rb', line 58

def unbracket(ident)
  if ident.respond_to?(:size)
    ident.map { |x| unbracket1(x) }.join("&#xA0;| ")
  else
    unbracket1(ident)
  end
end