metanorma-iso 2.1.6 → 2.1.9

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 (56) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/rake.yml +3 -1
  3. data/.github/workflows/release.yml +24 -0
  4. data/lib/isodoc/iso/html/html_iso_titlepage.html +2 -2
  5. data/lib/isodoc/iso/html/style-human.css +34 -2
  6. data/lib/isodoc/iso/html/style-human.scss +35 -1
  7. data/lib/isodoc/iso/html/style-iso.css +34 -2
  8. data/lib/isodoc/iso/html/style-iso.scss +36 -1
  9. data/lib/isodoc/iso/i18n-en.yaml +4 -0
  10. data/lib/isodoc/iso/i18n-fr.yaml +5 -0
  11. data/lib/isodoc/iso/i18n-ru.yaml +4 -0
  12. data/lib/isodoc/iso/i18n-zh-Hans.yaml +5 -0
  13. data/lib/isodoc/iso/init.rb +4 -0
  14. data/lib/isodoc/iso/iso.amendment.xsl +195 -197
  15. data/lib/isodoc/iso/iso.international-standard.xsl +195 -197
  16. data/lib/isodoc/iso/presentation_xml_convert.rb +22 -6
  17. data/lib/isodoc/iso/xref.rb +35 -4
  18. data/lib/metanorma/iso/base.rb +4 -0
  19. data/lib/metanorma/iso/biblio.rng +8 -5
  20. data/lib/metanorma/iso/cleanup.rb +5 -1
  21. data/lib/metanorma/iso/front_id.rb +63 -38
  22. data/lib/metanorma/iso/section.rb +5 -0
  23. data/lib/metanorma/iso/validate.rb +3 -2
  24. data/lib/metanorma/iso/version.rb +1 -1
  25. data/lib/metanorma/requirements/modspec.rb +60 -0
  26. data/lib/metanorma/requirements/requirements.rb +16 -0
  27. data/lib/metanorma-iso.rb +2 -1
  28. data/metanorma-iso.gemspec +1 -1
  29. data/spec/assets/iso.adoc +10 -0
  30. data/spec/examples/rice_img/1000-1_ed2amd3fig1a.png +0 -0
  31. data/spec/examples/rice_img/1000-1_ed2amd3fig1b.png +0 -0
  32. data/spec/examples/rice_img/1000-1_ed2amd3fig2.png +0 -0
  33. data/spec/examples/rice_img/1000-1_ed2amd3fig3.png +0 -0
  34. data/spec/examples/rice_img/1000-1_ed2amd3fig4.png +0 -0
  35. data/spec/examples/rice_img/1000-1_ed2amd3fig5_f.png +0 -0
  36. data/spec/examples/rice_img/1000-1_ed2amd3figA.png +0 -0
  37. data/spec/examples/rice_img/1000-1_ed2amd3figA1.png +0 -0
  38. data/spec/examples/rice_img/1000-1_ed2amd3figA2.png +0 -0
  39. data/spec/examples/rice_img/1000-1_ed2amd3figTab1.png +0 -0
  40. data/spec/examples/rice_img/1000-1_ed2amd3figTab2.png +0 -0
  41. data/spec/examples/rice_img/1001_ed2amd3fig1.png +0 -0
  42. data/spec/examples/rice_img/ISO_1213_1.png +0 -0
  43. data/spec/examples/rice_img/SL1000-1_ed2amd3fig1.png +0 -0
  44. data/spec/isodoc/ref_spec.rb +129 -82
  45. data/spec/metanorma/amd_spec.rb +0 -10
  46. data/spec/metanorma/base_spec.rb +15 -12
  47. data/spec/metanorma/cleanup_spec.rb +136 -0
  48. data/spec/metanorma/macros_spec.rb +99 -0
  49. data/spec/metanorma/processor_spec.rb +86 -86
  50. data/spec/metanorma/section_spec.rb +2 -2
  51. data/spec/metanorma/validate_spec.rb +41 -40
  52. data/spec/requirements/requirements_spec.rb +1299 -0
  53. data/spec/requirements/xref_spec.rb +1205 -0
  54. data/spec/vcr_cassettes/docrels.yml +385 -0
  55. data/spec/vcr_cassettes/withdrawn_iso.yml +21 -21
  56. metadata +40 -18
@@ -17,6 +17,24 @@ module IsoDoc
17
17
  super
18
18
  end
19
19
 
20
+ def block(docxml)
21
+ amend docxml
22
+ figure docxml
23
+ sourcecode docxml
24
+ formula docxml
25
+ admonition docxml
26
+ ol docxml
27
+ permission docxml
28
+ requirement docxml
29
+ recommendation docxml
30
+ requirement_render docxml
31
+ @xrefs.anchors_previous = @xrefs.anchors.dup # store old xrefs of reqts
32
+ @xrefs.parse docxml
33
+ table docxml # have table include requirements newly converted to tables
34
+ example docxml
35
+ note docxml
36
+ end
37
+
20
38
  def annex(isoxml)
21
39
  amd(isoxml) and @suppressheadingnumbers = @oldsuppressheadingnumbers
22
40
  super
@@ -178,12 +196,10 @@ module IsoDoc
178
196
  i18nhash: @i18n.get)
179
197
  end
180
198
 
181
- def bibrender(xml)
182
- unless xml.at(ns("./formattedref"))
183
- xml.children =
184
- "#{bibrenderer.render(xml.to_xml)}"\
185
- "#{xml.xpath(ns('./docidentifier | ./uri | ./note')).to_xml}"
186
- end
199
+ def bibrender_formattedref(formattedref, xml)
200
+ return if %w(techreport standard).include? xml["type"]
201
+
202
+ super
187
203
  end
188
204
 
189
205
  def ol_depth(node)
@@ -4,11 +4,11 @@ module IsoDoc
4
4
  end
5
5
 
6
6
  class Xref < IsoDoc::Xref
7
+ attr_accessor :anchors_previous, :anchors
8
+
7
9
  def initial_anchor_names(doc)
8
- if @klass.amd(doc)
9
- initial_anchor_names_amd(doc)
10
- else
11
- initial_anchor_names1(doc)
10
+ if @klass.amd(doc) then initial_anchor_names_amd(doc)
11
+ else initial_anchor_names1(doc)
12
12
  end
13
13
  if @parse_settings.empty? || @parse_settings[:clauses]
14
14
  introduction_names(doc.at(ns("//introduction")))
@@ -217,6 +217,37 @@ module IsoDoc
217
217
  end
218
218
  true
219
219
  end
220
+
221
+ def sequential_table_names(clause)
222
+ super
223
+ modspec_table_xrefs(clause) if @anchors_previous
224
+ end
225
+
226
+ def modspec_table_xrefs(clause)
227
+ clause.xpath(ns(".//table[@class = 'modspec']")).noblank.each do |t|
228
+ (@anchors[t["id"]] && !@anchors[t["id"]][:modspec]) or next
229
+ n = @anchors[t["id"]][:xref]
230
+ @anchors[t["id"]][:modspec] = true
231
+ @anchors[t["id"]][:xref] =
232
+ l10n("#{n}, #{@anchors_previous[t['id']][:xref_bare]}")
233
+ modspec_table_components_xrefs(t, n)
234
+ end
235
+ end
236
+
237
+ def modspec_table_components_xrefs(table, table_label)
238
+ table.xpath(ns(".//tr[@id]")).each do |tr|
239
+ (@anchors[tr["id"]] && !@anchors[tr["id"]][:modspec]) or next
240
+ @anchors[tr["id"]][:modspec] = true
241
+ @anchors[tr["id"]][:xref] =
242
+ l10n("#{table_label}, #{@anchors_previous[tr['id']][:xref]}")
243
+ @anchors[tr["id"]].delete(:container)
244
+ end
245
+ end
246
+
247
+ def hierarchical_table_names(clause, _num)
248
+ super
249
+ modspec_table_xrefs(clause) if @anchors_previous
250
+ end
220
251
  end
221
252
  end
222
253
  end
@@ -12,6 +12,10 @@ module Metanorma
12
12
  XML_ROOT_TAG = "iso-standard".freeze
13
13
  XML_NAMESPACE = "https://www.metanorma.org/ns/iso".freeze
14
14
 
15
+ def requirements_processor
16
+ ::Metanorma::Requirements::Iso
17
+ end
18
+
15
19
  def html_converter(node)
16
20
  IsoDoc::Iso::HtmlConvert.new(html_extract_attributes(node))
17
21
  end
@@ -225,9 +225,9 @@
225
225
  <zeroOrMore>
226
226
  <ref name="forename"/>
227
227
  </zeroOrMore>
228
- <zeroOrMore>
229
- <ref name="initial"/>
230
- </zeroOrMore>
228
+ <optional>
229
+ <ref name="formatted-initials"/>
230
+ </optional>
231
231
  <ref name="surname"/>
232
232
  <zeroOrMore>
233
233
  <ref name="addition"/>
@@ -247,8 +247,8 @@
247
247
  <ref name="LocalizedString"/>
248
248
  </element>
249
249
  </define>
250
- <define name="initial">
251
- <element name="initial">
250
+ <define name="formatted-initials">
251
+ <element name="formatted-initials">
252
252
  <ref name="LocalizedString"/>
253
253
  </element>
254
254
  </define>
@@ -264,6 +264,9 @@
264
264
  </define>
265
265
  <define name="forename">
266
266
  <element name="forename">
267
+ <optional>
268
+ <attribute name="initial"/>
269
+ </optional>
267
270
  <ref name="LocalizedString"/>
268
271
  </element>
269
272
  </define>
@@ -88,7 +88,6 @@ module Metanorma
88
88
  end
89
89
  end
90
90
 
91
- # TODO sort by authors
92
91
  # sort by: doc class (ISO, IEC, other standard (not DOI &c), other
93
92
  # then standard class (docid class other than DOI &c)
94
93
  # then docnumber if present, numeric sort
@@ -205,6 +204,11 @@ module Metanorma
205
204
  super
206
205
  end
207
206
 
207
+ def term_children_cleanup(xmldoc)
208
+ @vocab and return
209
+ super
210
+ end
211
+
208
212
  def bibdata_cleanup(xmldoc)
209
213
  super
210
214
  approval_groups_rename(xmldoc)
@@ -7,33 +7,6 @@ require "open-uri"
7
7
  require "twitter_cldr"
8
8
  require "pubid-iso"
9
9
 
10
- # @param stage [String] stage, eg. "WD", "CD", "DIS"
11
- # @param urn_stage [Float] numeric stage for URN rendering
12
- # @param iteration [Integer] document iteration, eg. "1", "2", "3"
13
- # @param joint_document [Identifier] joint document
14
- # @param supplement [Supplement] supplement
15
- # @param tctype [String] Technical Committee type, eg. "TC", "JTC"
16
- # @param sctype [String] TC subsommittee, eg. "SC"
17
- # @param wgtype [String] TC working group type, eg. "AG", "AHG"
18
- # @param tcnumber [Integer] Technical Committee number, eg. "1", "2"
19
- # @param scnumber [Integer] Subsommittee number, eg. "1", "2"
20
- # @param wgnumber [Integer] Working group number, eg. "1", "2"
21
- # @param dir [Boolean] Directives document
22
- # @param dirtype [String] Directives document type, eg. "JTC"
23
- # @see Supplement
24
- # @see Identifier
25
- # @see Pubid::Core::Identifier
26
- # @see Parser
27
- #
28
- =begin
29
- def initialize(number: nil, stage: nil, iteration: nil, supplement: nil,
30
- joint_document: nil, urn_stage: nil,
31
- tctype: nil, sctype: nil, wgtype: nil, tcnumber: nil,
32
- scnumber: nil, wgnumber:nil,
33
- dir: nil, dirtype: nil, **opts)
34
- super(**opts.merge(number: number))
35
- =end
36
-
37
10
  module Metanorma
38
11
  module ISO
39
12
  class Converter < Standoc::Converter
@@ -100,7 +73,6 @@ module Metanorma
100
73
  def iso_id(node, xml)
101
74
  (!@amd && node.attr("docnumber")) || (@amd && node.attr("updates")) or
102
75
  return
103
-
104
76
  dn = id_stage_prefix(iso_id1(node), node)
105
77
  dns = [id_year(dn, node, mode: :default),
106
78
  id_year(dn, node, mode: :force),
@@ -117,6 +89,69 @@ module Metanorma
117
89
  **attr_code(type: "iso-reference"))
118
90
  end
119
91
 
92
+ def get_typeabbr(node, amd: false)
93
+ case doctype(node)
94
+ when "directive" then "DIR "
95
+ when "technical-report" then "TR "
96
+ when "technical-specification" then "TS "
97
+ when "amendment" then (amd ? "Amd " : "")
98
+ when "technical-corrigendum" then (amd ? "Cor " : "")
99
+ end
100
+ end
101
+
102
+ =begin
103
+ def get_typeabbr(node, amd: false)
104
+ case doctype(node)
105
+ when "directive" then "DIR"
106
+ when "technical-report" then "TR"
107
+ when "technical-specification" then "TS"
108
+ else nil
109
+ end
110
+ end
111
+
112
+ def iso_id(node, xml)
113
+ (!@amd && node.attr("docnumber")) || (@amd && node.attr("updates")) or
114
+ return
115
+ stage = id_stage_abbr(get_stage(node), get_substage(node), node, true)&.strip
116
+ stage = nil if %w{IS (Review) (Withdrwal)}.include?(stage.strip)
117
+ urn_stage = "#{get_stage(node)}.#{get_substage(node)}"
118
+ pub = (node.attr("publisher") || "ISO").split(/[;,]/)
119
+ params = {
120
+ number: node.attr("docnumber"), # (@amd ? node.attr("updates") : node.attr("docnumber")),
121
+ part: node.attr("partnumber"),
122
+ language: node.attr("language") || "en",
123
+ type: get_typeabbr(node),
124
+ year: node.attr("copyright-year") || node.attr("updated-date")&.sub(/-.*$/, ""),
125
+ publisher: pub[0],
126
+ copublisher: pub[1..-1],
127
+ }.compact
128
+ if a = node.attr("amendment-number")
129
+ params[:amendments] = { number: a, stage: stage }
130
+ elsif a = node.attr("corrigendum-number")
131
+ params[:corrigendums] = { number: a, stage: stage }
132
+ else
133
+ params.merge!( { stage: stage, urn_stage: urn_stage }.compact )
134
+ end
135
+ iso_id_out(xml, params)
136
+ end
137
+
138
+ def iso_id_out(xml, params)
139
+ params_nolang = params.dup.tap { |hs| hs.delete(:language) }
140
+ unpub = /^[0-5]/.match?(params[:urn_stage])
141
+ params1 = unpub ? params_nolang.dup.tap { |hs| hs.delete(:year) } : params_nolang
142
+ xml.docidentifier Pubid::Iso::Identifier.new(**params1), **attr_code(type: "ISO")
143
+ params2 = params_nolang.dup.tap { |hs| hs.delete(:year) }
144
+ xml.docidentifier Pubid::Iso::Identifier.new(**params2), **attr_code(type: "iso-undated")
145
+ params1 = unpub ? params.dup.tap { |hs| hs.delete(:year) } : params
146
+ xml.docidentifier(Pubid::Iso::Identifier.new(**params1),
147
+ **attr_code(type: "iso-with-lang"))
148
+ warn params
149
+ warn "Generated: #{Pubid::Iso::Identifier.new(**params).to_s}"
150
+ xml.docidentifier(Pubid::Iso::Identifier.new(**params),
151
+ **attr_code(type: "iso-reference"))
152
+ end
153
+ =end
154
+
120
155
  def iso_id1(node)
121
156
  if @amd
122
157
  dn = node.attr("updates")
@@ -259,16 +294,6 @@ module Metanorma
259
294
  ret = (stage == "60" ? "60" : "00") if ret.nil? || ret.empty?
260
295
  ret
261
296
  end
262
-
263
- def get_typeabbr(node, amd: false)
264
- case doctype(node)
265
- when "directive" then "DIR "
266
- when "technical-report" then "TR "
267
- when "technical-specification" then "TS "
268
- when "amendment" then (amd ? "Amd " : "")
269
- when "technical-corrigendum" then (amd ? "Cor " : "")
270
- end
271
- end
272
297
  end
273
298
  end
274
299
  end
@@ -44,6 +44,11 @@ module Metanorma
44
44
  return term_def_subclause_parse1(attrs, xml, node)
45
45
  super
46
46
  end
47
+
48
+ def term_contains_subclauses(node)
49
+ @vocab and return false # treat this as a term
50
+ super
51
+ end
47
52
  end
48
53
  end
49
54
  end
@@ -90,11 +90,12 @@ module Metanorma
90
90
  end
91
91
 
92
92
  def term_xrefs_validate1(xref, termids)
93
- (termids[xref["target"]] && !termids[xref.parent["id"]]) and
93
+ closest_id = xref.xpath("./ancestor::*[@id]")&.last or return
94
+ (termids[xref["target"]] && !termids[closest_id["id"]]) and
94
95
  @log.add("Style", xref,
95
96
  "only terms clauses can cross-reference terms clause "\
96
97
  "(#{xref['target']})")
97
- (!termids[xref["target"]] && termids[xref.parent["id"]]) and
98
+ (!termids[xref["target"]] && termids[closest_id["id"]]) and
98
99
  @log.add("Style", xref,
99
100
  "non-terms clauses cannot cross-reference terms clause "\
100
101
  "(#{xref['target']})")
@@ -1,5 +1,5 @@
1
1
  module Metanorma
2
2
  module ISO
3
- VERSION = "2.1.6".freeze
3
+ VERSION = "2.1.9".freeze
4
4
  end
5
5
  end
@@ -0,0 +1,60 @@
1
+ module Metanorma
2
+ class Requirements
3
+ class Modspec
4
+ # Don't want to inherit from Metanorma::Requirements::Modspec
5
+ class Iso < ::Metanorma::Requirements::Modspec
6
+ def recommendation_label(elem, type, xrefs)
7
+ lbl = super
8
+ title = elem.at(ns("./title"))
9
+ return lbl unless title # &&
10
+
11
+ # elem.ancestors("requirement, recommendation, permission").empty?
12
+
13
+ lbl += l10n(": ") if lbl
14
+ lbl += title.children.to_xml
15
+ lbl
16
+ end
17
+
18
+ # ISO labels modspec reqt as table, with reqt label as title
19
+ def recommendation_header(reqt, out)
20
+ n = reqt.at(ns("./name")) and out << n
21
+ out
22
+ end
23
+
24
+ def recommend_title(node, out)
25
+ label = node.at(ns("./identifier")) or return
26
+ out.add_child("<tr><td>#{@labels['modspec']['identifier']}</td>"\
27
+ "<td><tt>#{label.children.to_xml}</tt></td>")
28
+ end
29
+
30
+ def requirement_component_parse(node, out)
31
+ if node["exclude"] != "true" && node.name == "description"
32
+ lbl = "statement"
33
+ lbl = "declaration" if recommend_class(node) == "recommendclass"
34
+ out << "<tr><td>#{@labels['modspec'][lbl]}</td>"\
35
+ "<td>#{node.children.to_xml}</td></tr>"
36
+ else
37
+ super
38
+ end
39
+ end
40
+
41
+ def requirement_table_cleanup(table)
42
+ return table unless table["type"] == "recommendclass"
43
+
44
+ ins = table.at(ns("./tbody/tr[td/table]")) or return table
45
+ ins.replace("<tr><td>#{@labels['modspec']['provisions']}</td>" +
46
+ "<td>#{nested_tables_names(table)}</td></tr>")
47
+ table.xpath(ns("./tbody/tr[td/table]")).each(&:remove)
48
+ table
49
+ end
50
+
51
+ def nested_tables_names(table)
52
+ table.xpath(ns("./tbody/tr/td/table"))
53
+ .each_with_object([]) do |t, m|
54
+ m << t.at(ns("./name")).children.to_xml
55
+ end.join("<br/>")
56
+ end
57
+ end
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,16 @@
1
+ require "mn-requirements"
2
+ require_relative "modspec"
3
+
4
+ module Metanorma
5
+ class Requirements
6
+ class Iso < ::Metanorma::Requirements
7
+ def create(type)
8
+ case type
9
+ when :modspec, :ogc
10
+ ::Metanorma::Requirements::Modspec::Iso.new(parent: self)
11
+ else ::Metanorma::Requirements::Default.new(parent: self)
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
data/lib/metanorma-iso.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  require "asciidoctor" unless defined? Asciidoctor::Converter
2
2
  require_relative "metanorma/iso/converter"
3
3
  require_relative "metanorma/iso/version"
4
+ require_relative "metanorma/requirements/requirements"
4
5
  require_relative "isodoc/iso/html_convert"
5
6
  require_relative "isodoc/iso/word_convert"
6
7
  require_relative "isodoc/iso/pdf_convert"
@@ -10,7 +11,7 @@ require_relative "isodoc/iso/presentation_xml_convert"
10
11
  require_relative "html2doc/lists"
11
12
  require "asciidoctor/extensions"
12
13
 
13
- if defined? Metanorma
14
+ if defined? Metanorma::Registry
14
15
  require_relative "metanorma/iso"
15
16
  Metanorma::Registry.instance.register(Metanorma::Iso::Processor)
16
17
  end
@@ -31,10 +31,10 @@ Gem::Specification.new do |spec|
31
31
 
32
32
  spec.add_dependency "metanorma-standoc", "~> 2.2.0"
33
33
  spec.add_dependency "mnconvert", "~> 1.14"
34
+ spec.add_dependency "pubid-iso"
34
35
  spec.add_dependency "ruby-jing"
35
36
  spec.add_dependency "tokenizer", "~> 0.3.0"
36
37
  spec.add_dependency "twitter_cldr"
37
- spec.add_dependency "pubid-iso"
38
38
 
39
39
  spec.add_development_dependency "debug"
40
40
  spec.add_development_dependency "equivalent-xml", "~> 0.6"
@@ -0,0 +1,10 @@
1
+ = X
2
+ A
3
+ :mn-document-class: iso
4
+ :title-main-en: Medical devices — Quality management systems — Requirements for regulatory purposes
5
+ :title-main-fr: Dispositifs médicaux — Systèmes de management de la qualité — Exigences à des fins réglementaires
6
+
7
+ == Clause 1
8
+
9
+ X
10
+