metanorma-itu 2.4.2 → 2.4.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,92 @@
1
+ require_relative "init"
2
+ require "roman-numerals"
3
+ require "isodoc"
4
+ require_relative "../../relaton/render/general"
5
+ require_relative "presentation_bibdata"
6
+ require_relative "presentation_preface"
7
+
8
+ module IsoDoc
9
+ module ITU
10
+ class PresentationXMLConvert < IsoDoc::PresentationXMLConvert
11
+ def bibrender_formattedref(formattedref, _xml)
12
+ formattedref << "." unless /\.$/.match?(formattedref.text)
13
+ id = reference_format_start(formattedref.parent) and
14
+ formattedref.children.first.previous = id
15
+ end
16
+
17
+ def bibrender_relaton(xml, renderings)
18
+ f = renderings[xml["id"]][:formattedref]
19
+ ids = reference_format_start(xml)
20
+ f &&= "<formattedref>#{ids}#{f}</formattedref>"
21
+ # retain date in order to generate reference tag
22
+ keep = "./docidentifier | ./uri | ./note | ./date | ./biblio-tag"
23
+ xml.children = "#{f}#{xml.xpath(ns(keep)).to_xml}"
24
+ end
25
+
26
+ def multi_bibitem_ref_code(bib)
27
+ skip = IsoDoc::Function::References::SKIP_DOCID
28
+ skip1 = "@type = 'metanorma' or @type = 'metanorma-ordinal'"
29
+ prim = "[@primary = 'true']"
30
+ id = bib.xpath(ns("./docidentifier#{prim}[not(#{skip} or #{skip1})]"))
31
+ id.empty? and id = bib.xpath(ns("./docidentifier#{prim}[not(#{skip1})]"))
32
+ id.empty? and id = bib.xpath(ns("./docidentifier[not(#{skip} or #{skip1})]"))
33
+ id.empty? and id = bib.xpath(ns("./docidentifier[not(#{skip1})]"))
34
+ id.empty? and return id
35
+ id.sort_by { |i| i["type"] == "ITU" ? 0 : 1 }
36
+ end
37
+
38
+ def render_multi_identifiers(ids)
39
+ ids.map do |id|
40
+ if id["type"] == "ITU" then doctype_title(id)
41
+ else
42
+ docid_prefix(id["type"], id.text.sub(/^\[/, "").sub(/\]$/, ""))
43
+ end
44
+ end.join("&#xA0;| ")
45
+ end
46
+
47
+ def reference_format_start(bib)
48
+ id = multi_bibitem_ref_code(bib)
49
+ id1 = render_multi_identifiers(id)
50
+ out = id1
51
+ date = bib.at(ns("./date[@type = 'published']/on | " \
52
+ "./date[@type = 'published']/from")) and
53
+ out << " (#{date.text.sub(/-.*$/, '')})"
54
+ out += ", " if date || !id1.empty?
55
+ out
56
+ end
57
+
58
+ def bibliography_bibitem_number1(bib, idx)
59
+ mn = bib.at(ns(".//docidentifier[@type = 'metanorma']")) and
60
+ /^\[?\d+\]?$/.match?(mn.text) and
61
+ mn["type"] = "metanorma-ordinal"
62
+ if (mn = bib.at(ns(".//docidentifier[@type = 'metanorma-ordinal']"))) &&
63
+ !bibliography_bibitem_number_skip(bib)
64
+ idx += 1
65
+ mn.children = "[#{idx}]"
66
+ end
67
+ idx
68
+ end
69
+
70
+ def bibliography_bibitem_number_skip(bibitem)
71
+ @xrefs.klass.implicit_reference(bibitem) ||
72
+ bibitem["hidden"] == "true" || bibitem.parent["hidden"] == "true"
73
+ end
74
+
75
+ def norm_ref_entry_code(_ordinal, idents, _ids, _standard, datefn, _bib)
76
+ ret = (idents[:metanorma] || idents[:ordinal] || idents[:sdo]).to_s
77
+ /^\[.+\]$/.match?(ret) or ret = "[#{ret}]"
78
+ ret += datefn
79
+ ret.empty? and return ret
80
+ ret.gsub("-", "&#x2011;").gsub(/ /, "&#xa0;")
81
+ end
82
+
83
+ def biblio_ref_entry_code(_ordinal, idents, _id, _standard, datefn, _bib)
84
+ ret = (idents[:metanorma] || idents[:ordinal] || idents[:sdo]).to_s
85
+ /^\[.+\]$/.match?(ret) or ret = "[#{ret}]"
86
+ ret += datefn
87
+ ret.empty? and return ret
88
+ ret.gsub("-", "&#x2011;").gsub(/ /, "&#xa0;")
89
+ end
90
+ end
91
+ end
92
+ end
@@ -4,6 +4,18 @@ require "isodoc"
4
4
  require_relative "../../relaton/render/general"
5
5
  require_relative "presentation_bibdata"
6
6
  require_relative "presentation_preface"
7
+ require_relative "presentation_ref"
8
+
9
+ module Nokogiri
10
+ module XML
11
+ class Node
12
+ def traverse_topdown(&block)
13
+ yield(self)
14
+ children.each { |j| j.traverse_topdown(&block) }
15
+ end
16
+ end
17
+ end
18
+ end
7
19
 
8
20
  module IsoDoc
9
21
  module ITU
@@ -39,6 +51,25 @@ module IsoDoc
39
51
  super
40
52
  end
41
53
 
54
+ def table1(elem)
55
+ elem.xpath(ns("./name | ./thead/tr/th")).each do |n|
56
+ capitalise_unless_text_transform(n)
57
+ end
58
+ super
59
+ end
60
+
61
+ def capitalise_unless_text_transform(elem)
62
+ css = nil
63
+ elem.traverse_topdown do |n|
64
+ n.name == "span" && /text-transform:/.match?(n["style"]) and
65
+ css = n
66
+ n.text? && /\S/.match?(n.text) or next
67
+ css && n.ancestors.include?(css) or
68
+ n.replace(::Metanorma::Utils.strict_capitalize_first(n.text))
69
+ break
70
+ end
71
+ end
72
+
42
73
  def get_eref_linkend(node)
43
74
  non_locality_elems(node).select do |c|
44
75
  !c.text? || /\S/.match(c)
@@ -52,57 +83,6 @@ module IsoDoc
52
83
  node.add_child(link)
53
84
  end
54
85
 
55
- def bibrenderer
56
- ::Relaton::Render::ITU::General.new(language: @lang)
57
- end
58
-
59
- def bibrender_formattedref(formattedref, _xml)
60
- formattedref << "." unless /\.$/.match?(formattedref.text)
61
- id = reference_format_start(formattedref.parent) and
62
- formattedref.children.first.previous = id
63
- end
64
-
65
- def bibrender_relaton(xml, renderings)
66
- f = renderings[xml["id"]][:formattedref]
67
- ids = reference_format_start(xml)
68
- f &&= "<formattedref>#{ids}#{f}</formattedref>"
69
- # retain date in order to generate reference tag
70
- keep = "./docidentifier | ./uri | ./note | ./date | ./biblio-tag"
71
- xml.children = "#{f}#{xml.xpath(ns(keep)).to_xml}"
72
- end
73
-
74
- def multi_bibitem_ref_code(bib)
75
- skip = IsoDoc::Function::References::SKIP_DOCID
76
- skip1 = "@type = 'metanorma' or @type = 'metanorma-ordinal'"
77
- prim = "[@primary = 'true']"
78
- id = bib.xpath(ns("./docidentifier#{prim}[not(#{skip} or #{skip1})]"))
79
- id.empty? and id = bib.xpath(ns("./docidentifier#{prim}[not(#{skip1})]"))
80
- id.empty? and id = bib.xpath(ns("./docidentifier[not(#{skip} or #{skip1})]"))
81
- id.empty? and id = bib.xpath(ns("./docidentifier[not(#{skip1})]"))
82
- id.empty? and return id
83
- id.sort_by { |i| i["type"] == "ITU" ? 0 : 1 }
84
- end
85
-
86
- def render_multi_identifiers(ids)
87
- ids.map do |id|
88
- if id["type"] == "ITU" then doctype_title(id)
89
- else
90
- docid_prefix(id["type"], id.text.sub(/^\[/, "").sub(/\]$/, ""))
91
- end
92
- end.join("&#xA0;| ")
93
- end
94
-
95
- def reference_format_start(bib)
96
- id = multi_bibitem_ref_code(bib)
97
- id1 = render_multi_identifiers(id)
98
- out = id1
99
- date = bib.at(ns("./date[@type = 'published']/on | " \
100
- "./date[@type = 'published']/from")) and
101
- out << " (#{date.text.sub(/-.*$/, '')})"
102
- out += ", " if date || !id1.empty?
103
- out
104
- end
105
-
106
86
  def titlecase(str)
107
87
  str.gsub(/ |_|-/, " ").split(/ /).map(&:capitalize).join(" ")
108
88
  end
@@ -165,39 +145,6 @@ module IsoDoc
165
145
  super
166
146
  end
167
147
 
168
- def bibliography_bibitem_number1(bib, idx)
169
- mn = bib.at(ns(".//docidentifier[@type = 'metanorma']")) and
170
- /^\[?\d+\]?$/.match?(mn.text) and
171
- mn["type"] = "metanorma-ordinal"
172
- if (mn = bib.at(ns(".//docidentifier[@type = 'metanorma-ordinal']"))) &&
173
- !bibliography_bibitem_number_skip(bib)
174
- idx += 1
175
- mn.children = "[#{idx}]"
176
- end
177
- idx
178
- end
179
-
180
- def bibliography_bibitem_number_skip(bibitem)
181
- @xrefs.klass.implicit_reference(bibitem) ||
182
- bibitem["hidden"] == "true" || bibitem.parent["hidden"] == "true"
183
- end
184
-
185
- def norm_ref_entry_code(_ordinal, idents, _ids, _standard, datefn, _bib)
186
- ret = (idents[:metanorma] || idents[:ordinal] || idents[:sdo]).to_s
187
- /^\[.+\]$/.match?(ret) or ret = "[#{ret}]"
188
- ret += datefn
189
- ret.empty? and return ret
190
- ret.gsub("-", "&#x2011;").gsub(/ /, "&#xa0;")
191
- end
192
-
193
- def biblio_ref_entry_code(_ordinal, idents, _id, _standard, datefn, _bib)
194
- ret = (idents[:metanorma] || idents[:ordinal] || idents[:sdo]).to_s
195
- /^\[.+\]$/.match?(ret) or ret = "[#{ret}]"
196
- ret += datefn
197
- ret.empty? and return ret
198
- ret.gsub("-", "&#x2011;").gsub(/ /, "&#xa0;")
199
- end
200
-
201
148
  def toc_title(docxml)
202
149
  @doctype == "resolution" and return
203
150
  super
@@ -261,6 +208,24 @@ module IsoDoc
261
208
  ret
262
209
  end
263
210
 
211
+ def block(docxml)
212
+ super
213
+ dl docxml
214
+ end
215
+
216
+ def dl(xml)
217
+ (xml.xpath(ns("//dl")) -
218
+ xml.xpath(ns("//table//dl | //figure//dl | //formula//dl")))
219
+ .each do |d|
220
+ dl1(d)
221
+ end
222
+ end
223
+
224
+ def dl1(dlist)
225
+ ins = dlist.at(ns("./dt"))
226
+ ins.previous = '<colgroup><col width="20%"/><col width="80%"/></colgroup>'
227
+ end
228
+
264
229
  include Init
265
230
  end
266
231
  end
@@ -338,29 +338,32 @@
338
338
  </define>
339
339
  <define name="organization">
340
340
  <element name="organization">
341
- <oneOrMore>
342
- <ref name="orgname"/>
343
- </oneOrMore>
344
- <zeroOrMore>
345
- <ref name="subdivision"/>
346
- </zeroOrMore>
347
- <optional>
348
- <ref name="abbreviation"/>
349
- </optional>
350
- <zeroOrMore>
351
- <ref name="uri"/>
352
- </zeroOrMore>
353
- <zeroOrMore>
354
- <ref name="org-identifier"/>
355
- </zeroOrMore>
356
- <zeroOrMore>
357
- <ref name="contact"/>
358
- </zeroOrMore>
359
- <optional>
360
- <ref name="logo"/>
361
- </optional>
341
+ <ref name="OrganizationType"/>
362
342
  </element>
363
343
  </define>
344
+ <define name="OrganizationType">
345
+ <oneOrMore>
346
+ <ref name="orgname"/>
347
+ </oneOrMore>
348
+ <zeroOrMore>
349
+ <ref name="subdivision"/>
350
+ </zeroOrMore>
351
+ <optional>
352
+ <ref name="abbreviation"/>
353
+ </optional>
354
+ <zeroOrMore>
355
+ <ref name="uri"/>
356
+ </zeroOrMore>
357
+ <zeroOrMore>
358
+ <ref name="org-identifier"/>
359
+ </zeroOrMore>
360
+ <zeroOrMore>
361
+ <ref name="contact"/>
362
+ </zeroOrMore>
363
+ <optional>
364
+ <ref name="logo"/>
365
+ </optional>
366
+ </define>
364
367
  <define name="orgname">
365
368
  <element name="name">
366
369
  <choice>
@@ -371,10 +374,10 @@
371
374
  </define>
372
375
  <define name="subdivision">
373
376
  <element name="subdivision">
374
- <choice>
375
- <ref name="LocalizedString"/>
376
- <ref name="NameWithVariants"/>
377
- </choice>
377
+ <optional>
378
+ <attribute name="type"/>
379
+ </optional>
380
+ <ref name="OrganizationType"/>
378
381
  </element>
379
382
  </define>
380
383
  <define name="logo">
@@ -24,6 +24,13 @@ module Metanorma
24
24
  end
25
25
  end
26
26
 
27
+ def header_rows_cleanup(xmldoc)
28
+ super
29
+ xmldoc.xpath("//table/thead/tr/th").each do |x|
30
+ x["align"] = "center"
31
+ end
32
+ end
33
+
27
34
  def insert_missing_sections(xml)
28
35
  xml.at("//metanorma-extension/semantic-metadata/" \
29
36
  "headless[text() = 'true']") and return nil
@@ -36,7 +36,8 @@ module Metanorma
36
36
  end
37
37
 
38
38
  def doctype(node)
39
- ret = node.attr("doctype")&.gsub(/\s+/, "-")&.downcase || "recommendation"
39
+ ret = node.attr("doctype")&.gsub(/\s+/, "-")&.downcase ||
40
+ "recommendation"
40
41
  ret = "recommendation" if ret == "article"
41
42
  ret
42
43
  end
@@ -87,7 +88,7 @@ module Metanorma
87
88
 
88
89
  def sectiontype(node, level = true)
89
90
  ret = super
90
- hdr = sectiontype_streamline(node&.attr("heading")&.downcase)
91
+ hdr = sectiontype_streamline(node.attr("heading")&.downcase)
91
92
  return nil if ret == "terms and definitions" &&
92
93
  hdr != "terms and definitions" && node.level > 1
93
94
  return nil if ret == "symbols and abbreviated terms" &&
@@ -120,10 +121,8 @@ module Metanorma
120
121
  node.option?("unnumbered") and attrs[:unnumbered] = true
121
122
  case sectiontype1(node)
122
123
  when "conventions" then attrs = attrs.merge(type: "conventions")
123
- when "history"
124
- attrs[:preface] and attrs = attrs.merge(type: "history")
125
- when "source"
126
- attrs[:preface] and attrs = attrs.merge(type: "source")
124
+ when "history", "source"
125
+ attrs[:preface] and attrs = attrs.merge(type: sectiontype1(node))
127
126
  end
128
127
  super
129
128
  end
@@ -141,7 +140,8 @@ module Metanorma
141
140
  def presentation_xml_converter(node)
142
141
  IsoDoc::ITU::PresentationXMLConvert
143
142
  .new(html_extract_attributes(node)
144
- .merge(output_formats: ::Metanorma::ITU::Processor.new.output_formats))
143
+ .merge(output_formats: ::Metanorma::ITU::Processor.new
144
+ .output_formats))
145
145
  end
146
146
 
147
147
  def html_converter(node)
@@ -1,5 +1,5 @@
1
1
  module Metanorma
2
2
  module ITU
3
- VERSION = "2.4.2".freeze
3
+ VERSION = "2.4.3".freeze
4
4
  end
5
5
  end
@@ -25,7 +25,8 @@ Gem::Specification.new do |spec|
25
25
  spec.require_paths = ["lib"]
26
26
  spec.required_ruby_version = Gem::Requirement.new(">= 2.7.0")
27
27
 
28
- spec.add_dependency "metanorma-standoc", "~> 2.8.2"
28
+ spec.add_dependency "metanorma-standoc", "~> 2.8.4"
29
+ spec.add_dependency "pubid-itu"
29
30
  spec.add_dependency "twitter_cldr", ">= 3.0.0"
30
31
  spec.add_dependency "tzinfo-data" # we need this for windows only
31
32
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: metanorma-itu
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.4.2
4
+ version: 2.4.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-02-19 00:00:00.000000000 Z
11
+ date: 2024-03-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: metanorma-standoc
@@ -16,14 +16,28 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 2.8.2
19
+ version: 2.8.4
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 2.8.2
26
+ version: 2.8.4
27
+ - !ruby/object:Gem::Dependency
28
+ name: pubid-itu
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: twitter_cldr
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -282,6 +296,7 @@ files:
282
296
  - lib/isodoc/itu/pdf_convert.rb
283
297
  - lib/isodoc/itu/presentation_bibdata.rb
284
298
  - lib/isodoc/itu/presentation_preface.rb
299
+ - lib/isodoc/itu/presentation_ref.rb
285
300
  - lib/isodoc/itu/presentation_xml_convert.rb
286
301
  - lib/isodoc/itu/ref.rb
287
302
  - lib/isodoc/itu/terms.rb