metanorma-iec 1.0.2 → 1.0.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/macos.yml +10 -10
  3. data/.github/workflows/ubuntu.yml +25 -11
  4. data/.github/workflows/windows.yml +11 -12
  5. data/README.adoc +3 -2
  6. data/lib/asciidoctor/iec/biblio.rng +131 -46
  7. data/lib/asciidoctor/iec/converter.rb +19 -130
  8. data/lib/asciidoctor/iec/front.rb +220 -0
  9. data/lib/asciidoctor/iec/isodoc.rng +32 -4
  10. data/lib/asciidoctor/iec/isostandard.rng +10 -0
  11. data/lib/isodoc/iec/base_convert.rb +118 -0
  12. data/lib/isodoc/iec/html/htmlstyle.scss +11 -8
  13. data/lib/isodoc/iec/html/scripts.html +23 -21
  14. data/lib/isodoc/iec/html_convert.rb +8 -0
  15. data/lib/isodoc/iec/i18n-en.yaml +2 -0
  16. data/lib/isodoc/iec/i18n-fr.yaml +2 -0
  17. data/lib/isodoc/iec/iec.international-standard.xsl +3969 -0
  18. data/lib/isodoc/iec/metadata.rb +3 -52
  19. data/lib/isodoc/iec/pdf_convert.rb +31 -0
  20. data/lib/metanorma-iec.rb +1 -0
  21. data/lib/metanorma/iec/processor.rb +12 -1
  22. data/lib/metanorma/iec/version.rb +1 -1
  23. data/spec/asciidoctor-iec/base_spec.rb +17 -27
  24. data/spec/asciidoctor-iec/blocks_spec.rb +15 -7
  25. data/spec/asciidoctor-iec/cleanup_spec.rb +13 -7
  26. data/spec/asciidoctor-iec/iev_spec.rb +161 -0
  27. data/spec/asciidoctor-iec/inline_spec.rb +2 -1
  28. data/spec/asciidoctor-iec/section_spec.rb +8 -8
  29. data/spec/assets/iso.xml +65 -2
  30. data/spec/examples/rice.html +5 -5
  31. data/spec/examples/rice_img/rice_image1.png +0 -0
  32. data/spec/examples/rice_img/rice_image2.png +0 -0
  33. data/spec/examples/rice_img/rice_image3_1.png +0 -0
  34. data/spec/examples/rice_img/rice_image3_2.png +0 -0
  35. data/spec/examples/rice_img/rice_image3_3.png +0 -0
  36. data/spec/isodoc/i18n_spec.rb +15 -22
  37. data/spec/isodoc/iev_spec.rb +356 -0
  38. data/spec/isodoc/inline_spec.rb +2 -2
  39. data/spec/isodoc/iso_spec.rb +2 -19
  40. data/spec/isodoc/metadata_spec.rb +12 -7
  41. data/spec/isodoc/postproc_spec.rb +9 -3
  42. data/spec/isodoc/section_spec.rb +11 -13
  43. data/spec/isodoc/terms_spec.rb +2 -2
  44. data/spec/metanorma/processor_spec.rb +3 -3
  45. data/spec/spec_helper.rb +3 -2
  46. metadata +12 -2
@@ -1,5 +1,6 @@
1
1
  require "asciidoctor"
2
2
  require "metanorma-iso"
3
+ require_relative "./front.rb"
3
4
 
4
5
  module Asciidoctor
5
6
  module Iec
@@ -9,51 +10,9 @@ module Asciidoctor
9
10
 
10
11
  register_for "iec"
11
12
 
12
- def metadata_author(node, xml)
13
- publishers = node.attr("publisher") || "IEC"
14
- publishers.split(/,[ ]?/).each do |p|
15
- xml.contributor do |c|
16
- c.role **{ type: "author" }
17
- c.organization { |a| organization(a, p) }
18
- end
19
- end
20
- end
21
-
22
- def metadata_publisher(node, xml)
23
- publishers = node.attr("publisher") || "IEC"
24
- publishers.split(/,[ ]?/).each do |p|
25
- xml.contributor do |c|
26
- c.role **{ type: "publisher" }
27
- c.organization { |a| organization(a, p) }
28
- end
29
- end
30
- end
31
-
32
- def metadata_copyright(node, xml)
33
- publishers = node.attr("publisher") || "IEC"
34
- publishers.split(/,[ ]?/).each do |p|
35
- xml.copyright do |c|
36
- c.from (node.attr("copyright-year") || Date.today.year)
37
- c.owner do |owner|
38
- owner.organization { |o| organization(o, p) }
39
- end
40
- end
41
- end
42
- end
43
-
44
- def iso_id(node, xml)
45
- return unless node.attr("docnumber")
46
- part, subpart = node&.attr("partnumber")&.split(/-/)
47
- dn = add_id_parts(node.attr("docnumber"), part, subpart)
48
- dn = id_stage_prefix(dn, node)
49
- dn = id_edition_suffix(dn, node)
50
- xml.docidentifier dn, **attr_code(type: "iso")
51
- end
52
-
53
- def id_edition_suffix(dn, node)
54
- ed = node.attr("edition") || 1
55
- dn += " ED #{ed}"
56
- dn
13
+ def init(node)
14
+ super
15
+ @is_iev = node.attr("docnumber") == "60050"
57
16
  end
58
17
 
59
18
  def boilerplate_file(x_orig)
@@ -79,91 +38,6 @@ module Asciidoctor
79
38
  File.join(File.dirname(__FILE__), "iec.rng"))
80
39
  end
81
40
 
82
- STAGE_CODES = {
83
- "PNW" => "1000",
84
- "ANW" => "2000",
85
- "CAN" => "2098",
86
- "ACD" => "2099",
87
- "CD" => "3020",
88
- "BWG" => "3092",
89
- "A2CD" => "3099",
90
- "2CD" => "3520",
91
- "3CD" => "3520",
92
- "4CD" => "3520",
93
- "5CD" => "3520",
94
- "6CD" => "3520",
95
- "7CD" => "3520",
96
- "8CD" => "3520",
97
- "9CD" => "3520",
98
- "CDM" => "3591",
99
- "A3CD" => "3592",
100
- "A4CD" => "3592",
101
- "A5CD" => "3592",
102
- "A6CD" => "3592",
103
- "A7CD" => "3592",
104
- "A8CD" => "3592",
105
- "A9CD" => "3592",
106
- "ACDV" => "3599",
107
- "CCDV" => "4020",
108
- "CDVM" => "4091",
109
- "NCDV" => "4092",
110
- "NADIS" => "4093",
111
- "ADIS" => "4099",
112
- "ADTR" => "4099",
113
- "ADTS" => "4099",
114
- "RDISH" => "5000",
115
- "RFDIS" => "5000",
116
- "CDISH" => "5020",
117
- "CDPAS" => "5020",
118
- "CDTR" => "5020",
119
- "CDTS" => "5020",
120
- "CFDIS" => "5020",
121
- "DTRM" => "5092",
122
- "DTSM" => "5092",
123
- "NDTR" => "5092",
124
- "NDTS" => "5092",
125
- "NFDIS" => "5092",
126
- "APUB" => "5099",
127
- "BPUB" => "6000",
128
- "PPUB" => "6060",
129
- "RR" => "9092",
130
- "AMW" => "9220",
131
- "WPUB" => "9599",
132
- "DELPUB" => "9960",
133
- }.freeze
134
-
135
- DOC_STAGE = {
136
- "00": "PWI",
137
- "10": "NWIP",
138
- "20": "WD",
139
- "30": "CD",
140
- "40": "CDV",
141
- "50": "FDIS",
142
- }.freeze
143
-
144
- def get_stage(node)
145
- stage = node.attr("status") || node.attr("docstage") || "60"
146
- m = /([0-9])CD$/.match(stage) and
147
- node.set_attr("iteration", m[1])
148
- STAGE_CODES[stage] and stage = STAGE_CODES[stage][0..1]
149
- stage
150
- end
151
-
152
- def get_substage(node)
153
- st = node.attr("status") || node.attr("docstage")
154
- stage = get_stage(node)
155
- node.attr("docsubstage") ||
156
- ( stage == "60" ? "60" :
157
- STAGE_CODES[st] ? STAGE_CODES[st][2..3] :
158
- "00" )
159
- end
160
-
161
- def id_stage_abbr(stage, substage, node)
162
- abbr = DOC_STAGE[stage.to_sym] || ""
163
- abbr = node.attr("iteration") + abbr if node.attr("iteration")
164
- abbr
165
- end
166
-
167
41
  def load_yaml(lang, script)
168
42
  y = if @i18nyaml then YAML.load_file(@i18nyaml)
169
43
  elsif lang == "en"
@@ -187,6 +61,21 @@ module Asciidoctor
187
61
  node.nil? ? IsoDoc::Iec::WordConvert.new({}) :
188
62
  IsoDoc::Iec::WordConvert.new(doc_extract_attributes(node))
189
63
  end
64
+
65
+ def pdf_converter(node)
66
+ node.nil? ? IsoDoc::Iec::PdfConvert.new({}) :
67
+ IsoDoc::Iec::PdfConvert.new(doc_extract_attributes(node))
68
+ end
69
+
70
+ def norm_ref_preface(f)
71
+ return super unless @is_iev
72
+ f.at("./title").next =
73
+ "<p>#{@norm_empty_pref}</p>"
74
+ end
75
+
76
+ def term_defs_boilerplate(div, source, term, preface, isodoc)
77
+ return super unless @is_iev
78
+ end
190
79
  end
191
80
  end
192
81
  end
@@ -0,0 +1,220 @@
1
+ module Asciidoctor
2
+ module Iec
3
+ class Converter < ISO::Converter
4
+ def metadata_author(node, xml)
5
+ publishers = node.attr("publisher") || "IEC"
6
+ publishers.split(/,[ ]?/).each do |p|
7
+ xml.contributor do |c|
8
+ c.role **{ type: "author" }
9
+ c.organization { |a| organization(a, p) }
10
+ end
11
+ end
12
+ end
13
+
14
+ def metadata_publisher(node, xml)
15
+ publishers = node.attr("publisher") || "IEC"
16
+ publishers.split(/,[ ]?/).each do |p|
17
+ xml.contributor do |c|
18
+ c.role **{ type: "publisher" }
19
+ c.organization { |a| organization(a, p) }
20
+ end
21
+ end
22
+ end
23
+
24
+ def metadata_copyright(node, xml)
25
+ publishers = node.attr("publisher") || "IEC"
26
+ publishers.split(/,[ ]?/).each do |p|
27
+ xml.copyright do |c|
28
+ c.from (node.attr("copyright-year") || Date.today.year)
29
+ c.owner do |owner|
30
+ owner.organization { |o| organization(o, p) }
31
+ end
32
+ end
33
+ end
34
+ end
35
+
36
+ def iso_id(node, xml)
37
+ return unless node.attr("docnumber")
38
+ part, subpart = node&.attr("partnumber")&.split(/-/)
39
+ dn = add_id_parts(node.attr("docnumber"), part, subpart)
40
+ dn = id_stage_prefix(dn, node, false)
41
+ dn = id_edition_suffix(dn, node)
42
+ xml.docidentifier dn, **attr_code(type: "iso")
43
+ end
44
+
45
+ def id_edition_suffix(dn, node)
46
+ ed = node.attr("edition") || 1
47
+ dn += " ED #{ed}"
48
+ dn
49
+ end
50
+
51
+ STAGE_CODES = {
52
+ "PNW" => "1000",
53
+ "ANW" => "2000",
54
+ "CAN" => "2098",
55
+ "ACD" => "2099",
56
+ "CD" => "3020",
57
+ "BWG" => "3092",
58
+ "A2CD" => "3099",
59
+ "2CD" => "3520",
60
+ "3CD" => "3520",
61
+ "4CD" => "3520",
62
+ "5CD" => "3520",
63
+ "6CD" => "3520",
64
+ "7CD" => "3520",
65
+ "8CD" => "3520",
66
+ "9CD" => "3520",
67
+ "CDM" => "3591",
68
+ "A3CD" => "3592",
69
+ "A4CD" => "3592",
70
+ "A5CD" => "3592",
71
+ "A6CD" => "3592",
72
+ "A7CD" => "3592",
73
+ "A8CD" => "3592",
74
+ "A9CD" => "3592",
75
+ "ACDV" => "3599",
76
+ "CCDV" => "4020",
77
+ "CDVM" => "4091",
78
+ "NCDV" => "4092",
79
+ "NADIS" => "4093",
80
+ "ADIS" => "4099",
81
+ "ADTR" => "4099",
82
+ "ADTS" => "4099",
83
+ "RDISH" => "5000",
84
+ "RFDIS" => "5000",
85
+ "CDISH" => "5020",
86
+ "CDPAS" => "5020",
87
+ "CDTR" => "5020",
88
+ "CDTS" => "5020",
89
+ "CFDIS" => "5020",
90
+ "DTRM" => "5092",
91
+ "DTSM" => "5092",
92
+ "NDTR" => "5092",
93
+ "NDTS" => "5092",
94
+ "NFDIS" => "5092",
95
+ "APUB" => "5099",
96
+ "BPUB" => "6000",
97
+ "PPUB" => "6060",
98
+ "RR" => "9092",
99
+ "AMW" => "9220",
100
+ "WPUB" => "9599",
101
+ "DELPUB" => "9960",
102
+ }.freeze
103
+
104
+ DOC_STAGE = {
105
+ "00": "PWI",
106
+ "10": "NWIP",
107
+ "20": "WD",
108
+ "30": "CD",
109
+ "40": "CDV",
110
+ "50": "FDIS",
111
+ "60": "PPUB",
112
+ "90": "RR",
113
+ "92": "AMW",
114
+ "95": "WPUB",
115
+ "99": "DELPUB",
116
+ }.freeze
117
+
118
+ STAGE_ABBRS = {
119
+ "00" => {"00" => "PWI"},
120
+ "10" => {"00" => "PNW"},
121
+ "20" => {"00" => "ANW", "98" => "CAN", "99" => "ACD"},
122
+ "30" => {"00" => "CD", "20" => "CD", "92" => "BWG", "97" => "MERGED", "98" => "DREJ", "99" => "A2CD"},
123
+ "35" => {"00" => "CD", "20" => "CD", "91" => "CDM", "92" => "ACD", "99" => "ACDV"},
124
+ "40" => {"00" => "CCDV", "20" => "CCDV", "91" => "CDVM", "92" => "NCDV", "93" => "NADIS", "95" => "ADISSB", "99" => "ADIS"},
125
+ "50" => {"00" => "RFDIS", "20" => "CFDIS", "92" => "NFDIS", "95" => "APUBSB", "99" => "APUB"},
126
+ "60" => {"00" => "BPUB", "60" => "PPUB"},
127
+ "90" => {"00" => "RR", "92" => "RR"},
128
+ "92" => {"00" => "AMW", "20" => "AMW"},
129
+ "95" => {"00" => "WPUB", "99" => "WPUB"},
130
+ "99" => {"00" => "DELPUB", "60" => "DELPUB"},
131
+ }.freeze
132
+
133
+ STAGE_NAMES = {
134
+ "00": "Preliminary work item",
135
+ "10": "New work item proposal",
136
+ "20": "Working draft",
137
+ "30": "Committee draft",
138
+ "35": "Committee draft",
139
+ "40": "Committed draft for vote",
140
+ "50": "Final draft international standard",
141
+ "60": "International standard",
142
+ "90": "Review",
143
+ "92": "Review",
144
+ "95": "Withdrawal",
145
+ "99": "Deleted",
146
+ }.freeze
147
+
148
+ def status_abbrev1(stage, substage, iter, doctype, draft)
149
+ return "" unless stage
150
+ abbr = STAGE_ABBRS.dig(stage, substage) || "??"
151
+ if stage == "35" && substage == "92"
152
+ iter = (iter.to_i + 1) % "02"
153
+ end
154
+ case doctype
155
+ when "technical-report"
156
+ stage = "ADTR" if stage == "40" && substage == "99"
157
+ stage = "CDTR" if stage == "50" && substage == "20"
158
+ stage = "DTRM" if stage == "50" && substage == "92"
159
+ when "technical-specification"
160
+ stage = "ADTS" if stage == "40" && substage == "99"
161
+ stage = "CDTS" if stage == "50" && substage == "20"
162
+ stage = "DTSM" if stage == "50" && substage == "92"
163
+ when "interpretation-sheet"
164
+ stage = "RDISH" if stage == "50" && substage == "00"
165
+ stage = "CDISH" if stage == "50" && substage == "20"
166
+ when "publicly-available-specification"
167
+ stage = "CDPAS" if stage == "50" && substage == "20"
168
+ end
169
+ abbr = abbr.sub(/CD$/, "#{iter}CD") if iter
170
+ abbr
171
+ end
172
+
173
+ def stage_abbr(stage, substage)
174
+ return "PPUB" if stage == "60"
175
+ DOC_STAGE[stage.to_sym] || "??"
176
+ end
177
+
178
+ def stage_name(stage, substage, _doctype)
179
+ STAGE_NAMES[stage.to_sym]
180
+ end
181
+
182
+ def get_stage(node)
183
+ stage = node.attr("status") || node.attr("docstage") || "60"
184
+ m = /([0-9])CD$/.match(stage) and
185
+ node.set_attr("iteration", m[1])
186
+ STAGE_CODES[stage] and stage = STAGE_CODES[stage][0..1]
187
+ stage
188
+ end
189
+
190
+ def get_substage(node)
191
+ st = node.attr("status") || node.attr("docstage")
192
+ stage = get_stage(node)
193
+ node.attr("docsubstage") ||
194
+ ( stage == "60" ? "60" :
195
+ STAGE_CODES[st] ? STAGE_CODES[st][2..3] :
196
+ "00" )
197
+ end
198
+
199
+ def id_stage_abbr(stage, substage, node)
200
+ return "" if stage == "60"
201
+ abbr = DOC_STAGE[stage.to_sym] || ""
202
+ abbr = node.attr("iteration") + abbr if node.attr("iteration")
203
+ abbr
204
+ end
205
+
206
+ def metadata_status(node, xml)
207
+ stage = get_stage(node)
208
+ substage = get_substage(node)
209
+ xml.status do |s|
210
+ s.stage stage, **attr_code(abbreviation: stage_abbr(stage, substage))
211
+ s.substage substage,
212
+ **attr_code(abbreviation: status_abbrev1(stage, substage,
213
+ node.attr("iteration"),
214
+ doctype(node),node.attr("draft")))
215
+ node.attr("iteration") && (s.iteration node.attr("iteration"))
216
+ end
217
+ end
218
+ end
219
+ end
220
+ end
@@ -101,9 +101,7 @@
101
101
  <ref name="structuredidentifier"/>
102
102
  </zeroOrMore>
103
103
  </define>
104
- <define name="TitleType">
105
- <text/>
106
- </define>
104
+ <!-- TitleType = text -->
107
105
  <define name="sections">
108
106
  <element name="sections">
109
107
  <oneOrMore>
@@ -131,6 +129,9 @@
131
129
  </choice>
132
130
  </attribute>
133
131
  </optional>
132
+ <attribute name="normative">
133
+ <data type="boolean"/>
134
+ </attribute>
134
135
  <optional>
135
136
  <ref name="section-title"/>
136
137
  </optional>
@@ -307,6 +308,21 @@
307
308
  </define>
308
309
  </include>
309
310
  <!-- end overrides -->
311
+ <define name="TextElement" combine="choice">
312
+ <ref name="concept"/>
313
+ </define>
314
+ <define name="concept">
315
+ <element name="concept">
316
+ <optional>
317
+ <attribute name="term"/>
318
+ </optional>
319
+ <choice>
320
+ <ref name="eref"/>
321
+ <ref name="xref"/>
322
+ <ref name="termref"/>
323
+ </choice>
324
+ </element>
325
+ </define>
310
326
  <define name="BasicBlock" combine="choice">
311
327
  <choice>
312
328
  <ref name="requirement"/>
@@ -913,7 +929,10 @@
913
929
  </define>
914
930
  <define name="origin">
915
931
  <element name="origin">
916
- <ref name="erefType"/>
932
+ <choice>
933
+ <ref name="erefType"/>
934
+ <ref name="termref"/>
935
+ </choice>
917
936
  </element>
918
937
  </define>
919
938
  <define name="modification">
@@ -921,6 +940,15 @@
921
940
  <ref name="paragraph"/>
922
941
  </element>
923
942
  </define>
943
+ <define name="termref">
944
+ <element name="termref">
945
+ <attribute name="base"/>
946
+ <attribute name="target"/>
947
+ <optional>
948
+ <text/>
949
+ </optional>
950
+ </element>
951
+ </define>
924
952
  <define name="structuredidentifier">
925
953
  <element name="structuredidentifier">
926
954
  <optional>