metanorma-itu 1.1.3 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -7,18 +7,21 @@ module IsoDoc
7
7
  def initialize(lang, script, labels)
8
8
  super
9
9
  here = File.dirname(__FILE__)
10
+ n = "International_Telecommunication_Union_Logo.svg"
10
11
  set(:logo_html,
11
- File.expand_path(File.join(here, "html", "International_Telecommunication_Union_Logo.svg")))
12
+ File.expand_path(File.join(here, "html", n)))
12
13
  set(:logo_comb,
13
14
  File.expand_path(File.join(here, "html", "itu-document-comb.png")))
14
15
  set(:logo_word,
15
- File.expand_path(File.join(here, "html", "International_Telecommunication_Union_Logo.svg")))
16
+ File.expand_path(File.join(here, "html", n)))
16
17
  end
17
18
 
18
19
  def title(isoxml, _out)
19
- main = isoxml&.at(ns("//bibdata/title[@language='#{@lang}'][@type = 'main']"))&.text
20
+ main = isoxml&.at(ns("//bibdata/title[@language='#{@lang}']"\
21
+ "[@type = 'main']"))&.text
20
22
  set(:doctitle, main)
21
- main = isoxml&.at(ns("//bibdata/title[@language='#{@lang}'][@type = 'subtitle']"))&.text
23
+ main = isoxml&.at(ns("//bibdata/title[@language='#{@lang}']"\
24
+ "[@type = 'subtitle']"))&.text
22
25
  set(:docsubtitle, main)
23
26
  series = isoxml&.at(ns("//bibdata/series[@type='main']/title"))&.text
24
27
  set(:series, series)
@@ -50,7 +53,7 @@ module IsoDoc
50
53
  dn = isoxml.at(ns("//bibdata/ext/structuredidentifier/annexid"))
51
54
  oblig = isoxml&.at(ns("//annex/@obligation"))&.text
52
55
  lbl = oblig == "informative" ? @labels["appendix"] : @labels["annex"]
53
- dn and set(:annexid, IsoDoc::Function::I18n::l10n("#{lbl} #{dn&.text}"))
56
+ dn and set(:annexid, @i18n.l10n("#{lbl} #{dn&.text}"))
54
57
  end
55
58
 
56
59
  def unpublished(status)
@@ -1,5 +1,4 @@
1
1
  require "isodoc"
2
- require_relative "metadata"
3
2
  require "fileutils"
4
3
 
5
4
  module IsoDoc
@@ -1,9 +1,54 @@
1
- require_relative "base_convert"
1
+ require_relative "init"
2
2
  require "isodoc"
3
3
 
4
4
  module IsoDoc
5
5
  module ITU
6
6
  class PresentationXMLConvert < IsoDoc::PresentationXMLConvert
7
+ def initialize(options)
8
+ @hierarchical_assets = options[:hierarchical_assets]
9
+ super
10
+ end
11
+
12
+ def prefix_container(container, linkend, _target)
13
+ l10n("#{linkend} #{@i18n.get["in"]} #{@xrefs.anchor(container, :xref)}")
14
+ end
15
+
16
+ def eref(docxml)
17
+ docxml.xpath(ns("//eref")).each do |f|
18
+ eref1(f)
19
+ end
20
+ end
21
+
22
+ def origin(docxml)
23
+ docxml.xpath(ns("//origin[not(termref)]")).each do |f|
24
+ eref1(f)
25
+ end
26
+ end
27
+
28
+ def quotesource(docxml)
29
+ docxml.xpath(ns("//quote/source")).each do |f|
30
+ eref1(f)
31
+ end
32
+ end
33
+
34
+ def eref1(f)
35
+ get_eref_linkend(f)
36
+ end
37
+
38
+ def get_eref_linkend(node)
39
+ contents = non_locality_elems(node).select do |c|
40
+ !c.text? || /\S/.match(c)
41
+ end
42
+ return unless contents.empty?
43
+ link = anchor_linkend(node, docid_l10n(node["target"] || node["citeas"]))
44
+ link && !/^\[.*\]$/.match(link) and link = "[#{link}]"
45
+ link += eref_localities(node.xpath(ns("./locality | ./localityStack")),
46
+ link)
47
+ non_locality_elems(node).each { |n| n.remove }
48
+ node.add_child(link)
49
+ end
50
+
51
+ include Init
7
52
  end
8
53
  end
9
54
  end
@@ -11,7 +11,7 @@ module IsoDoc
11
11
  f = isoxml.at(ns(q)) or return num
12
12
  out.div do |div|
13
13
  num = num + 1
14
- clause_name(num, @normref_lbl, div, nil)
14
+ clause_name(num, f.at(ns("./title")), div, nil)
15
15
  biblio_list(f, div, false)
16
16
  end
17
17
  num
@@ -45,9 +45,7 @@ module IsoDoc
45
45
  nonstd_bibitem(tbody, b, i, biblio)
46
46
  else
47
47
  unless %w(title clause references).include? b.name
48
- tbody.tx do |tx|
49
- parse(b, tx)
50
- end
48
+ tbody.tx { |tx| parse(b, tx) }
51
49
  end
52
50
  end
53
51
  end
@@ -77,12 +75,14 @@ module IsoDoc
77
75
  b.at(ns("./docidentifier[@type = 'ITU']")) || super
78
76
  end
79
77
 
80
- IGNORE_IDS =
81
- "@type = 'DOI' or @type = 'ISSN' or @type = 'ISBN' or @type = 'rfc-anchor'".freeze
78
+ IGNORE_IDS = "@type = 'DOI' or @type = 'ISSN' or @type = 'ISBN' or "\
79
+ "@type = 'rfc-anchor'".freeze
82
80
 
83
81
  def multi_bibitem_ref_code(b)
84
- id = b.xpath(ns("./docidentifier[not(@type = 'metanorma' or #{IGNORE_IDS})]"))
85
- id.empty? and id = b.xpath(ns("./docidentifier[not(@type = 'metanorma')]"))
82
+ id = b.xpath(ns("./docidentifier[not(@type = 'metanorma' or "\
83
+ "#{IGNORE_IDS})]"))
84
+ id.empty? and
85
+ id = b.xpath(ns("./docidentifier[not(@type = 'metanorma')]"))
86
86
  return [] if id.empty?
87
87
  id.sort_by { |i| i["type"] == "ITU" ? 0 : 1 }
88
88
  end
@@ -100,7 +100,8 @@ module IsoDoc
100
100
  /^(?<prefix>ITU-[A-Z] [A-Z])[ .-]Sup[a-z]*\.[ ]?(?<num>\d+)$/ =~ id.text
101
101
  "#{prefix}-series Recommendations – Supplement #{num}"
102
102
  else
103
- "#{titlecase(type)} #{docid_prefix(id["type"], id.text.sub(/^\[/, '').sub(/\]$/, ''))}"
103
+ d = docid_prefix(id["type"], id.text.sub(/^\[/, '').sub(/\]$/, ''))
104
+ "#{titlecase(type)} #{d}"
104
105
  end
105
106
  end
106
107
 
@@ -1,15 +1,12 @@
1
1
  module IsoDoc
2
2
  module ITU
3
3
  module BaseConvert
4
- def term_def_title(node)
5
- node
6
- end
7
-
4
+ =begin
8
5
  def terms_defs(node, out, num)
9
6
  f = node.at(ns(IsoDoc::Convert::TERM_CLAUSE)) or return num
10
7
  out.div **attr_code(id: f["id"]) do |div|
11
8
  num = num + 1
12
- clause_name(num, term_def_title(f.at(ns("./title"))), div, nil)
9
+ clause_name(num, f.at(ns("./title")), div, nil)
13
10
  if f.at(ns("./clause | ./terms | ./term")).nil? then out.p "None."
14
11
  else
15
12
  f.children.reject { |c1| c1.name == "title" }.each do |c1|
@@ -31,13 +28,14 @@ module IsoDoc
31
28
  end
32
29
  end
33
30
  end
31
+ =end
34
32
 
35
- def termdef_parse1(node, div, term, defn, source)
33
+ def termdef_parse1(node, div, defn, source)
36
34
  div.p **{ class: "TermNum", id: node["id"] } do |p|
37
35
  p.b do |b|
38
- b << @xrefs.anchor(node["id"], :label)
36
+ node&.at(ns("./name"))&.children&.each { |n| parse(n, b) }
39
37
  insert_tab(b, 1)
40
- term.children.each { |n| parse(n, b) }
38
+ node&.at(ns("./preferred"))&.children&.each { |n| parse(n, b) }
41
39
  end
42
40
  source and p << " #{bracket_opt(source.value)}"
43
41
  p << ": "
@@ -46,27 +44,20 @@ module IsoDoc
46
44
  end
47
45
 
48
46
  def termdef_parse(node, out)
49
- term = node.at(ns("./preferred"))
50
47
  defn = node.at(ns("./definition"))
51
48
  source = node.at(ns("./termsource/origin/@citeas"))
52
49
  out.div **attr_code(id: node["id"]) do |div|
53
- termdef_parse1(node, div, term, defn, source)
50
+ termdef_parse1(node, div, defn, source)
54
51
  set_termdomain("")
55
52
  node.children.each do |n|
56
- next if %w(preferred definition termsource title).include? n.name
53
+ next if %w(preferred definition termsource title name).include? n.name
57
54
  parse(n, out)
58
55
  end
59
56
  end
60
57
  end
61
58
 
62
- def termnote_parse(node, out)
63
- out.div **note_attrs(node) do |div|
64
- first = node.first_element_child
65
- div.p do |p|
66
- p << note_label(node) # "#{@xrefs.anchor(node['id'], :label) || '???'}: "
67
- para_then_remainder(first, node, p, div)
68
- end
69
- end
59
+ def termnote_delim
60
+ " &ndash; "
70
61
  end
71
62
  end
72
63
  end
@@ -1,5 +1,5 @@
1
1
  require "isodoc"
2
- require_relative "metadata"
2
+ require_relative "init"
3
3
  require "fileutils"
4
4
 
5
5
  module IsoDoc
@@ -37,7 +37,7 @@ module IsoDoc
37
37
 
38
38
  def abstract(isoxml, out)
39
39
  f = isoxml.at(ns("//preface/abstract")) || return
40
- out.div **attr_code(id: f["id"]) do |s|
40
+ out.div **attr_code(id: f["id"], class: "Abstract") do |s|
41
41
  clause_name(nil, "Summary", s, class: "AbstractTitle")
42
42
  f.elements.each { |e| parse(e, s) unless e.name == "title" }
43
43
  end
@@ -46,7 +46,7 @@ module IsoDoc
46
46
  def keywords(_docxml, out)
47
47
  kw = @meta.get[:keywords]
48
48
  kw.nil? || kw.empty? and return
49
- out.div do |div|
49
+ out.div **attr_code(class: "Keyword") do |div|
50
50
  clause_name(nil, "Keywords", div, class: "IntroTitle")
51
51
  div.p kw.join(", ") + "."
52
52
  end
@@ -107,10 +107,10 @@ module IsoDoc
107
107
  historybox = docxml.at("//div[@id='historybox']")
108
108
  sourcebox = docxml.at("//div[@id='sourcebox']")
109
109
  keywordsbox = docxml.at("//div[@id='keywordsbox']")
110
- abstract = docxml.at("//p[@class = 'h1Preface' and text() = 'Summary']/..")
111
- history = docxml.at("//p[@class = 'h1Preface' and text() = 'History']/..")
112
- source = docxml.at("//p[@class = 'h1Preface' and text() = 'Source']/..")
113
- keywords = docxml.at("//p[@class = 'h1Preface' and text() = 'Keywords']/..")
110
+ abstract = docxml.at("//div[@class = 'Abstract']")
111
+ history = docxml.at("//div[@class = 'history']")
112
+ source = docxml.at("//div[@class = 'source']")
113
+ keywords = docxml.at("//div[@class = 'Keywords']")
114
114
  abstract.parent = abstractbox if abstract && abstractbox
115
115
  history.parent = historybox if history && historybox
116
116
  source.parent = sourcebox if source && sourcebox
@@ -122,8 +122,7 @@ module IsoDoc
122
122
  div.p **attr_code(class: "formula") do |p|
123
123
  insert_tab(div, 1)
124
124
  parse(node.at(ns("./stem")), div)
125
- lbl = @xrefs.anchor(node['id'], :label, false)
126
- unless lbl.nil?
125
+ if lbl = node&.at(ns("./name"))&.text
127
126
  insert_tab(div, 1)
128
127
  div << "(#{lbl})"
129
128
  end
@@ -165,16 +164,19 @@ module IsoDoc
165
164
  @wordstylesheet&.write(@landscapestyle)
166
165
  @wordstylesheet&.close
167
166
  end
168
- Html2Doc.process(result, filename: filename, stylesheet: @wordstylesheet&.path,
167
+ Html2Doc.process(result, filename: filename,
168
+ stylesheet: @wordstylesheet&.path,
169
169
  header_file: header&.path, dir: dir,
170
170
  asciimathdelims: [@openmathdelim, @closemathdelim],
171
- liststyles: { ul: @ulstyle, ol: @olstyle, steps: "l4" })
171
+ liststyles: { ul: @ulstyle, ol: @olstyle,
172
+ steps: "l4" })
172
173
  header&.unlink
173
174
  @wordstylesheet&.unlink
174
175
  end
175
176
 
176
177
  def link_parse(node, out)
177
- out.a **attr_code(href: node["target"], title: node["alt"], class: "url") do |l|
178
+ out.a **attr_code(href: node["target"], title: node["alt"],
179
+ class: "url") do |l|
178
180
  if node.text.empty?
179
181
  l << node["target"].sub(/^mailto:/, "")
180
182
  else
@@ -214,14 +216,23 @@ module IsoDoc
214
216
  p["class"] = "boilerplateHdr"
215
217
  auth&.xpath(".//p[not(@class)]")&.each_with_index do |p, i|
216
218
  p["class"] = "boilerplate"
217
- i == 0 && t == "copyright" and p["style"] = "text-align:center;"
219
+ #i == 0 && t == "copyright" and p["style"] = "text-align:center;"
218
220
  end
219
- auth << "<p>&nbsp;</p><p>&nbsp;</p><p>&nbsp;</p>" unless t == "copyright"
221
+ t == "copyright" or
222
+ auth << "<p>&nbsp;</p><p>&nbsp;</p><p>&nbsp;</p>"
220
223
  dest.replace(auth.remove)
221
224
  end
222
225
  end
223
226
 
227
+ def clause_attrs(node)
228
+ ret = {}
229
+ %w(source history).include?(node["type"]) and
230
+ ret = { class: node["type"] }
231
+ super.merge(ret)
232
+ end
233
+
224
234
  include BaseConvert
235
+ include Init
225
236
  end
226
237
  end
227
238
  end
@@ -1,5 +1,4 @@
1
1
  require "isodoc"
2
- require_relative "metadata"
3
2
  require "fileutils"
4
3
 
5
4
  module IsoDoc
@@ -11,12 +10,14 @@ module IsoDoc
11
10
  end
12
11
 
13
12
  def annex_name_lbl(clause, num)
14
- lbl = clause["obligation"] == "informative" ? @labels["appendix"] : @labels["annex"]
15
- l10n("<b>#{lbl} #{num}</b>")
13
+ lbl = clause["obligation"] == "informative" ?
14
+ @labels["appendix"] : @labels["annex"]
15
+ l10n("<strong>#{lbl} #{num}</strong>")
16
16
  end
17
17
 
18
18
  def annex_names(clause, num)
19
- lbl = clause["obligation"] == "informative" ? @labels["appendix"] : @labels["annex"]
19
+ lbl = clause["obligation"] == "informative" ?
20
+ @labels["appendix"] : @labels["annex"]
20
21
  @anchors[clause["id"]] =
21
22
  { label: annex_name_lbl(clause, num), type: "clause",
22
23
  xref: "#{lbl} #{num}", level: 1 }
@@ -33,13 +34,16 @@ module IsoDoc
33
34
 
34
35
  def back_anchor_names(docxml)
35
36
  super
36
- if annexid = docxml&.at(ns("//bibdata/ext/structuredidentifier/annexid"))&.text
37
+ if annexid =
38
+ docxml&.at(ns("//bibdata/ext/structuredidentifier/annexid"))&.text
37
39
  docxml.xpath(ns("//annex")).each { |c| annex_names(c, annexid) }
38
40
  else
39
- docxml.xpath(ns("//annex[@obligation = 'informative']")).each_with_index do |c, i|
41
+ docxml.xpath(ns("//annex[@obligation = 'informative']"))
42
+ .each_with_index do |c, i|
40
43
  annex_names(c, RomanNumerals.to_roman(i + 1))
41
44
  end
42
- docxml.xpath(ns("//annex[not(@obligation = 'informative')]")).each_with_index do |c, i|
45
+ docxml.xpath(ns("//annex[not(@obligation = 'informative')]"))
46
+ .each_with_index do |c, i|
43
47
  annex_names(c, (65 + i + (i > 7 ? 1 : 0)).chr.to_s)
44
48
  end
45
49
  end
@@ -49,7 +53,8 @@ module IsoDoc
49
53
  @anchors[clause["id"]] =
50
54
  { label: num, xref: "#{@labels["annex_subclause"]} #{num}",
51
55
  level: level, type: "clause" }
52
- clause.xpath(ns("./clause | ./references | ./terms | ./definitions")).each_with_index do |c, i|
56
+ clause.xpath(ns("./clause | ./references | ./terms | ./definitions"))
57
+ .each_with_index do |c, i|
53
58
  annex_names1(c, "#{num}.#{i + 1}", level + 1)
54
59
  end
55
60
  end
@@ -58,11 +63,11 @@ module IsoDoc
58
63
  d.xpath(ns("//boilerplate//clause")).each { |c| preface_names(c) }
59
64
  d.xpath("//xmlns:preface/child::*").each { |c| preface_names(c) }
60
65
  @hierarchical_assets ?
61
- hierarchical_asset_names(d.xpath("//xmlns:preface/child::*"), "Preface") :
62
- sequential_asset_names(d.xpath("//xmlns:preface/child::*"))
63
- n = section_names(d.at(ns("//clause[title = 'Scope']")), 0, 1)
64
- n = section_names(d.at(ns("//bibliography/clause[.//references[@normative = 'true']] | "\
65
- "//bibliography/references[@normative = 'true']")), n, 1)
66
+ hierarchical_asset_names(d.xpath("//xmlns:preface/child::*"),
67
+ "Preface") :
68
+ sequential_asset_names(d.xpath("//xmlns:preface/child::*"))
69
+ n = section_names(d.at(ns("//clause[@type = 'scope']")), 0, 1)
70
+ n = section_names(d.at(ns(@klass.norm_ref_xpath)), n, 1)
66
71
  n = section_names(d.at(ns("//sections/terms | "\
67
72
  "//sections/clause[descendant::terms]")), n, 1)
68
73
  n = section_names(d.at(ns("//sections/definitions")), n, 1)
@@ -72,15 +77,17 @@ module IsoDoc
72
77
  termexample_anchor_names(d)
73
78
  end
74
79
 
75
- MIDDLE_SECTIONS = "//clause[title = 'Scope'] | "\
76
- "//foreword | //introduction | //acknowledgements | "\
77
- "//references[@normative = 'true'] | "\
78
- "//sections/terms | //preface/clause | "\
79
- "//sections/definitions | //clause[parent::sections]".freeze
80
+ def middle_sections
81
+ "//clause[@type = 'scope'] | "\
82
+ "//foreword | //introduction | //acknowledgements | "\
83
+ " #{@klass.norm_ref_xpath} | "\
84
+ "//sections/terms | //preface/clause | "\
85
+ "//sections/definitions | //clause[parent::sections]"
86
+ end
80
87
 
81
88
  def middle_section_asset_names(d)
82
89
  return super unless @hierarchical_assets
83
- d.xpath(ns(MIDDLE_SECTIONS)).each do |c|
90
+ d.xpath(ns(middle_sections)).each do |c|
84
91
  hierarchical_asset_names(c, @anchors[c["id"]][:label])
85
92
  end
86
93
  end
@@ -104,7 +111,8 @@ module IsoDoc
104
111
  def hierarchical_figure_names(clause, num)
105
112
  c = IsoDoc::XrefGen::Counter.new
106
113
  j = 0
107
- clause.xpath(ns(".//figure | .//sourcecode[not(ancestor::example)]")).each do |t|
114
+ clause.xpath(ns(".//figure | "\
115
+ ".//sourcecode[not(ancestor::example)]")).each do |t|
108
116
  if t.parent.name == "figure" then j += 1
109
117
  else
110
118
  j = 0
@@ -113,13 +121,14 @@ module IsoDoc
113
121
  label = "#{num}#{hiersep}#{c.print}" +
114
122
  (j.zero? ? "" : "#{hierfigsep}#{(96 + j).chr.to_s}")
115
123
  next if t["id"].nil? || t["id"].empty?
116
- @anchors[t["id"]] = anchor_struct(label, nil, @labels["figure"], "figure",
117
- t["unnumbered"])
124
+ @anchors[t["id"]] =
125
+ anchor_struct(label, nil, @labels["figure"], "figure",
126
+ t["unnumbered"])
118
127
  end
119
128
  end
120
129
 
121
130
  def sequential_formula_names(clause)
122
- clause&.first&.xpath(ns(MIDDLE_SECTIONS))&.each do |c|
131
+ clause&.first&.xpath(ns(middle_sections))&.each do |c|
123
132
  if c["id"] && @anchors[c["id"]]
124
133
  hierarchical_formula_names(c, @anchors[c["id"]][:label] ||
125
134
  @anchors[c["id"]][:xref] || "???")
@@ -133,16 +142,17 @@ module IsoDoc
133
142
  c = IsoDoc::XrefGen::Counter.new
134
143
  clause.xpath(ns(".//formula")).each do |t|
135
144
  next if t["id"].nil? || t["id"].empty?
136
- @anchors[t["id"]] =
137
- anchor_struct("#{num}-#{c.increment(t).print}", nil,
138
- t["inequality"] ? @labels["inequality"] : @labels["formula"],
139
- "formula", t["unnumbered"])
145
+ @anchors[t["id"]] = anchor_struct(
146
+ "#{num}-#{c.increment(t).print}", nil,
147
+ t["inequality"] ? @labels["inequality"] : @labels["formula"],
148
+ "formula", t["unnumbered"])
140
149
  end
141
150
  end
142
151
 
143
152
  def reference_names(ref)
144
153
  super
145
- @anchors[ref["id"]] = { xref: @anchors[ref["id"]][:xref].sub(/^\[/, '').sub(/\]$/, '') }
154
+ @anchors[ref["id"]] =
155
+ { xref: @anchors[ref["id"]][:xref].sub(/^\[/, '').sub(/\]$/, '') }
146
156
  end
147
157
 
148
158
  def termnote_anchor_names(docxml)
@@ -152,8 +162,11 @@ module IsoDoc
152
162
  notes.each do |n|
153
163
  return if n["id"].nil? || n["id"].empty?
154
164
  idx = notes.size == 1 ? "" : " #{c.increment(n).print}"
155
- @anchors[n["id"]] = anchor_struct(idx, n, @labels["note_xref"],
156
- "termnote", false)
165
+ @anchors[n["id"]] =
166
+ { label: termnote_label(idx).strip, type: "termnote",
167
+ xref: l10n("#{anchor(t['id'], :xref)}, "\
168
+ "#{@labels["note_xref"]} #{c.print}") }
169
+
157
170
  end
158
171
  end
159
172
  end