Module: IsoDoc::ITU::BaseConvert

Included in:
HtmlConvert, PdfConvert, WordConvert
Defined in:
lib/isodoc/itu/base_convert.rb

Constant Summary collapse

FRONT_CLAUSE =
"//*[parent::preface]"\
"[not(local-name() = 'abstract')]".freeze
ELSEWHERE_TERMS =
"This Recommendation uses the following terms defined elsewhere:"
HERE_TERMS =
"This Recommendation defines the following terms:"

Instance Method Summary collapse

Instance Method Details

#annex_name(annex, name, div) ⇒ Object



37
38
39
40
41
42
43
44
45
# File 'lib/isodoc/itu/base_convert.rb', line 37

def annex_name(annex, name, div)
  div.h1 **{ class: "Annex" } do |t|
    t << "#{get_anchors[annex['id']][:label]} "
    t.br
    t.b do |b|
      name&.children&.each { |c2| parse(c2, b) }
    end
  end
end

#biblio_list(f, div, bibliography) ⇒ Object



137
138
139
140
141
142
# File 'lib/isodoc/itu/base_convert.rb', line 137

def biblio_list(f, div, bibliography)
  bibitems = split_bibitems(f)
  bibitems.each_with_index do |b, i|
    noniso_bibitem_entry(div, b, (i + 1), bibliography)
  end
end

#cleanup(docxml) ⇒ Object



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

def cleanup(docxml)
  super
  term_cleanup(docxml)
end

#eref_parse(node, out) ⇒ Object



198
199
200
201
202
203
204
205
206
207
# File 'lib/isodoc/itu/base_convert.rb', line 198

def eref_parse(node, out)
  linkend = get_eref_linkend(node)
  if node["type"] == "footnote"
    out.sup do |s|
      s.a(**{ "href": "#" + node["bibitemid"] }) { |l| l << linkend }
    end
  else
    out.a(**{ "href": "#" + node["bibitemid"] }) { |l| l << linkend }
  end
end

#fileloc(loc) ⇒ Object



59
60
61
# File 'lib/isodoc/itu/base_convert.rb', line 59

def fileloc(loc)
  File.join(File.dirname(__FILE__), loc)
end

#get_eref_linkend(node) ⇒ Object



190
191
192
193
194
195
196
# File 'lib/isodoc/itu/base_convert.rb', line 190

def get_eref_linkend(node)
  link = "[#{anchor_linkend(node, docid_l10n(node["target"] || node["citeas"]))}]"
  link += eref_localities(node.xpath(ns("./locality")), link)
  contents = node.children.select { |c| c.name != "locality" }
  return link if contents.nil? || contents.empty?
  Nokogiri::XML::NodeSet.new(node.document, contents).to_xml
end

#i18n_init(lang, script) ⇒ Object



55
56
57
# File 'lib/isodoc/itu/base_convert.rb', line 55

def i18n_init(lang, script)
  super
end

#info(isoxml, out) ⇒ Object



77
78
79
80
81
# File 'lib/isodoc/itu/base_convert.rb', line 77

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

#initial_anchor_names(d) ⇒ Object



83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/isodoc/itu/base_convert.rb', line 83

def initial_anchor_names(d)
  d.xpath("//xmlns:preface/child::*").each do |c|
    preface_names(c)
  end
  sequential_asset_names(d.xpath("//xmlns:preface/child::*"))
  n = section_names(d.at(ns("//clause[title = 'Scope']")), 0, 1)
  n = section_names(d.at(ns("//bibliography/clause[title = 'References'] | "\
                            "//bibliography/references[title = 'References']")), n, 1)
  n = section_names(d.at(ns("//sections/terms | "\
                            "//sections/clause[descendant::terms]")), n, 1)
  n = section_names(d.at(ns("//sections/definitions")), n, 1)
  clause_names(d, n)
  middle_section_asset_names(d)
  termnote_anchor_names(d)
  termexample_anchor_names(d)
end

#load_yaml(lang, script) ⇒ Object



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

def load_yaml(lang, script)
  y = if @i18nyaml then YAML.load_file(@i18nyaml)
      elsif lang == "en"
        YAML.load_file(File.join(File.dirname(__FILE__), "i18n-en.yaml"))
      else
        YAML.load_file(File.join(File.dirname(__FILE__), "i18n-en.yaml"))
      end
  super.merge(y)
end

#metadata_init(lang, script, labels) ⇒ Object



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

def (lang, script, labels)
  @meta = Metadata.new(lang, script, labels)
end

#noniso_bibitem_entry(list, b, ordinal, biblio) ⇒ Object



127
128
129
130
131
132
133
134
135
# File 'lib/isodoc/itu/base_convert.rb', line 127

def noniso_bibitem_entry(list, b, ordinal, biblio)
  return if implicit_reference(b)
  list.p **attr_code(iso_bibitem_entry_attrs(b, biblio)) do |ref|
    ref << "[#{iso_bibitem_ref_code(b)}]"
    date_note_process(b, ref)
    insert_tab(ref, 1)
    reference_format(b, ref)
  end
end

#norm_ref(isoxml, out, num) ⇒ Object



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

def norm_ref(isoxml, out, num)
  q = "//bibliography/references[title = 'References']"
  f = isoxml.at(ns(q)) or return num
  out.div do |div|
    num = num + 1
    clause_name(num, "References", div, nil)
    norm_ref_preface(f, div)
    biblio_list(f, div, false)
  end
  num
end

#norm_ref_preface(f, div) ⇒ Object



112
113
114
# File 'lib/isodoc/itu/base_convert.rb', line 112

def norm_ref_preface(f, div)
  div.p "The following ITU-T Recommendations and other references contain provisions which, through reference in this text, constitute provisions of this Recommendation. At the time of publication, the editions indicated were valid. All Recommendations and other references are subject to revision; users of this Recommendation are therefore encouraged to investigate the possibility of applying the most recent edition of the Recommendations and other references listed below. A list of the currently valid ITU-T Recommendations is regularly published. The reference to a document within this Recommendation does not give it, as a stand-alone document, the status of a Recommendation."
end

#preface(isoxml, out) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
# File 'lib/isodoc/itu/base_convert.rb', line 25

def preface(isoxml, out)
  isoxml.xpath(ns(FRONT_CLAUSE)).each do |c|
    title = c&.at(ns("./title"))
    out.div **attr_code(id: c["id"]) do |s|
      clause_name(nil, title&.content, s, class: "IntroTitle")
      c.elements.reject { |c1| c1.name == "title" }.each do |c1|
        parse(c1, s)
      end
    end
  end
end

#split_bibitems(f) ⇒ Object



119
120
121
122
123
124
125
# File 'lib/isodoc/itu/base_convert.rb', line 119

def split_bibitems(f)
  bibitem = []
  f.xpath(ns("./bibitem")).each do |x|
    bibitem << x
  end
  bibitem
end

#term_cleanup(docxml) ⇒ Object



68
69
70
71
72
73
74
75
# File 'lib/isodoc/itu/base_convert.rb', line 68

def term_cleanup(docxml)
  docxml.xpath("//p[@class = 'Terms']").each do |d|
    h2 = d.at("./preceding-sibling::*[@class = 'TermNum'][1]")
    h2.add_child("&nbsp;")
    h2.add_child(d.remove)
  end
  docxml
end

#term_defs_boilerplate(div, source, term, preface) ⇒ Object



47
48
49
50
51
52
53
# File 'lib/isodoc/itu/base_convert.rb', line 47

def term_defs_boilerplate(div, source, term, preface)
  if source.empty? && term.nil?
    div << @no_terms_boilerplate
  else
    div << term_defs_boilerplate_cont(source, term)
  end
end

#termdef_parse(node, out) ⇒ Object



176
177
178
179
180
181
182
183
184
185
186
187
188
# File 'lib/isodoc/itu/base_convert.rb', line 176

def termdef_parse(node, out)
  term = node.at(ns("./preferred"))
  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, term, defn, source)
    set_termdomain("")
    node.children.each do |n|
      next if %w(preferred definition termsource title).include? n.name
      parse(n, out)
    end
  end
end

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



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

def termdef_parse1(node, div, term, defn, source)
  div.p **{ class: "TermNum", id: node["id"] } do |p|
    p.b do |b|
      b << get_anchors[node["id"]][:label]
      insert_tab(b, 1)
      term.children.each { |n| parse(n, b) }
    end
    source and p << " [#{source.value}]"
    p << ":"
    defn and defn.children.each { |n| parse(n, p) }
  end
end

#terms_parse(node, out) ⇒ Object



147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
# File 'lib/isodoc/itu/base_convert.rb', line 147

def terms_parse(node, out)
  out.div **attr_code(id: node["id"]) do |div|
    clause_parse_title(node, div, node.at(ns("./title")), out)
    title = node.at(ns("./title"))&.text&.downcase
    title == "terms defined elsewhere" and out.p ELSEWHERE_TERMS
    title == "terms defined in this recommendation" and out.p HERE_TERMS
    content = node.at(ns("./clause | ./term"))
    if content.nil? then out.p "None."
    else
      node.children.reject { |c1| c1.name == "title" }.each do |c1|
        parse(c1, div)
      end
    end
  end
end