metanorma-iso 1.10.4 → 2.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (79) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/rake.yml +3 -33
  3. data/.github/workflows/ubuntu.yml +1 -1
  4. data/.gitignore +26 -0
  5. data/Makefile +1 -1
  6. data/lib/asciidoctor/iso/base.rb +2 -69
  7. data/lib/asciidoctor/iso/cleanup.rb +2 -175
  8. data/lib/asciidoctor/iso/converter.rb +2 -17
  9. data/lib/asciidoctor/iso/deprecated.rb +5 -0
  10. data/lib/asciidoctor/iso/front.rb +2 -156
  11. data/lib/asciidoctor/iso/front_id.rb +2 -221
  12. data/lib/asciidoctor/iso/section.rb +2 -48
  13. data/lib/asciidoctor/iso/validate.rb +2 -171
  14. data/lib/asciidoctor/iso/validate_image.rb +2 -96
  15. data/lib/asciidoctor/iso/validate_requirements.rb +2 -110
  16. data/lib/asciidoctor/iso/validate_section.rb +2 -246
  17. data/lib/asciidoctor/iso/validate_style.rb +2 -169
  18. data/lib/asciidoctor/iso/validate_title.rb +2 -104
  19. data/lib/isodoc/iso/base_convert.rb +14 -31
  20. data/lib/isodoc/iso/html/style-human.css +37 -22
  21. data/lib/isodoc/iso/html/style-human.scss +17 -10
  22. data/lib/isodoc/iso/html/style-iso.css +34 -20
  23. data/lib/isodoc/iso/html/style-iso.scss +13 -7
  24. data/lib/isodoc/iso/html/wordstyle.css +10 -8
  25. data/lib/isodoc/iso/html/wordstyle.scss +10 -8
  26. data/lib/isodoc/iso/html_convert.rb +6 -4
  27. data/lib/isodoc/iso/index.rb +53 -45
  28. data/lib/isodoc/iso/iso.amendment.xsl +1328 -1225
  29. data/lib/isodoc/iso/iso.international-standard.xsl +1328 -1225
  30. data/lib/isodoc/iso/metadata.rb +27 -22
  31. data/lib/isodoc/iso/presentation_xml_convert.rb +41 -16
  32. data/lib/isodoc/iso/sts_convert.rb +2 -4
  33. data/lib/isodoc/iso/word_convert.rb +2 -0
  34. data/lib/metanorma/iso/base.rb +70 -0
  35. data/lib/{asciidoctor → metanorma}/iso/basicdoc.rng +0 -0
  36. data/lib/{asciidoctor → metanorma}/iso/biblio.rng +0 -0
  37. data/lib/{asciidoctor → metanorma}/iso/boilerplate-fr.xml +0 -0
  38. data/lib/{asciidoctor → metanorma}/iso/boilerplate.xml +0 -0
  39. data/lib/metanorma/iso/cleanup.rb +176 -0
  40. data/lib/metanorma/iso/converter.rb +18 -0
  41. data/lib/metanorma/iso/front.rb +170 -0
  42. data/lib/metanorma/iso/front_id.rb +225 -0
  43. data/lib/{asciidoctor → metanorma}/iso/isodoc.rng +35 -2
  44. data/lib/{asciidoctor → metanorma}/iso/isostandard-amd.rng +0 -0
  45. data/lib/{asciidoctor → metanorma}/iso/isostandard.rnc +0 -0
  46. data/lib/{asciidoctor → metanorma}/iso/isostandard.rng +0 -0
  47. data/lib/{asciidoctor → metanorma}/iso/reqt.rng +0 -0
  48. data/lib/metanorma/iso/section.rb +49 -0
  49. data/lib/metanorma/iso/validate.rb +172 -0
  50. data/lib/metanorma/iso/validate_image.rb +97 -0
  51. data/lib/metanorma/iso/validate_requirements.rb +111 -0
  52. data/lib/metanorma/iso/validate_section.rb +247 -0
  53. data/lib/metanorma/iso/validate_style.rb +170 -0
  54. data/lib/metanorma/iso/validate_title.rb +105 -0
  55. data/lib/metanorma/iso/version.rb +1 -1
  56. data/lib/metanorma-iso.rb +1 -1
  57. data/metanorma-iso.gemspec +2 -2
  58. data/spec/isodoc/amd_spec.rb +261 -250
  59. data/spec/isodoc/inline_spec.rb +238 -212
  60. data/spec/isodoc/iso_spec.rb +3 -1
  61. data/spec/isodoc/ref_spec.rb +4 -2
  62. data/spec/isodoc/section_spec.rb +1 -1
  63. data/spec/isodoc/terms_spec.rb +4 -4
  64. data/spec/{asciidoctor → metanorma}/amd_spec.rb +1 -1
  65. data/spec/metanorma/base_spec.rb +1185 -0
  66. data/spec/{asciidoctor → metanorma}/blank_spec.rb +1 -1
  67. data/spec/{asciidoctor → metanorma}/blocks_spec.rb +1 -1
  68. data/spec/{asciidoctor → metanorma}/cleanup_spec.rb +1 -1
  69. data/spec/{asciidoctor → metanorma}/inline_spec.rb +1 -1
  70. data/spec/{asciidoctor → metanorma}/lists_spec.rb +1 -1
  71. data/spec/metanorma/processor_spec.rb +1 -1
  72. data/spec/{asciidoctor → metanorma}/refs_spec.rb +1 -1
  73. data/spec/{asciidoctor → metanorma}/section_spec.rb +1 -1
  74. data/spec/{asciidoctor → metanorma}/table_spec.rb +1 -1
  75. data/spec/{asciidoctor → metanorma}/validate_spec.rb +1 -1
  76. data/spec/spec_helper.rb +1 -1
  77. data/spec/vcr_cassettes/docrels.yml +34 -424
  78. metadata +39 -26
  79. data/spec/asciidoctor/base_spec.rb +0 -1333
@@ -21,9 +21,8 @@ module IsoDoc
21
21
  stage = "DTS" if stage == "DIS"
22
22
  stage = "FDTS" if stage == "FDIS"
23
23
  end
24
- if %w(PWI NWIP WD CD).include?(stage) && iter
24
+ %w(PWI NWIP WD CD).include?(stage) && iter and
25
25
  stage += iter
26
- end
27
26
  stage = "Pre#{stage}" if /^0\./.match?(draft)
28
27
  stage
29
28
  end
@@ -31,20 +30,25 @@ module IsoDoc
31
30
  def docstatus(isoxml, _out)
32
31
  docstatus = isoxml.at(ns("//bibdata/status/stage"))
33
32
  set(:unpublished, false)
34
- if docstatus
35
- set(:stage, docstatus.text)
36
- set(:stage_int, docstatus.text.to_i)
37
- set(:unpublished, unpublished(docstatus.text))
38
- set(:statusabbr, status_abbrev(docstatus["abbreviation"] || "??",
39
- isoxml&.at(ns("//bibdata/status/substage"))&.text,
40
- isoxml&.at(ns("//bibdata/status/iteration"))&.text,
41
- isoxml&.at(ns("//bibdata/version/draft"))&.text,
42
- isoxml&.at(ns("//bibdata/ext/doctype"))&.text))
43
- unpublished(docstatus.text) and
44
- set(:stageabbr, docstatus["abbreviation"])
45
- end
46
33
  revdate = isoxml.at(ns("//bibdata/version/revision-date"))
47
34
  set(:revdate, revdate&.text)
35
+ if docstatus
36
+ docstatus1(isoxml, docstatus)
37
+ end
38
+ end
39
+
40
+ def docstatus1(isoxml, docstatus)
41
+ set(:stage, docstatus.text)
42
+ set(:stage_int, docstatus.text.to_i)
43
+ set(:unpublished, unpublished(docstatus.text))
44
+ set(:statusabbr,
45
+ status_abbrev(docstatus["abbreviation"] || "??",
46
+ isoxml&.at(ns("//bibdata/status/substage"))&.text,
47
+ isoxml&.at(ns("//bibdata/status/iteration"))&.text,
48
+ isoxml&.at(ns("//bibdata/version/draft"))&.text,
49
+ isoxml&.at(ns("//bibdata/ext/doctype"))&.text))
50
+ unpublished(docstatus.text) and
51
+ set(:stageabbr, docstatus["abbreviation"])
48
52
  end
49
53
 
50
54
  def unpublished(status)
@@ -73,8 +77,7 @@ module IsoDoc
73
77
 
74
78
  def amd_label(lang)
75
79
  case lang
76
- when "en" then "AMENDMENT"
77
- when "fr" then "AMENDMENT"
80
+ when "en", "fr" then "AMENDMENT"
78
81
  end
79
82
  end
80
83
 
@@ -183,10 +186,10 @@ module IsoDoc
183
186
  end
184
187
 
185
188
  def tc(xml)
186
- tc_num = xml.at(ns("//bibdata/ext/editorialgroup/technical-committee/@number"))
187
- tc_type = xml.at(ns("//bibdata/ext/editorialgroup/technical-committee/@type"))
188
- &.text || "TC"
189
- if tc_num
189
+ tc_type = xml.at(ns("//bibdata/ext/editorialgroup/technical-committee/"\
190
+ "@type"))&.text || "TC"
191
+ if tc_num = xml.at(ns("//bibdata/ext/editorialgroup/"\
192
+ "technical-committee/@number"))
190
193
  tcid = "#{tc_type} #{tc_num.text}"
191
194
  set(:tc, tcid)
192
195
  set(:editorialgroup, get[:editorialgroup] << tcid)
@@ -195,7 +198,8 @@ module IsoDoc
195
198
 
196
199
  def sc(xml)
197
200
  sc_num = xml.at(ns("//bibdata/ext/editorialgroup/subcommittee/@number"))
198
- sc_type = xml.at(ns("//bibdata/ext/editorialgroup/subcommittee/@type"))&.text || "SC"
201
+ sc_type = xml.at(ns("//bibdata/ext/editorialgroup/subcommittee/"\
202
+ "@type"))&.text || "SC"
199
203
  if sc_num
200
204
  scid = "#{sc_type} #{sc_num.text}"
201
205
  set(:sc, scid)
@@ -205,7 +209,8 @@ module IsoDoc
205
209
 
206
210
  def wg(xml)
207
211
  wg_num = xml.at(ns("//bibdata/ext/editorialgroup/workgroup/@number"))
208
- wg_type = xml.at(ns("//bibdata/ext/editorialgroup/workgroup/@type"))&.text || "WG"
212
+ wg_type = xml.at(ns("//bibdata/ext/editorialgroup/workgroup/"\
213
+ "@type"))&.text || "WG"
209
214
  if wg_num
210
215
  wgid = "#{wg_type} #{wg_num.text}"
211
216
  set(:wg, wgid)
@@ -113,28 +113,29 @@ module IsoDoc
113
113
  end
114
114
 
115
115
  def concept(docxml)
116
- docxml.xpath(ns("//term//concept")).each_with_object({}) do |f, m|
117
- concept_term(f, m)
118
- end
116
+ concept_term(docxml)
119
117
  docxml.xpath(ns("//concept")).each do |node|
120
- concept_render(node, ital: node["ital"] || "false",
121
- ref: node["ref"] || "false",
122
- linkref: node["linkref"] || "true",
123
- linkmention: node["linkmention"] || "false")
118
+ concept_render(node, ital: "false", ref: "false",
119
+ linkref: "true", linkmention: "false")
120
+ end
121
+ end
122
+
123
+ def concept_term(docxml)
124
+ docxml.xpath(ns("//term")).each do |f|
125
+ m = {}
126
+ f.xpath(ns(".//concept")).each do |c|
127
+ concept_term1(c, m)
128
+ end
124
129
  end
125
130
  end
126
131
 
127
- def concept_term(node, seen)
132
+ def concept_term1(node, seen)
128
133
  term = node&.at(ns("./refterm"))&.to_xml
129
134
  if term && seen[term]
130
- concept_render(node, ital: node["ital"] || "false",
131
- ref: node["ref"] || "false",
132
- linkref: node["linkref"] || "true",
133
- linkmention: node["linkmention"] || "false")
134
- else concept_render(node, ital: node["ital"] || "true",
135
- ref: node["ref"] || "true",
136
- linkref: node["linkref"] || "true",
137
- linkmention: node["linkmention"] || "false")
135
+ concept_render(node, ital: "false", ref: "false",
136
+ linkref: "true", linkmention: "false")
137
+ else concept_render(node, ital: "true", ref: "true",
138
+ linkref: "true", linkmention: "false")
138
139
  end
139
140
  seen[term] = true if term
140
141
  seen
@@ -184,6 +185,30 @@ module IsoDoc
184
185
  "&#x3c;#{d.remove.children.to_xml}&#x3e; "
185
186
  end
186
187
 
188
+ def insertall_after_here(node, insert, name)
189
+ node.children.each do |n|
190
+ next unless n.name == name
191
+
192
+ insert.next = n.remove
193
+ insert = n
194
+ end
195
+ insert
196
+ end
197
+
198
+ def termexamples_before_termnotes(node)
199
+ return unless insert = node.at(ns("./definition"))
200
+
201
+ insert = insertall_after_here(node, insert, "termexample")
202
+ insertall_after_here(node, insert, "termnote")
203
+ end
204
+
205
+ def terms(docxml)
206
+ docxml.xpath(ns("//term[termnote][termexample]")).each do |node|
207
+ termexamples_before_termnotes(node)
208
+ end
209
+ super
210
+ end
211
+
187
212
  include Init
188
213
  end
189
214
  end
@@ -20,10 +20,8 @@ module IsoDoc
20
20
  end
21
21
  FileUtils.rm_rf dir
22
22
  MnConvert.convert(in_fname,
23
- {
24
- input_format: MnConvert::InputFormat::MN,
25
- output_file: out_fname || "#{filename}.#{@suffix}",
26
- })
23
+ { input_format: MnConvert::InputFormat::MN,
24
+ output_file: out_fname || "#{filename}.#{@suffix}" })
27
25
  end
28
26
  end
29
27
  end
@@ -154,11 +154,13 @@ module IsoDoc
154
154
  end
155
155
 
156
156
  def annex_name(_annex, name, div)
157
+ preceding_floating_titles(name, div)
157
158
  return if name.nil?
158
159
 
159
160
  name&.at(ns("./strong"))&.remove # supplied by CSS list numbering
160
161
  div.h1 **{ class: "Annex" } do |t|
161
162
  name.children.each { |c2| parse(c2, t) }
163
+ clause_parse_subtitle(name, t)
162
164
  end
163
165
  end
164
166
 
@@ -0,0 +1,70 @@
1
+ require "date"
2
+ require "nokogiri"
3
+ require "json"
4
+ require "pathname"
5
+ require "open-uri"
6
+ require "isodoc"
7
+ require "fileutils"
8
+
9
+ module Metanorma
10
+ module ISO
11
+ class Converter < Standoc::Converter
12
+ XML_ROOT_TAG = "iso-standard".freeze
13
+ XML_NAMESPACE = "https://www.metanorma.org/ns/iso".freeze
14
+
15
+ def html_converter(node)
16
+ IsoDoc::Iso::HtmlConvert.new(html_extract_attributes(node))
17
+ end
18
+
19
+ def html_converter_alt(node)
20
+ IsoDoc::Iso::HtmlConvert.new(html_extract_attributes(node)
21
+ .merge(alt: true))
22
+ end
23
+
24
+ def doc_converter(node)
25
+ IsoDoc::Iso::WordConvert.new(doc_extract_attributes(node))
26
+ end
27
+
28
+ def pdf_converter(node)
29
+ return nil if node.attr("no-pdf")
30
+
31
+ IsoDoc::Iso::PdfConvert.new(pdf_extract_attributes(node))
32
+ end
33
+
34
+ def sts_converter(node)
35
+ return nil if node.attr("no-pdf")
36
+
37
+ IsoDoc::Iso::StsConvert.new(html_extract_attributes(node))
38
+ end
39
+
40
+ def presentation_xml_converter(node)
41
+ IsoDoc::Iso::PresentationXMLConvert.new(html_extract_attributes(node))
42
+ end
43
+
44
+ def init(node)
45
+ super
46
+ @amd = %w(amendment technical-corrigendum).include? doctype(node)
47
+ @vocab = node.attr("docsubtype") == "vocabulary"
48
+ end
49
+
50
+ def ol_attrs(node)
51
+ attr_code(keep_attrs(node)
52
+ .merge(id: ::Metanorma::Utils::anchor_or_uuid(node)))
53
+ end
54
+
55
+ def outputs(node, ret)
56
+ File.open("#{@filename}.xml", "w:UTF-8") { |f| f.write(ret) }
57
+ presentation_xml_converter(node).convert("#{@filename}.xml")
58
+ html_converter_alt(node).convert("#{@filename}.presentation.xml",
59
+ nil, false, "#{@filename}_alt.html")
60
+ html_converter(node).convert("#{@filename}.presentation.xml",
61
+ nil, false, "#{@filename}.html")
62
+ doc_converter(node).convert("#{@filename}.presentation.xml",
63
+ nil, false, "#{@filename}.doc")
64
+ pdf_converter(node)&.convert("#{@filename}.presentation.xml",
65
+ nil, false, "#{@filename}.pdf")
66
+ # sts_converter(node)&.convert(@filename + ".xml")
67
+ end
68
+ end
69
+ end
70
+ end
File without changes
File without changes
File without changes
@@ -0,0 +1,176 @@
1
+ require "date"
2
+ require "nokogiri"
3
+ require "htmlentities"
4
+ require "json"
5
+ require "pathname"
6
+
7
+ module Metanorma
8
+ module ISO
9
+ class Converter < Standoc::Converter
10
+ PRE_NORMREF_FOOTNOTES = "//preface//fn | "\
11
+ "//clause[@type = 'scope']//fn".freeze
12
+
13
+ NORMREF_FOOTNOTES =
14
+ "//references[@normative = 'true']//fn".freeze
15
+
16
+ POST_NORMREF_FOOTNOTES =
17
+ "//sections//clause[not(@type = 'scope')]//fn | "\
18
+ "//annex//fn | "\
19
+ "//references[@normative = 'false']//fn".freeze
20
+
21
+ def other_footnote_renumber(xmldoc)
22
+ seen = {}
23
+ i = 0
24
+ [PRE_NORMREF_FOOTNOTES, NORMREF_FOOTNOTES,
25
+ POST_NORMREF_FOOTNOTES].each do |xpath|
26
+ xmldoc.xpath(xpath).each do |fn|
27
+ i, seen = other_footnote_renumber1(fn, i, seen)
28
+ end
29
+ end
30
+ end
31
+
32
+ def id_prefix(prefix, id)
33
+ # we're just inheriting the prefixes from parent doc
34
+ return id.text if @amd
35
+
36
+ prefix.join("/") + (id.text.match?(%{^/}) ? "" : " ") + id.text
37
+ end
38
+
39
+ def get_id_prefix(xmldoc)
40
+ prefix = []
41
+ xmldoc.xpath("//bibdata/contributor[role/@type = 'publisher']"\
42
+ "/organization").each do |x|
43
+ x1 = x.at("abbreviation")&.text || x.at("name")&.text
44
+ (x1 == "ISO" and prefix.unshift("ISO")) or prefix << x1
45
+ end
46
+ prefix
47
+ end
48
+
49
+ # ISO as a prefix goes first
50
+ def docidentifier_cleanup(xmldoc)
51
+ prefix = get_id_prefix(xmldoc)
52
+ id = xmldoc.at("//bibdata/docidentifier[@type = 'ISO']") or return
53
+ id.content = id_prefix(prefix, id)
54
+ id = xmldoc.at("//bibdata/ext/structuredidentifier/project-number") and
55
+ id.content = id_prefix(prefix, id)
56
+ id = xmldoc.at("//bibdata/docidentifier[@type = 'iso-with-lang']") and
57
+ id.content = id_prefix(prefix, id)
58
+ id = xmldoc.at("//bibdata/docidentifier[@type = 'iso-reference']") and
59
+ id.content = id_prefix(prefix, id)
60
+ end
61
+
62
+ def format_ref(ref, type)
63
+ ref = ref.sub(/ \(All Parts\)/i, "")
64
+ super
65
+ end
66
+
67
+ TERM_CLAUSE =
68
+ "//sections//terms | "\
69
+ "//sections//clause[descendant::terms][not(descendant::definitions)]"
70
+ .freeze
71
+
72
+ PUBLISHER = "./contributor[role/@type = 'publisher']/organization".freeze
73
+
74
+ OTHERIDS = "@type = 'DOI' or @type = 'metanorma' or @type = 'ISSN' or "\
75
+ "@type = 'ISBN'".freeze
76
+
77
+ def pub_class(bib)
78
+ return 1 if bib.at("#{PUBLISHER}[abbreviation = 'ISO']")
79
+ return 1 if bib.at("#{PUBLISHER}[name = 'International Organization "\
80
+ "for Standardization']")
81
+ return 2 if bib.at("#{PUBLISHER}[abbreviation = 'IEC']")
82
+ return 2 if bib.at("#{PUBLISHER}[name = 'International "\
83
+ "Electrotechnical Commission']")
84
+ return 3 if bib.at("./docidentifier[@type][not(#{OTHERIDS})]")
85
+
86
+ 4
87
+ end
88
+
89
+ def sort_biblio(bib)
90
+ bib.sort do |a, b|
91
+ sort_biblio_key(a) <=> sort_biblio_key(b)
92
+ end
93
+ end
94
+
95
+ # TODO sort by authors
96
+ # sort by: doc class (ISO, IEC, other standard (not DOI &c), other
97
+ # then standard class (docid class other than DOI &c)
98
+ # then docnumber if present, numeric sort
99
+ # else alphanumeric metanorma id (abbreviation)
100
+ # then doc part number if present, numeric sort
101
+ # then doc id (not DOI &c)
102
+ # then title
103
+ def sort_biblio_key(bib)
104
+ pubclass = pub_class(bib)
105
+ num = bib&.at("./docnumber")&.text
106
+ id = bib&.at("./docidentifier[not(#{OTHERIDS})]")
107
+ metaid = bib&.at("./docidentifier[@type = 'metanorma']")&.text
108
+ abbrid = metaid unless /^\[\d+\]$/.match?(metaid)
109
+ /\d-(?<partid>\d+)/ =~ id&.text
110
+ type = id["type"] if id
111
+ title = bib&.at("./title[@type = 'main']")&.text ||
112
+ bib&.at("./title")&.text || bib&.at("./formattedref")&.text
113
+ "#{pubclass} :: #{type} :: "\
114
+ "#{num.nil? ? abbrid : sprintf('%09d', num.to_i)} :: "\
115
+ "#{sprintf('%09d', partid.to_i)} :: #{id&.text} :: #{title}"
116
+ end
117
+
118
+ def sections_cleanup(xml)
119
+ super
120
+ return unless @amd
121
+
122
+ xml.xpath("//*[@inline-header]").each do |h|
123
+ h.delete("inline-header")
124
+ end
125
+ end
126
+
127
+ def boilerplate_file(_xmldoc)
128
+ file = @lang == "fr" ? "boilerplate-fr.xml" : "boilerplate.xml"
129
+ File.join(@libdir, file)
130
+ end
131
+
132
+ def footnote_cleanup(xmldoc)
133
+ unpub_footnotes(xmldoc)
134
+ super
135
+ end
136
+
137
+ def unpub_footnotes(xmldoc)
138
+ xmldoc.xpath("//bibitem/note[@type = 'Unpublished-Status']").each do |n|
139
+ id = n.parent["id"]
140
+ e = xmldoc.at("//eref[@bibitemid = '#{id}']") or next
141
+ fn = n.children.to_xml
142
+ n&.elements&.first&.name == "p" or fn = "<p>#{fn}</p>"
143
+ e.next = "<fn>#{fn}</fn>"
144
+ end
145
+ end
146
+
147
+ def bibitem_cleanup(xmldoc)
148
+ super
149
+ unpublished_note(xmldoc)
150
+ end
151
+
152
+ def unpublished_note(xmldoc)
153
+ xmldoc.xpath("//bibitem[not(note[@type = 'Unpublished-Status'])]")
154
+ .each do |b|
155
+ next if pub_class(b) > 2
156
+ next unless (s = b.at("./status/stage")) && (s.text.to_i < 60)
157
+
158
+ id = b.at("docidentifier").text
159
+ b.at("./language | ./script | ./abstract | ./status")
160
+ .previous = %(<note type="Unpublished-Status">
161
+ <p>#{@i18n.under_preparation.sub(/%/, id)}</p></note>)
162
+ end
163
+ end
164
+
165
+ def termdef_boilerplate_insert(xmldoc, isodoc, once = false)
166
+ once = true
167
+ super
168
+ end
169
+
170
+ def term_defs_boilerplate_cont(src, term, isodoc)
171
+ @vocab and src.empty? and return
172
+ super
173
+ end
174
+ end
175
+ end
176
+ end
@@ -0,0 +1,18 @@
1
+ require "asciidoctor"
2
+ require "metanorma-standoc"
3
+ require "metanorma/iso/version"
4
+ require "metanorma/iso/base"
5
+ require "metanorma/iso/front"
6
+ require "metanorma/iso/section"
7
+ require "metanorma/iso/validate"
8
+ require "metanorma/iso/cleanup"
9
+
10
+ module Metanorma
11
+ module ISO
12
+ # A {Converter} implementation that generates ISO output, and a document
13
+ # schema encapsulation of the document for validation
14
+ class Converter < ::Metanorma::Standoc::Converter
15
+ register_for "iso"
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,170 @@
1
+ require "date"
2
+ require "nokogiri"
3
+ require "htmlentities"
4
+ require "json"
5
+ require "pathname"
6
+ require "open-uri"
7
+ require_relative "front_id"
8
+
9
+ module Metanorma
10
+ module ISO
11
+ class Converter < Standoc::Converter
12
+ def metadata_ext(node, xml)
13
+ super
14
+ structured_id(node, xml)
15
+ xml.stagename stage_name(get_stage(node), get_substage(node),
16
+ doctype(node), node.attr("iteration"))
17
+ @amd && a = node.attr("updates-document-type") and
18
+ xml.updates_document_type a
19
+ end
20
+
21
+ def metadata_subdoctype(node, xml)
22
+ super
23
+ a = node.attr("horizontal") and xml.horizontal a
24
+ end
25
+
26
+ def org_abbrev
27
+ { "International Organization for Standardization" => "ISO",
28
+ "International Electrotechnical Commission" => "IEC" }
29
+ end
30
+
31
+ def metadata_author(node, xml)
32
+ publishers = node.attr("publisher") || "ISO"
33
+ csv_split(publishers).each do |p|
34
+ xml.contributor do |c|
35
+ c.role **{ type: "author" }
36
+ c.organization do |a|
37
+ organization(a, p, false, node, !node.attr("publisher"))
38
+ end
39
+ end
40
+ end
41
+ end
42
+
43
+ def metadata_publisher(node, xml)
44
+ publishers = node.attr("publisher") || "ISO"
45
+ csv_split(publishers).each do |p|
46
+ xml.contributor do |c|
47
+ c.role **{ type: "publisher" }
48
+ c.organization do |a|
49
+ organization(a, p, true, node, !node.attr("publisher"))
50
+ end
51
+ end
52
+ end
53
+ end
54
+
55
+ def metadata_copyright(node, xml)
56
+ publishers = node.attr("copyright-holder") || node.attr("publisher") ||
57
+ "ISO"
58
+ csv_split(publishers).each do |p|
59
+ xml.copyright do |c|
60
+ c.from (node.attr("copyright-year") || Date.today.year)
61
+ c.owner do |owner|
62
+ owner.organization do |o|
63
+ organization(
64
+ o, p, true, node,
65
+ !(node.attr("copyright-holder") || node.attr("publisher"))
66
+ )
67
+ end
68
+ end
69
+ end
70
+ end
71
+ end
72
+
73
+ def metadata_status(node, xml)
74
+ stage = get_stage(node)
75
+ substage = get_substage(node)
76
+ xml.status do |s|
77
+ s.stage stage, **attr_code(abbreviation: cover_stage_abbr(node))
78
+ s.substage substage
79
+ node.attr("iteration") && (s.iteration node.attr("iteration"))
80
+ end
81
+ end
82
+
83
+ def metadata_committee(node, xml)
84
+ xml.editorialgroup do |a|
85
+ committee_component("technical-committee", node, a)
86
+ committee_component("subcommittee", node, a)
87
+ committee_component("workgroup", node, a)
88
+ node.attr("secretariat") && a.secretariat(node.attr("secretariat"))
89
+ end
90
+ end
91
+
92
+ def title_intro(node, xml, lang, at)
93
+ return unless node.attr("title-intro-#{lang}")
94
+
95
+ xml.title(**attr_code(at.merge(type: "title-intro"))) do |t1|
96
+ t1 << Metanorma::Utils::asciidoc_sub(node.attr("title-intro-#{lang}"))
97
+ end
98
+ end
99
+
100
+ def title_main(node, xml, lang, at)
101
+ xml.title **attr_code(at.merge(type: "title-main")) do |t1|
102
+ t1 << Metanorma::Utils::asciidoc_sub(node.attr("title-main-#{lang}"))
103
+ end
104
+ end
105
+
106
+ def title_part(node, xml, lang, at)
107
+ return unless node.attr("title-part-#{lang}")
108
+
109
+ xml.title(**attr_code(at.merge(type: "title-part"))) do |t1|
110
+ t1 << Metanorma::Utils::asciidoc_sub(node.attr("title-part-#{lang}"))
111
+ end
112
+ end
113
+
114
+ def title_amd(node, xml, lang, at)
115
+ return unless node.attr("title-amendment-#{lang}")
116
+
117
+ xml.title(**attr_code(at.merge(type: "title-amd"))) do |t1|
118
+ t1 << Metanorma::Utils::asciidoc_sub(
119
+ node.attr("title-amendment-#{lang}"),
120
+ )
121
+ end
122
+ end
123
+
124
+ def title_full(node, xml, lang, at)
125
+ title = node.attr("title-main-#{lang}")
126
+ intro = node.attr("title-intro-#{lang}")
127
+ part = node.attr("title-part-#{lang}")
128
+ amd = node.attr("title-amendment-#{lang}")
129
+ title = "#{intro} -- #{title}" if intro
130
+ title = "#{title} -- #{part}" if part
131
+ title = "#{title} -- #{amd}" if amd && @amd
132
+ xml.title **attr_code(at.merge(type: "main")) do |t1|
133
+ t1 << Metanorma::Utils::asciidoc_sub(title)
134
+ end
135
+ end
136
+
137
+ def title(node, xml)
138
+ ["en", "fr"].each do |lang|
139
+ at = { language: lang, format: "text/plain" }
140
+ title_full(node, xml, lang, at)
141
+ title_intro(node, xml, lang, at)
142
+ title_main(node, xml, lang, at)
143
+ title_part(node, xml, lang, at)
144
+ title_amd(node, xml, lang, at) if @amd
145
+ end
146
+ end
147
+
148
+ def relaton_relations
149
+ super + %w(obsoletes successor-of manifestation-of related annotation-of)
150
+ end
151
+
152
+ def relaton_relation_descriptions
153
+ super.merge(
154
+ "amends" => "updates", "revises" => "updates",
155
+ "replaces" => "obsoletes",
156
+ "supersedes" => "obsoletes",
157
+ "corrects" => "updates",
158
+ "informatively-cited-in" => "isCitedIn",
159
+ "informatively-cites" => "cites",
160
+ "normatively-cited in" => "isCitedIn",
161
+ "normatively-cites" => "cites",
162
+ "identical-adopted-from" => "adoptedFrom",
163
+ "modified-adopted-from" => "adoptedFrom",
164
+ "related-directive" => "related",
165
+ "related-mandate" => "related",
166
+ )
167
+ end
168
+ end
169
+ end
170
+ end