metanorma-iec 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (56) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile +7 -0
  3. data/bin/rspec +18 -0
  4. data/lib/asciidoctor/iec/biblio.rng +949 -0
  5. data/lib/asciidoctor/iec/converter.rb +68 -0
  6. data/lib/asciidoctor/iec/iec_intro_en.xml +15 -0
  7. data/lib/asciidoctor/iec/iec_intro_fr.xml +15 -0
  8. data/lib/asciidoctor/iec/isodoc.rng +1132 -0
  9. data/lib/asciidoctor/iec/isostandard.rng +789 -0
  10. data/lib/asciidoctor/iec/reqt.rng +162 -0
  11. data/lib/isodoc/iec/base_convert.rb +69 -0
  12. data/lib/isodoc/iec/html/header.html +160 -0
  13. data/lib/isodoc/iec/html/html_iec_intro.html +34 -0
  14. data/lib/isodoc/iec/html/html_iec_titlepage.html +62 -0
  15. data/lib/isodoc/iec/html/htmlstyle.scss +840 -0
  16. data/lib/isodoc/iec/html/isodoc.scss +785 -0
  17. data/lib/isodoc/iec/html/scripts.html +176 -0
  18. data/lib/isodoc/iec/html/word_iec_intro.html +72 -0
  19. data/lib/isodoc/iec/html/word_iec_titlepage.html +92 -0
  20. data/lib/isodoc/iec/html/wordstyle.scss +1849 -0
  21. data/lib/isodoc/iec/html_convert.rb +33 -0
  22. data/lib/isodoc/iec/i18n-en.yaml +3 -0
  23. data/lib/isodoc/iec/i18n-fr.yaml +3 -0
  24. data/lib/isodoc/iec/i18n-zh-Hans.yaml +3 -0
  25. data/lib/isodoc/iec/metadata.rb +20 -0
  26. data/lib/isodoc/iec/word_convert.rb +165 -0
  27. data/lib/metanorma-iec.rb +12 -0
  28. data/lib/metanorma/iec.rb +8 -0
  29. data/lib/metanorma/iec/processor.rb +40 -0
  30. data/lib/metanorma/iec/version.rb +6 -0
  31. data/metanorma-iec.gemspec +47 -0
  32. data/spec/asciidoctor-iec/base_spec.rb +609 -0
  33. data/spec/asciidoctor-iec/blocks_spec.rb +467 -0
  34. data/spec/asciidoctor-iec/cleanup_spec.rb +766 -0
  35. data/spec/asciidoctor-iec/inline_spec.rb +162 -0
  36. data/spec/asciidoctor-iec/lists_spec.rb +190 -0
  37. data/spec/asciidoctor-iec/macros_spec.rb +21 -0
  38. data/spec/asciidoctor-iec/refs_spec.rb +268 -0
  39. data/spec/asciidoctor-iec/section_spec.rb +341 -0
  40. data/spec/asciidoctor-iec/table_spec.rb +307 -0
  41. data/spec/asciidoctor-iec/validate_spec.rb +132 -0
  42. data/spec/examples/rice.adoc +723 -0
  43. data/spec/examples/rice.doc +19162 -0
  44. data/spec/examples/rice.html +1787 -0
  45. data/spec/examples/rice.xml +1951 -0
  46. data/spec/isodoc/i18n_spec.rb +642 -0
  47. data/spec/isodoc/inline_spec.rb +265 -0
  48. data/spec/isodoc/iso_spec.rb +319 -0
  49. data/spec/isodoc/metadata_spec.rb +153 -0
  50. data/spec/isodoc/postproc_spec.rb +569 -0
  51. data/spec/isodoc/section_spec.rb +686 -0
  52. data/spec/isodoc/terms_spec.rb +206 -0
  53. data/spec/isodoc/xref_spec.rb +1323 -0
  54. data/spec/metanorma/processor_spec.rb +88 -0
  55. data/spec/spec_helper.rb +253 -0
  56. metadata +325 -0
@@ -0,0 +1,467 @@
1
+ require "spec_helper"
2
+
3
+ RSpec.describe Asciidoctor::Iec do
4
+ it "processes open blocks" do
5
+ expect(strip_guid(Asciidoctor.convert(<<~"INPUT", backend: :iec, header_footer: true))).to be_equivalent_to <<~"OUTPUT"
6
+ #{ASCIIDOC_BLANK_HDR}
7
+ --
8
+ x
9
+
10
+ y
11
+
12
+ z
13
+ --
14
+ INPUT
15
+ #{BLANK_HDR}
16
+ <sections><p id="_">x</p>
17
+ <p id="_">y</p>
18
+ <p id="_">z</p></sections>
19
+ </iso-standard>
20
+ OUTPUT
21
+ end
22
+
23
+ it "processes stem blocks" do
24
+ expect(strip_guid(Asciidoctor.convert(<<~"INPUT", backend: :iec, header_footer: true))).to be_equivalent_to <<~"OUTPUT"
25
+ #{ASCIIDOC_BLANK_HDR}
26
+ [stem]
27
+ ++++
28
+ r = 1 %
29
+ r = 1 %
30
+ ++++
31
+
32
+ [stem]
33
+ ++++
34
+ <mml:math><mml:msub xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:m="http://schemas.openxmlformats.org/officeDocument/2006/math"> <mml:mrow> <mml:mrow> <mml:mi mathvariant="bold-italic">F</mml:mi> </mml:mrow> </mml:mrow> <mml:mrow> <mml:mrow> <mml:mi mathvariant="bold-italic">&#x0391;</mml:mi> </mml:mrow> </mml:mrow> </mml:msub> </mml:math>
35
+ ++++
36
+ INPUT
37
+ #{BLANK_HDR}
38
+ <sections>
39
+ <formula id="_">
40
+ <stem type="AsciiMath">r = 1 %
41
+ r = 1 %</stem>
42
+ </formula>
43
+
44
+ <formula id="_">
45
+ <stem type="MathML"><math xmlns="http://www.w3.org/1998/Math/MathML"><msub> <mrow> <mrow> <mi mathvariant="bold-italic">F</mi> </mrow> </mrow> <mrow> <mrow> <mi mathvariant="bold-italic">Α</mi> </mrow> </mrow> </msub> </math></stem>
46
+ </stem>
47
+ </formula>
48
+ </sections>
49
+ </iso-standard>
50
+ OUTPUT
51
+ end
52
+
53
+ it "ignores review blocks unless document is in draft mode" do
54
+ expect(strip_guid(Asciidoctor.convert(<<~"INPUT", backend: :iec, header_footer: true))).to be_equivalent_to <<~"OUTPUT"
55
+ #{ASCIIDOC_BLANK_HDR}
56
+ [[foreword]]
57
+ .Foreword
58
+ Foreword
59
+
60
+ [reviewer=ISO,date=20170101,from=foreword,to=foreword]
61
+ ****
62
+ A Foreword shall appear in each document. The generic text is shown here. It does not contain requirements, recommendations or permissions.
63
+
64
+ For further information on the Foreword, see *ISO/IEC Directives, Part 2, 2016, Clause 12.*
65
+ ****
66
+ INPUT
67
+ #{BLANK_HDR}
68
+ <sections><p id="foreword">Foreword</p>
69
+ </sections>
70
+ </iso-standard>
71
+ OUTPUT
72
+ end
73
+
74
+ it "processes review blocks if document is in draft mode" do
75
+ expect(strip_guid(Asciidoctor.convert(<<~"INPUT", backend: :iec, header_footer: true)).sub(/^.+<sections>/m, "")).to be_equivalent_to <<~"OUTPUT"
76
+ = Document title
77
+ Author
78
+ :docfile: test.adoc
79
+ :nodoc:
80
+ :novalid:
81
+ :draft: 1.2
82
+ :no-isobib:
83
+
84
+ [[foreword]]
85
+ .Foreword
86
+ Foreword
87
+
88
+ [reviewer=ISO,date=20170101,from=foreword,to=foreword]
89
+ ****
90
+ A Foreword shall appear in each document. The generic text is shown here. It does not contain requirements, recommendations or permissions.
91
+
92
+ For further information on the Foreword, see *ISO/IEC Directives, Part 2, 2016, Clause 12.*
93
+ ****
94
+ INPUT
95
+ <p id="foreword">Foreword</p>
96
+ <review reviewer="ISO" id="_" date="20170101T00:00:00Z" from="foreword" to="foreword"><p id="_">A Foreword shall appear in each document. The generic text is shown here. It does not contain requirements, recommendations or permissions.</p>
97
+ <p id="_">For further information on the Foreword, see <strong>ISO/IEC Directives, Part 2, 2016, Clause 12.</strong></p></review></sections>
98
+ </iso-standard>
99
+
100
+ OUTPUT
101
+ end
102
+
103
+ it "processes term notes" do
104
+ expect(strip_guid(Asciidoctor.convert(<<~"INPUT", backend: :iec, header_footer: true))).to be_equivalent_to <<~"OUTPUT"
105
+ #{ASCIIDOC_BLANK_HDR}
106
+ == Terms and Definitions
107
+
108
+ === Term1
109
+
110
+ NOTE: This is a note
111
+ INPUT
112
+ #{BLANK_HDR}
113
+ <sections>
114
+ <terms id="_" obligation="normative">
115
+ <title>Terms and definitions</title>
116
+ <term id="_">
117
+ <preferred>Term1</preferred>
118
+ <termnote id="_">
119
+ <p id="_">This is a note</p>
120
+ </termnote>
121
+ </term>
122
+ </terms>
123
+ </sections>
124
+ </iso-standard>
125
+ OUTPUT
126
+ end
127
+
128
+ it "processes notes" do
129
+ expect(strip_guid(Asciidoctor.convert(<<~"INPUT", backend: :iec, header_footer: true))).to be_equivalent_to <<~"OUTPUT"
130
+ #{ASCIIDOC_BLANK_HDR}
131
+ NOTE: This is a note
132
+ INPUT
133
+ #{BLANK_HDR}
134
+ <sections>
135
+ <note id="_">
136
+ <p id="_">This is a note</p>
137
+ </note>
138
+ </sections>
139
+ </iso-standard>
140
+
141
+ OUTPUT
142
+ end
143
+
144
+ it "processes literals" do
145
+ expect(strip_guid(Asciidoctor.convert(<<~"INPUT", backend: :iec, header_footer: true))).to be_equivalent_to <<~"OUTPUT"
146
+ #{ASCIIDOC_BLANK_HDR}
147
+ ....
148
+ LITERAL
149
+ ....
150
+ INPUT
151
+ #{BLANK_HDR}
152
+ <sections>
153
+ <figure id="_">
154
+ <pre id="_">LITERAL</pre>
155
+ </figure>
156
+ </sections>
157
+ </iso-standard>
158
+ OUTPUT
159
+ end
160
+
161
+ it "processes simple admonitions with Asciidoc names" do
162
+ expect(strip_guid(Asciidoctor.convert(<<~"INPUT", backend: :iec, header_footer: true))).to be_equivalent_to <<~"OUTPUT"
163
+ #{ASCIIDOC_BLANK_HDR}
164
+ CAUTION: Only use paddy or parboiled rice for the determination of husked rice yield.
165
+ INPUT
166
+ #{BLANK_HDR}
167
+ <sections>
168
+ <admonition id="_" type="caution">
169
+ <p id="_">Only use paddy or parboiled rice for the determination of husked rice yield.</p>
170
+ </admonition>
171
+ </sections>
172
+ </iso-standard>
173
+
174
+ OUTPUT
175
+ end
176
+
177
+
178
+ it "processes complex admonitions with non-Asciidoc names" do
179
+ expect(strip_guid(Asciidoctor.convert(<<~"INPUT", backend: :iec, header_footer: true))).to be_equivalent_to <<~"OUTPUT"
180
+ #{ASCIIDOC_BLANK_HDR}
181
+ [CAUTION,type=Safety Precautions]
182
+ .Safety Precautions
183
+ ====
184
+ While werewolves are hardy community members, keep in mind the following dietary concerns:
185
+
186
+ . They are allergic to cinnamon.
187
+ . More than two glasses of orange juice in 24 hours makes them howl in harmony with alarms and sirens.
188
+ . Celery makes them sad.
189
+ ====
190
+ INPUT
191
+ #{BLANK_HDR}
192
+ <sections>
193
+ <admonition id="_" type="safety precautions"><name>Safety Precautions</name><p id="_">While werewolves are hardy community members, keep in mind the following dietary concerns:</p>
194
+ <ol id="_" type="arabic">
195
+ <li>
196
+ <p id="_">They are allergic to cinnamon.</p>
197
+ </li>
198
+ <li>
199
+ <p id="_">More than two glasses of orange juice in 24 hours makes them howl in harmony with alarms and sirens.</p>
200
+ </li>
201
+ <li>
202
+ <p id="_">Celery makes them sad.</p>
203
+ </li>
204
+ </ol></admonition>
205
+ </sections>
206
+ </iso-standard>
207
+
208
+ OUTPUT
209
+ end
210
+
211
+ it "processes term examples" do
212
+ expect(strip_guid(Asciidoctor.convert(<<~"INPUT", backend: :iec, header_footer: true))).to be_equivalent_to <<~"OUTPUT"
213
+ #{ASCIIDOC_BLANK_HDR}
214
+ == Terms and Definitions
215
+
216
+ === Term1
217
+
218
+ [example]
219
+ This is an example
220
+ INPUT
221
+ #{BLANK_HDR}
222
+ <sections>
223
+ <terms id="_" obligation="normative">
224
+ <title>Terms and definitions</title>
225
+ <term id="_">
226
+ <preferred>Term1</preferred>
227
+ <termexample id="_">
228
+ <p id="_">This is an example</p>
229
+ </termexample>
230
+ </term>
231
+ </terms>
232
+ </sections>
233
+ </iso-standard>
234
+
235
+ OUTPUT
236
+ end
237
+
238
+ it "processes examples" do
239
+ expect(strip_guid(Asciidoctor.convert(<<~"INPUT", backend: :iec, header_footer: true))).to be_equivalent_to <<~"OUTPUT"
240
+ #{ASCIIDOC_BLANK_HDR}
241
+ [example]
242
+ ====
243
+ This is an example
244
+
245
+ Amen
246
+ ====
247
+ INPUT
248
+ #{BLANK_HDR}
249
+ <sections>
250
+ <example id="_"><p id="_">This is an example</p>
251
+ <p id="_">Amen</p></example>
252
+ </sections>
253
+ </iso-standard>
254
+ OUTPUT
255
+ end
256
+
257
+ it "processes preambles" do
258
+ expect(strip_guid(Asciidoctor.convert(<<~"INPUT", backend: :iec, header_footer: true))).to be_equivalent_to <<~"OUTPUT"
259
+ #{ASCIIDOC_BLANK_HDR}
260
+ This is a preamble
261
+
262
+ == Section 1
263
+ INPUT
264
+ #{BLANK_HDR}
265
+ <preface><foreword obligation="informative">
266
+ <title>Foreword</title>
267
+ <p id="_">This is a preamble</p>
268
+ </foreword></preface><sections>
269
+ <clause id="_" inline-header="false" obligation="normative">
270
+ <title>Section 1</title>
271
+ </clause></sections>
272
+ </iso-standard>
273
+ OUTPUT
274
+ end
275
+
276
+ it "processes images" do
277
+ expect(strip_guid(Asciidoctor.convert(<<~"INPUT", backend: :iec, header_footer: true))).to be_equivalent_to <<~"OUTPUT"
278
+ #{ASCIIDOC_BLANK_HDR}
279
+ .Split-it-right sample divider
280
+ image::spec/examples/rice_images/rice_image1.png[]
281
+
282
+ INPUT
283
+ #{BLANK_HDR}
284
+ <sections>
285
+ <figure id="_">
286
+ <name>Split-it-right sample divider</name>
287
+ <image src="spec/examples/rice_images/rice_image1.png" id="_" imagetype="PNG" height="auto" width="auto"/>
288
+ </figure>
289
+ </sections>
290
+ </iso-standard>
291
+ OUTPUT
292
+ end
293
+
294
+ it "accepts width and height attributes on images" do
295
+ expect(strip_guid(Asciidoctor.convert(<<~"INPUT", backend: :iec, header_footer: true))).to be_equivalent_to <<~"OUTPUT"
296
+ #{ASCIIDOC_BLANK_HDR}
297
+ [height=4,width=3]
298
+ image::spec/examples/rice_images/rice_image1.png[]
299
+
300
+ INPUT
301
+ #{BLANK_HDR}
302
+ <sections>
303
+ <figure id="_">
304
+ <image src="spec/examples/rice_images/rice_image1.png" id="_" imagetype="PNG" height="4" width="3"/>
305
+ </figure>
306
+ </sections>
307
+ </iso-standard>
308
+ OUTPUT
309
+ end
310
+
311
+ it "accepts auto for width and height attributes on images" do
312
+ expect(strip_guid(Asciidoctor.convert(<<~"INPUT", backend: :iec, header_footer: true))).to be_equivalent_to <<~"OUTPUT"
313
+ #{ASCIIDOC_BLANK_HDR}
314
+ [height=4,width=auto]
315
+ image::spec/examples/rice_images/rice_image1.png[]
316
+
317
+ INPUT
318
+ #{BLANK_HDR}
319
+ <sections>
320
+ <figure id="_">
321
+ <image src="spec/examples/rice_images/rice_image1.png" id="_" imagetype="PNG" height="4" width="auto"/>
322
+ </figure>
323
+ </sections>
324
+ </iso-standard>
325
+ OUTPUT
326
+ end
327
+
328
+ it "accepts alignment attribute on paragraphs" do
329
+ expect(strip_guid(Asciidoctor.convert(<<~"INPUT", backend: :iec, header_footer: true))).to be_equivalent_to <<~"OUTPUT"
330
+ #{ASCIIDOC_BLANK_HDR}
331
+ [align=right]
332
+ This para is right-aligned.
333
+ INPUT
334
+ #{BLANK_HDR}
335
+ <sections>
336
+ <p align="right" id="_">This para is right-aligned.</p>
337
+ </sections>
338
+ </iso-standard>
339
+ OUTPUT
340
+ end
341
+
342
+ it "processes blockquotes" do
343
+ expect(strip_guid(Asciidoctor.convert(<<~"INPUT", backend: :iec, header_footer: true))).to be_equivalent_to <<~"OUTPUT"
344
+ #{ASCIIDOC_BLANK_HDR}
345
+ [quote, ISO, "ISO7301,section 1"]
346
+ ____
347
+ Block quotation
348
+ ____
349
+ INPUT
350
+ #{BLANK_HDR}
351
+ <sections>
352
+ <quote id="_">
353
+ <source type="inline" bibitemid="ISO7301" citeas=""><locality type="section"><referenceFrom>1</referenceFrom></locality></source>
354
+ <author>ISO</author>
355
+ <p id="_">Block quotation</p>
356
+ </quote>
357
+ </sections>
358
+ </iso-standard>
359
+ OUTPUT
360
+ end
361
+
362
+ it "processes source code" do
363
+ expect(strip_guid(Asciidoctor.convert(<<~"INPUT", backend: :iec, header_footer: true))).to be_equivalent_to <<~"OUTPUT"
364
+ #{ASCIIDOC_BLANK_HDR}
365
+ [source,ruby]
366
+ --
367
+ puts "Hello, world."
368
+ %w{a b c}.each do |x|
369
+ puts x
370
+ end
371
+ --
372
+ INPUT
373
+ #{BLANK_HDR}
374
+ <sections>
375
+ <sourcecode lang="ruby" id="_">puts "Hello, world."
376
+ %w{a b c}.each do |x|
377
+ puts x
378
+ end</sourcecode>
379
+ </sections>
380
+ </iso-standard>
381
+ OUTPUT
382
+ end
383
+
384
+ it "processes callouts" do
385
+ expect(strip_guid(Asciidoctor.convert(<<~"INPUT", backend: :iec, header_footer: true))).to be_equivalent_to <<~"OUTPUT"
386
+ #{ASCIIDOC_BLANK_HDR}
387
+ [source,ruby]
388
+ --
389
+ puts "Hello, world." <1>
390
+ %w{a b c}.each do |x|
391
+ puts x <2>
392
+ end
393
+ --
394
+ <1> This is one callout
395
+ <2> This is another callout
396
+ INPUT
397
+ #{BLANK_HDR}
398
+ <sections><sourcecode lang="ruby" id="_">puts "Hello, world." <callout target="_">1</callout>
399
+ %w{a b c}.each do |x|
400
+ puts x <callout target="_">2</callout>
401
+ end<annotation id="_">
402
+ <p id="_">This is one callout</p>
403
+ </annotation><annotation id="_">
404
+ <p id="_">This is another callout</p>
405
+ </annotation></sourcecode>
406
+ </sections>
407
+ </iso-standard>
408
+ OUTPUT
409
+ end
410
+
411
+ it "processes unmodified term sources" do
412
+ expect(strip_guid(Asciidoctor.convert(<<~"INPUT", backend: :iec, header_footer: true))).to be_equivalent_to <<~"OUTPUT"
413
+ #{ASCIIDOC_BLANK_HDR}
414
+ == Terms and Definitions
415
+
416
+ === Term1
417
+
418
+ [.source]
419
+ <<ISO2191,section=1>>
420
+ INPUT
421
+ #{BLANK_HDR}
422
+ <sections>
423
+ <terms id="_" obligation="normative">
424
+ <title>Terms and definitions</title>
425
+ <term id="_">
426
+ <preferred>Term1</preferred>
427
+ <termsource status="identical">
428
+ <origin bibitemid="ISO2191" type="inline" citeas=""><locality type="section"><referenceFrom>1</referenceFrom></locality></origin>
429
+ </termsource>
430
+ </term>
431
+ </terms>
432
+ </sections>
433
+ </iso-standard>
434
+ OUTPUT
435
+ end
436
+
437
+ it "processes modified term sources" do
438
+ expect(strip_guid(Asciidoctor.convert(<<~"INPUT", backend: :iec, header_footer: true))).to be_equivalent_to <<~"OUTPUT"
439
+ #{ASCIIDOC_BLANK_HDR}
440
+ == Terms and Definitions
441
+
442
+ === Term1
443
+
444
+ [.source]
445
+ <<ISO2191,section=1>>, with adjustments
446
+ INPUT
447
+ #{BLANK_HDR}
448
+ <sections>
449
+ <terms id="_" obligation="normative">
450
+ <title>Terms and definitions</title>
451
+ <term id="_">
452
+ <preferred>Term1</preferred>
453
+ <termsource status="modified">
454
+ <origin bibitemid="ISO2191" type="inline" citeas=""><locality type="section"><referenceFrom>1</referenceFrom></locality></origin>
455
+ <modification>
456
+ <p id="_">with adjustments</p>
457
+ </modification>
458
+ </termsource>
459
+ </term>
460
+ </terms>
461
+ </sections>
462
+ </iso-standard>
463
+ OUTPUT
464
+ end
465
+
466
+
467
+ end