metanorma-iso 2.0.7 → 2.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. checksums.yaml +4 -4
  2. data/lib/asciidoctor/iso/base.rb +0 -1
  3. data/lib/asciidoctor/iso/cleanup.rb +0 -1
  4. data/lib/asciidoctor/iso/converter.rb +0 -1
  5. data/lib/asciidoctor/iso/deprecated.rb +4 -2
  6. data/lib/asciidoctor/iso/front.rb +0 -1
  7. data/lib/asciidoctor/iso/front_id.rb +0 -1
  8. data/lib/asciidoctor/iso/section.rb +0 -1
  9. data/lib/asciidoctor/iso/validate.rb +0 -1
  10. data/lib/asciidoctor/iso/validate_image.rb +0 -1
  11. data/lib/asciidoctor/iso/validate_requirements.rb +0 -1
  12. data/lib/asciidoctor/iso/validate_section.rb +0 -1
  13. data/lib/asciidoctor/iso/validate_style.rb +0 -1
  14. data/lib/asciidoctor/iso/validate_title.rb +0 -1
  15. data/lib/isodoc/iso/html/html_iso_titlepage.html +2 -2
  16. data/lib/isodoc/iso/html/word_iso_titlepage-dis.html +1 -1
  17. data/lib/isodoc/iso/html/word_iso_titlepage.html +2 -2
  18. data/lib/isodoc/iso/i18n-en.yaml +1 -1
  19. data/lib/isodoc/iso/index.rb +1 -1
  20. data/lib/isodoc/iso/iso.amendment.xsl +132 -46
  21. data/lib/isodoc/iso/iso.international-standard.xsl +132 -46
  22. data/lib/isodoc/iso/metadata.rb +74 -56
  23. data/lib/isodoc/iso/presentation_xml_convert.rb +0 -2
  24. data/lib/isodoc/iso/xref.rb +4 -5
  25. data/lib/metanorma/iso/biblio.rng +25 -2
  26. data/lib/metanorma/iso/cleanup.rb +5 -5
  27. data/lib/metanorma/iso/front_id.rb +28 -11
  28. data/lib/metanorma/iso/version.rb +1 -1
  29. data/spec/isodoc/i18n_spec.rb +111 -114
  30. data/spec/isodoc/iso_spec.rb +42 -26
  31. data/spec/metanorma/amd_spec.rb +39 -16
  32. data/spec/metanorma/base_spec.rb +8 -0
  33. data/spec/metanorma/blocks_spec.rb +4 -4
  34. data/spec/metanorma/cleanup_spec.rb +11 -11
  35. data/spec/metanorma/section_spec.rb +3 -3
  36. data/spec/spec_helper.rb +1 -1
  37. metadata +2 -2
@@ -56,10 +56,14 @@ module IsoDoc
56
56
  end
57
57
 
58
58
  def docid(isoxml, _out)
59
- set(:docnumber, isoxml&.at(ns("//bibdata/docidentifier[@type = 'ISO']"))&.text)
60
- set(:tc_docnumber, isoxml.xpath(ns("//bibdata/docidentifier[@type = 'iso-tc']")).map(&:text))
61
- set(:docnumber_lang, isoxml&.at(ns("//bibdata/docidentifier[@type = 'iso-with-lang']"))&.text)
62
- set(:docnumber_reference, isoxml&.at(ns("//bibdata/docidentifier[@type = 'iso-reference']"))&.text)
59
+ set(:tc_docnumber, isoxml
60
+ .xpath(ns("//bibdata/docidentifier[@type = 'iso-tc']")).map(&:text))
61
+ { docnumber: "ISO", docnumber_lang: "iso-with-lang",
62
+ docnumber_reference: "iso-reference",
63
+ docnumber_undated: "iso-undated" }.each do |k, v|
64
+ set(k,
65
+ isoxml&.at(ns("//bibdata/docidentifier[@type = '#{v}']"))&.text)
66
+ end
63
67
  end
64
68
 
65
69
  # we don't leave this to i18n.rb, because we have both English and
@@ -87,55 +91,63 @@ module IsoDoc
87
91
  end
88
92
  end
89
93
 
90
- def part_title(part, partnum, subpartnum, lang)
94
+ def part_title(part, titlenums, lang)
91
95
  return "" unless part
92
96
 
93
97
  suffix = @c.encode(part.text, :hexadecimal)
94
- partnum = "#{partnum}–#{subpartnum}" if partnum && subpartnum
95
- suffix = "#{part_label(lang)} #{partnum}: " + suffix if partnum
98
+ p = titlenums[:part]
99
+ titlenums[:part] && titlenums[:subpart] and
100
+ p = "#{titlenums[:part]}–#{titlenums[:subpart]}"
101
+ titlenums[:part] and
102
+ suffix = "#{part_label(lang)} #{p}: " + suffix
96
103
  suffix
97
104
  end
98
105
 
99
- def part_prefix(partnum, subpartnum, lang)
100
- partnum = "#{partnum}–#{subpartnum}" if partnum && subpartnum
101
- "#{part_label(lang)} #{partnum}"
106
+ def part_prefix(titlenums, lang)
107
+ p = titlenums[:part]
108
+ titlenums[:part] && titlenums[:subpart] and
109
+ p = "#{titlenums[:part]}–#{titlenums[:subpart]}"
110
+ "#{part_label(lang)} #{p}"
102
111
  end
103
112
 
104
- def amd_prefix(num, lang)
105
- "#{amd_label(lang)} #{num}"
113
+ def amd_prefix(titlenums, lang)
114
+ "#{amd_label(lang)} #{titlenums[:amd]}"
106
115
  end
107
116
 
108
- def corr_prefix(num, lang)
109
- "#{corr_label(lang)} #{num}"
117
+ def corr_prefix(titlenums, lang)
118
+ "#{corr_label(lang)} #{titlenums[:corr]}"
110
119
  end
111
120
 
112
- def compose_title(main, intro, part, partnum, subpartnum, lang)
113
- main = main.nil? ? "" : @c.encode(main.text, :hexadecimal)
114
- intro &&
115
- main = "#{@c.encode(intro.text, :hexadecimal)} — #{main}"
116
- if part
117
- suffix = part_title(part, partnum, subpartnum, lang)
121
+ def compose_title(tparts, tnums, lang)
122
+ main = ""
123
+ tparts[:main].nil? or
124
+ main = @c.encode(tparts[:main].text, :hexadecimal)
125
+ tparts[:intro] &&
126
+ main = "#{@c.encode(tparts[:intro].text,
127
+ :hexadecimal)} — #{main}"
128
+ if tparts[:part]
129
+ suffix = part_title(tparts[:part], tnums, lang)
118
130
  main = "#{main} — #{suffix}"
119
131
  end
120
132
  main
121
133
  end
122
134
 
123
135
  def title_nums(isoxml)
124
- [isoxml.at(ns("//bibdata//project-number/@part")),
125
- isoxml.at(ns("//bibdata//project-number/@subpart")),
126
- isoxml.at(ns("//bibdata//project-number/@amendment")),
127
- isoxml.at(ns("//bibdata//project-number/@corrigendum"))]
136
+ { part: isoxml.at(ns("//bibdata//project-number/@part")),
137
+ subpart: isoxml.at(ns("//bibdata//project-number/@subpart")),
138
+ amd: isoxml.at(ns("//bibdata//project-number/@amendment")),
139
+ corr: isoxml.at(ns("//bibdata//project-number/@corrigendum")) }
128
140
  end
129
141
 
130
142
  def title_parts(isoxml, lang)
131
- [isoxml.at(ns("//bibdata//title[@type='title-intro' and "\
132
- "@language='#{lang}']")),
133
- isoxml.at(ns("//bibdata//title[@type='title-main' and "\
134
- "@language='#{lang}']")),
135
- isoxml.at(ns("//bibdata//title[@type='title-part' and "\
136
- "@language='#{lang}']")),
137
- isoxml.at(ns("//bibdata//title[@type='title-amd' and "\
138
- "@language='#{lang}']"))]
143
+ { intro: isoxml.at(ns("//bibdata//title[@type='title-intro' and "\
144
+ "@language='#{lang}']")),
145
+ main: isoxml.at(ns("//bibdata//title[@type='title-main' and "\
146
+ "@language='#{lang}']")),
147
+ part: isoxml.at(ns("//bibdata//title[@type='title-part' and "\
148
+ "@language='#{lang}']")),
149
+ amd: isoxml.at(ns("//bibdata//title[@type='title-amd' and "\
150
+ "@language='#{lang}']")) }
139
151
  end
140
152
 
141
153
  def title(isoxml, _out)
@@ -144,40 +156,46 @@ module IsoDoc
144
156
  when "ru" then "ru"
145
157
  else "en"
146
158
  end
147
- intro, main, part, amd = title_parts(isoxml, lang)
148
- partnumber, subpartnumber, amdnumber, corrnumber = title_nums(isoxml)
159
+ # intro, main, part, amd = title_parts(isoxml, lang)
160
+ tp = title_parts(isoxml, lang)
161
+ tn = title_nums(isoxml)
149
162
 
150
- set(:doctitlemain, @c.encode(main ? main.text : "", :hexadecimal))
151
- main = compose_title(main, intro, part, partnumber, subpartnumber, lang)
163
+ set(:doctitlemain,
164
+ @c.encode(tp[:main] ? tp[:main].text : "", :hexadecimal))
165
+ main = compose_title(tp, tn, lang)
152
166
  set(:doctitle, main)
153
- if intro
167
+ if tp[:intro]
154
168
  set(:doctitleintro,
155
- @c.encode(intro ? intro.text : "", :hexadecimal))
169
+ @c.encode(tp[:intro] ? tp[:intro].text : "", :hexadecimal))
156
170
  end
157
- set(:doctitlepartlabel, part_prefix(partnumber, subpartnumber, lang))
158
- set(:doctitlepart, @c.encode(part.text, :hexadecimal)) if part
159
- set(:doctitleamdlabel, amd_prefix(amdnumber, lang)) if amdnumber
160
- set(:doctitleamd, @c.encode(amd.text, :hexadecimal)) if amd
161
- set(:doctitlecorrlabel, corr_prefix(corrnumber, lang)) if corrnumber
171
+ set(:doctitlepartlabel, part_prefix(tn, lang))
172
+ set(:doctitlepart, @c.encode(tp[:part].text, :hexadecimal)) if tp[:part]
173
+ set(:doctitleamdlabel, amd_prefix(tn, lang)) if tn[:amd]
174
+ set(:doctitleamd, @c.encode(tp[:amd].text, :hexadecimal)) if tp[:amd]
175
+ set(:doctitlecorrlabel, corr_prefix(tn, lang)) if tn[:corr]
162
176
  end
163
177
 
164
178
  def subtitle(isoxml, _out)
165
179
  lang = @lang == "en" ? "fr" : "en"
166
- intro, main, part, amd = title_parts(isoxml, lang)
167
- partnumber, subpartnumber, amdnumber, corrnumber = title_nums(isoxml)
180
+ tp = title_parts(isoxml, lang)
181
+ tn = title_nums(isoxml)
168
182
 
169
- set(:docsubtitlemain, @c.encode(main ? main.text : "", :hexadecimal))
170
- main = compose_title(main, intro, part, partnumber, subpartnumber, lang)
183
+ set(:docsubtitlemain,
184
+ @c.encode(tp[:main] ? tp[:main].text : "", :hexadecimal))
185
+ main = compose_title(tp, tn, lang)
171
186
  set(:docsubtitle, main)
172
- if intro
187
+ if tp[:intro]
173
188
  set(:docsubtitleintro,
174
- @c.encode(intro ? intro.text : "", :hexadecimal))
189
+ @c.encode(tp[:intro] ? tp[:intro].text : "", :hexadecimal))
190
+ end
191
+ set(:docsubtitlepartlabel, part_prefix(tn, lang))
192
+ if tp[:part]
193
+ set(:docsubtitlepart,
194
+ @c.encode(tp[:part].text, :hexadecimal))
175
195
  end
176
- set(:docsubtitlepartlabel, part_prefix(partnumber, subpartnumber, lang))
177
- set(:docsubtitlepart, @c.encode(part.text, :hexadecimal)) if part
178
- set(:docsubtitleamdlabel, amd_prefix(amdnumber, lang)) if amdnumber
179
- set(:docsubtitleamd, @c.encode(amd.text, :hexadecimal)) if amd
180
- set(:docsubtitlecorrlabel, corr_prefix(corrnumber, lang)) if corrnumber
196
+ set(:docsubtitleamdlabel, amd_prefix(tn, lang)) if tn[:amd]
197
+ set(:docsubtitleamd, @c.encode(tp[:amd].text, :hexadecimal)) if tp[:amd]
198
+ set(:docsubtitlecorrlabel, corr_prefix(tn, lang)) if tn[:corr]
181
199
  end
182
200
 
183
201
  def author(xml, _out)
@@ -231,8 +249,8 @@ module IsoDoc
231
249
  ics = []
232
250
  isoxml.xpath(ns("//bibdata/ext/ics/code")).each { |i| ics << i.text }
233
251
  set(:ics, ics.empty? ? nil : ics.join(", "))
234
- a = isoxml.at(ns("//bibdata/ext/horizontal")) and set(:horizontal,
235
- a.text)
252
+ a = isoxml.at(ns("//bibdata/ext/horizontal")) and
253
+ set(:horizontal, a.text)
236
254
  end
237
255
  end
238
256
  end
@@ -27,8 +27,6 @@ module IsoDoc
27
27
  end
28
28
 
29
29
  def figure1(node)
30
- return if labelled_ancestor(node) && node.ancestors("figure").empty?
31
-
32
30
  lbl = @xrefs.anchor(node["id"], :label, false) or return
33
31
  figname = node.parent.name == "figure" ? "" : "#{@i18n.figure} "
34
32
  connective = node.parent.name == "figure" ? "&nbsp; " : "&nbsp;&mdash; "
@@ -113,7 +113,7 @@ module IsoDoc
113
113
  def hierarchical_formula_names(clause, num)
114
114
  c = IsoDoc::XrefGen::Counter.new
115
115
  clause.xpath(ns(".//formula")).each do |t|
116
- next if t["id"].nil? || t["id"].empty?
116
+ next if blank?(t["id"])
117
117
 
118
118
  @anchors[t["id"]] = anchor_struct(
119
119
  "#{num}#{hiersep}#{c.increment(t).print}", t,
@@ -133,13 +133,12 @@ module IsoDoc
133
133
  end
134
134
 
135
135
  def sequential_figure_names(clause)
136
- c = IsoDoc::XrefGen::Counter.new
137
136
  j = 0
138
137
  clause.xpath(ns(".//figure | .//sourcecode[not(ancestor::example)]"))
139
- .each do |t|
138
+ .each_with_object(IsoDoc::XrefGen::Counter.new) do |t, c|
140
139
  j = subfigure_increment(j, c, t)
141
140
  sublabel = j.zero? ? nil : "#{(j + 96).chr})"
142
- next if t["id"].nil? || t["id"].empty?
141
+ next if blank?(t["id"])
143
142
 
144
143
  figure_anchor(t, sublabel, c.print)
145
144
  end
@@ -153,7 +152,7 @@ module IsoDoc
153
152
  j = subfigure_increment(j, c, t)
154
153
  label = "#{num}#{hiersep}#{c.print}"
155
154
  sublabel = j.zero? ? nil : "#{(j + 96).chr})"
156
- next if t["id"].nil? || t["id"].empty?
155
+ next if blank?(t["id"])
157
156
 
158
157
  figure_anchor(t, sublabel, label)
159
158
  end
@@ -527,7 +527,7 @@
527
527
  </define>
528
528
  <define name="LocalityType">
529
529
  <data type="string">
530
- <param name="pattern">section|clause|part|paragraph|chapter|page|whole|table|annex|figure|note|list|example|volume|issue|time|anchor|locality:[a-zA-Z0-9_]+</param>
530
+ <param name="pattern">section|clause|part|paragraph|chapter|page|title|line|whole|table|annex|figure|note|list|example|volume|issue|time|anchor|locality:[a-zA-Z0-9_]+</param>
531
531
  </data>
532
532
  </define>
533
533
  <define name="referenceFrom">
@@ -677,6 +677,9 @@
677
677
  <zeroOrMore>
678
678
  <ref name="extent"/>
679
679
  </zeroOrMore>
680
+ <optional>
681
+ <ref name="bibliographic_size"/>
682
+ </optional>
680
683
  <zeroOrMore>
681
684
  <ref name="accesslocation"/>
682
685
  </zeroOrMore>
@@ -922,9 +925,29 @@
922
925
  <text/>
923
926
  </element>
924
927
  </define>
928
+ <define name="sizevalue">
929
+ <element name="value">
930
+ <attribute name="type"/>
931
+ <text/>
932
+ </element>
933
+ </define>
934
+ <define name="bibliographic_size">
935
+ <element name="size">
936
+ <oneOrMore>
937
+ <ref name="sizevalue"/>
938
+ </oneOrMore>
939
+ </element>
940
+ </define>
925
941
  <define name="extent">
926
942
  <element name="extent">
927
- <ref name="BibItemLocality"/>
943
+ <choice>
944
+ <zeroOrMore>
945
+ <ref name="locality"/>
946
+ </zeroOrMore>
947
+ <zeroOrMore>
948
+ <ref name="localityStack"/>
949
+ </zeroOrMore>
950
+ </choice>
928
951
  </element>
929
952
  </define>
930
953
  <define name="series">
@@ -51,10 +51,10 @@ module Metanorma
51
51
  id.content = id_prefix(prefix, id)
52
52
  id = xmldoc.at("//bibdata/ext/structuredidentifier/project-number") and
53
53
  id.content = id_prefix(prefix, id)
54
- id = xmldoc.at("//bibdata/docidentifier[@type = 'iso-with-lang']") and
55
- id.content = id_prefix(prefix, id)
56
- id = xmldoc.at("//bibdata/docidentifier[@type = 'iso-reference']") and
57
- id.content = id_prefix(prefix, id)
54
+ %w(iso-with-lang iso-reference iso-undated).each do |t|
55
+ id = xmldoc.at("//bibdata/docidentifier[@type = '#{t}']") and
56
+ id.content = id_prefix(prefix, id)
57
+ end
58
58
  end
59
59
 
60
60
  def format_ref(ref, type)
@@ -140,7 +140,7 @@ module Metanorma
140
140
  xmldoc.xpath("//bibitem/note[@type = 'Unpublished-Status']").each do |n|
141
141
  e = xmldoc.at("//eref[@bibitemid = '#{n.parent['id']}']") or next
142
142
  fn = n.children.to_xml
143
- n&.elements&.first&.name == "p" or fn = "<p>#{fn}</p>"
143
+ n.elements&.first&.name == "p" or fn = "<p>#{fn}</p>"
144
144
  e.next = "<fn>#{fn}</fn>"
145
145
  end
146
146
  end
@@ -73,13 +73,19 @@ module Metanorma
73
73
  (!@amd && node.attr("docnumber")) || (@amd && node.attr("updates")) or
74
74
  return
75
75
 
76
- dn = iso_id1(node)
77
- dn1 = id_stage_prefix(dn, node, false)
78
- dn2 = id_stage_prefix(dn, node, true)
79
- xml.docidentifier dn1, **attr_code(type: "ISO")
80
- xml.docidentifier(id_langsuffix(dn1, node),
76
+ dn = id_stage_prefix(iso_id1(node), node)
77
+ dns = [id_year(dn, node, mode: :default),
78
+ id_year(dn, node, mode: :force),
79
+ id_year(dn, node, mode: :strip)]
80
+ iso_id_out(node, xml, dns)
81
+ end
82
+
83
+ def iso_id_out(node, xml, dns)
84
+ xml.docidentifier dns[0], **attr_code(type: "ISO")
85
+ xml.docidentifier dns[2], **attr_code(type: "iso-undated")
86
+ xml.docidentifier(id_langsuffix(dns[0], node),
81
87
  **attr_code(type: "iso-with-lang"))
82
- xml.docidentifier(id_langsuffix(dn2, node),
88
+ xml.docidentifier(id_langsuffix(dns[1], node),
83
89
  **attr_code(type: "iso-reference"))
84
90
  end
85
91
 
@@ -160,14 +166,14 @@ module Metanorma
160
166
  def cover_stage_abbr(node)
161
167
  stage = get_stage(node)
162
168
  abbr = id_stage_abbr(get_stage(node), get_substage(node), node, true)
163
- typeabbr = get_typeabbr(node, true)
169
+ typeabbr = get_typeabbr(node, amd: true)
164
170
  if stage.to_i > 50 || (stage.to_i == 60 && get_substage(node).to_i < 60)
165
171
  typeabbr = ""
166
172
  end
167
173
  "#{abbr}#{typeabbr}".strip
168
174
  end
169
175
 
170
- def id_stage_prefix(docnum, node, force_year)
176
+ def id_stage_prefix(docnum, node)
171
177
  stage = get_stage(node)
172
178
  typeabbr = get_typeabbr(node)
173
179
  if stage && (stage.to_i < 60)
@@ -175,11 +181,22 @@ module Metanorma
175
181
  elsif typeabbr == "DIR " then docnum = "#{typeabbr}#{docnum}"
176
182
  elsif typeabbr && !@amd then docnum = "/#{typeabbr}#{docnum}"
177
183
  end
178
- (force_year || !(stage && (stage.to_i < 60))) and
179
- docnum = id_add_year(docnum, node)
180
184
  docnum
181
185
  end
182
186
 
187
+ def id_year(docnum, node, mode: :default)
188
+ case mode
189
+ when :strip then docnum.sub(/:(19|20)\d\d(?!\d)/, "")
190
+ when :force then id_add_year(docnum, node)
191
+ else
192
+ stage = get_stage(node)
193
+ if stage && (stage.to_i < 60)
194
+ docnum
195
+ else id_add_year(docnum, node)
196
+ end
197
+ end
198
+ end
199
+
183
200
  def unpub_stage_prefix(docnum, stage, typeabbr, node)
184
201
  abbr = id_stage_abbr(stage, get_substage(node), node)
185
202
  %w(40 50).include?(stage) && i = node.attr("iteration") and
@@ -213,7 +230,7 @@ module Metanorma
213
230
  ret
214
231
  end
215
232
 
216
- def get_typeabbr(node, amd = false)
233
+ def get_typeabbr(node, amd: false)
217
234
  case doctype(node)
218
235
  when "directive" then "DIR "
219
236
  when "technical-report" then "TR "
@@ -1,5 +1,5 @@
1
1
  module Metanorma
2
2
  module ISO
3
- VERSION = "2.0.7".freeze
3
+ VERSION = "2.0.8".freeze
4
4
  end
5
5
  end