metanorma-bsi 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (75) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +6 -0
  3. data/.hound.yml +3 -0
  4. data/.rubocop.yml +14 -0
  5. data/CODE_OF_CONDUCT.md +74 -0
  6. data/Gemfile +7 -0
  7. data/LICENSE +25 -0
  8. data/README.adoc +199 -0
  9. data/Rakefile +8 -0
  10. data/bin/rspec +18 -0
  11. data/lib/asciidoctor/bsi/basicdoc.rng +1131 -0
  12. data/lib/asciidoctor/bsi/biblio.rng +1235 -0
  13. data/lib/asciidoctor/bsi/bsi.rng +120 -0
  14. data/lib/asciidoctor/bsi/bsi_intro_en.xml +105 -0
  15. data/lib/asciidoctor/bsi/cleanup.rb +78 -0
  16. data/lib/asciidoctor/bsi/cleanup_ref.rb +183 -0
  17. data/lib/asciidoctor/bsi/converter.rb +83 -0
  18. data/lib/asciidoctor/bsi/front.rb +67 -0
  19. data/lib/asciidoctor/bsi/isodoc.rng +1870 -0
  20. data/lib/asciidoctor/bsi/isostandard.rng +477 -0
  21. data/lib/asciidoctor/bsi/reqt.rng +194 -0
  22. data/lib/asciidoctor/bsi/validate.rb +224 -0
  23. data/lib/asciidoctor/bsi/validate_list.rb +72 -0
  24. data/lib/asciidoctor/bsi/validate_requirement.rb +163 -0
  25. data/lib/isodoc/bsi/base_convert.rb +91 -0
  26. data/lib/isodoc/bsi/bsi.international-standard.xsl +6540 -0
  27. data/lib/isodoc/bsi/html/html_bsi_intro.html +8 -0
  28. data/lib/isodoc/bsi/html/html_bsi_titlepage.html +50 -0
  29. data/lib/isodoc/bsi/html/htmlstyle.css +968 -0
  30. data/lib/isodoc/bsi/html/htmlstyle.scss +699 -0
  31. data/lib/isodoc/bsi/html_convert.rb +56 -0
  32. data/lib/isodoc/bsi/i18n-en.yaml +56 -0
  33. data/lib/isodoc/bsi/i18n.rb +15 -0
  34. data/lib/isodoc/bsi/init.rb +24 -0
  35. data/lib/isodoc/bsi/metadata.rb +33 -0
  36. data/lib/isodoc/bsi/pdf_convert.rb +17 -0
  37. data/lib/isodoc/bsi/presentation_xml_convert.rb +72 -0
  38. data/lib/isodoc/bsi/sts_convert.rb +30 -0
  39. data/lib/isodoc/bsi/xref.rb +134 -0
  40. data/lib/metanorma-bsi.rb +15 -0
  41. data/lib/metanorma/bsi.rb +6 -0
  42. data/lib/metanorma/bsi/processor.rb +51 -0
  43. data/lib/metanorma/bsi/version.rb +6 -0
  44. data/metanorma-bsi.gemspec +47 -0
  45. data/spec/asciidoctor/base_spec.rb +778 -0
  46. data/spec/asciidoctor/blocks_spec.rb +553 -0
  47. data/spec/asciidoctor/cleanup_spec.rb +547 -0
  48. data/spec/asciidoctor/inline_spec.rb +176 -0
  49. data/spec/asciidoctor/lists_spec.rb +194 -0
  50. data/spec/asciidoctor/refs_spec.rb +318 -0
  51. data/spec/asciidoctor/section_spec.rb +382 -0
  52. data/spec/asciidoctor/validate_spec.rb +858 -0
  53. data/spec/assets/header.html +7 -0
  54. data/spec/assets/html.css +2 -0
  55. data/spec/assets/iso.xml +71 -0
  56. data/spec/assets/rice_image1.png +0 -0
  57. data/spec/assets/word.css +2 -0
  58. data/spec/assets/wordintro.html +4 -0
  59. data/spec/assets/xref_error.adoc +7 -0
  60. data/spec/isodoc/blocks_spec.rb +259 -0
  61. data/spec/isodoc/i18n_spec.rb +442 -0
  62. data/spec/isodoc/inline_spec.rb +287 -0
  63. data/spec/isodoc/iso_spec.rb +116 -0
  64. data/spec/isodoc/metadata_spec.rb +262 -0
  65. data/spec/isodoc/postproc_spec.rb +137 -0
  66. data/spec/isodoc/ref_spec.rb +376 -0
  67. data/spec/isodoc/section_spec.rb +467 -0
  68. data/spec/isodoc/terms_spec.rb +246 -0
  69. data/spec/isodoc/xref_spec.rb +1730 -0
  70. data/spec/metanorma/processor_spec.rb +76 -0
  71. data/spec/spec_helper.rb +291 -0
  72. data/spec/vcr_cassettes/iso-639.yml +182 -0
  73. data/spec/vcr_cassettes/isobib_get_639_1967.yml +136 -0
  74. data/spec/vcr_cassettes/multistandard.yml +352 -0
  75. metadata +343 -0
@@ -0,0 +1,547 @@
1
+ require "spec_helper"
2
+
3
+ RSpec.describe Asciidoctor::BSI do
4
+ before(:all) do
5
+ @blank_hdr = blank_hdr_gen
6
+ end
7
+
8
+ it "removes empty text elements" do
9
+ expect(xmlpp(strip_guid(Asciidoctor.convert(<<~"INPUT", backend: :bsi, header_footer: true)))).to be_equivalent_to xmlpp(<<~"OUTPUT")
10
+ #{ASCIIDOC_BLANK_HDR}
11
+ == {blank}
12
+ INPUT
13
+ #{@blank_hdr}
14
+ <sections>
15
+ <clause id="_" inline-header="false" obligation="normative">
16
+
17
+ </clause>
18
+ </sections>
19
+ </bsi-standard>
20
+ OUTPUT
21
+ end
22
+
23
+ it "processes stem-only terms as admitted" do
24
+ expect(xmlpp(strip_guid(Asciidoctor.convert(<<~"INPUT", backend: :bsi, header_footer: true)))).to be_equivalent_to xmlpp(<<~"OUTPUT")
25
+ #{ASCIIDOC_BLANK_HDR}
26
+ == Terms and Definitions
27
+
28
+ === stem:[t_90]
29
+
30
+ stem:[t_91]
31
+
32
+ Time
33
+ INPUT
34
+ #{@blank_hdr}
35
+ <sections>
36
+ <terms id="_" obligation="normative">
37
+ <title>Terms and definitions</title>
38
+ <p id="_">For the purposes of this British Standard,
39
+ the following terms and definitions apply.</p>
40
+ #{TERMS_BOILERPLATE}
41
+ <term id="term-t90"><preferred><stem type="MathML"><math xmlns="http://www.w3.org/1998/Math/MathML"><msub><mrow>
42
+ <mi>t</mi>
43
+ </mrow>
44
+ <mrow>
45
+ <mn>90</mn>
46
+ </mrow>
47
+ </msub></math></stem></preferred><admitted><stem type="MathML"><math xmlns="http://www.w3.org/1998/Math/MathML"><msub><mrow>
48
+ <mi>t</mi>
49
+ </mrow>
50
+ <mrow>
51
+ <mn>91</mn>
52
+ </mrow>
53
+ </msub></math></stem></admitted>
54
+ <definition><p id="_">Time</p></definition></term>
55
+ </terms>
56
+ </sections>
57
+ </bsi-standard>
58
+ OUTPUT
59
+ end
60
+
61
+ it "permits multiple blocks in term definition paragraph" do
62
+ expect(xmlpp(strip_guid(Asciidoctor.convert(<<~"INPUT", backend: :bsi, header_footer: true)))).to be_equivalent_to xmlpp(<<~"OUTPUT")
63
+ = Document title
64
+ Author
65
+ :docfile: test.adoc
66
+ :nodoc:
67
+ :novalid:
68
+ :stem:
69
+ :no-isobib:
70
+
71
+ == Terms and Definitions
72
+
73
+ === stem:[t_90]
74
+
75
+ [stem]
76
+ ++++
77
+ t_A
78
+ ++++
79
+
80
+ This paragraph is extraneous
81
+ INPUT
82
+ #{@blank_hdr}
83
+ <sections>
84
+ <terms id="_" obligation="normative">
85
+ <title>Terms and definitions</title>
86
+ <p id="_">For the purposes of this British Standard,
87
+ the following terms and definitions apply.</p>
88
+ #{TERMS_BOILERPLATE}
89
+ <term id="term-t90"><preferred><stem type="MathML"><math xmlns="http://www.w3.org/1998/Math/MathML"><msub><mrow>
90
+ <mi>t</mi>
91
+ </mrow>
92
+ <mrow>
93
+ <mn>90</mn>
94
+ </mrow>
95
+ </msub></math></stem></preferred><definition><formula id="_">
96
+ <stem type="MathML"><math xmlns="http://www.w3.org/1998/Math/MathML"><msub><mrow>
97
+ <mi>t</mi>
98
+ </mrow>
99
+ <mrow>
100
+ <mi>A</mi>
101
+ </mrow>
102
+ </msub></math></stem>
103
+ </formula><p id="_">This paragraph is extraneous</p></definition>
104
+ </term>
105
+ </terms>
106
+ </sections>
107
+ </bsi-standard>
108
+ OUTPUT
109
+ end
110
+
111
+ it "keeps any initial boilerplate from terms and definitions" do
112
+ expect(xmlpp(strip_guid(Asciidoctor.convert(<<~"INPUT", backend: :bsi, header_footer: true)))).to be_equivalent_to xmlpp(<<~"OUTPUT")
113
+ #{ASCIIDOC_BLANK_HDR}
114
+ == Terms and Definitions
115
+
116
+ I am boilerplate
117
+
118
+ * So am I
119
+
120
+ === Time
121
+
122
+ This paragraph is extraneous
123
+ INPUT
124
+ #{@blank_hdr}
125
+ <sections>
126
+ <terms id="_" obligation="normative"><title>Terms and definitions</title>
127
+ <p id="_">For the purposes of this British Standard,
128
+ the following terms and definitions apply.</p>
129
+ #{TERMS_BOILERPLATE}
130
+ <p id='_'>I am boilerplate</p>
131
+ <ul id='_'>
132
+ <li>
133
+ <p id='_'>So am I</p>
134
+ </li>
135
+ </ul>
136
+ <term id="term-time">
137
+ <preferred>Time</preferred>
138
+ <definition><p id="_">This paragraph is extraneous</p></definition>
139
+ </term></terms>
140
+ </sections>
141
+ </bsi-standard>
142
+ OUTPUT
143
+ end
144
+
145
+ it "strips type from xrefs" do
146
+ expect(xmlpp(strip_guid(Asciidoctor.convert(<<~"INPUT", backend: :bsi, header_footer: true)))).to be_equivalent_to xmlpp(<<~"OUTPUT")
147
+ #{ASCIIDOC_BLANK_HDR}
148
+ <<iso216>>
149
+
150
+ [bibliography]
151
+ == Clause
152
+ * [[[iso216,ISO 216]]], _Reference_
153
+ INPUT
154
+ #{@blank_hdr}
155
+ <preface>
156
+ <foreword id="_" obligation="informative">
157
+ <title>FOREWORD</title>
158
+ <p id="_">
159
+ <eref type="inline" bibitemid="iso216" citeas="[1]"/>
160
+ </p>
161
+ </foreword></preface><sections>
162
+ </sections><bibliography><references id="_" obligation="informative" normative="false">
163
+ <title>Bibliography</title>
164
+ <p id='_'>
165
+ For dated references, only the edition cited applies. For undated
166
+ references, the latest edition of the referenced document (including any
167
+ amendments) applies.
168
+ </p>
169
+ <bibitem id="iso216" type="standard">
170
+ <title format="text/plain">Reference</title>
171
+ <docidentifier type='metanorma'>[1]</docidentifier>
172
+ <docidentifier>ISO 216</docidentifier>
173
+ <docnumber>216</docnumber>
174
+ <contributor>
175
+ <role type="publisher"/>
176
+ <organization>
177
+ <name>International Organization for Standardization</name>
178
+ <abbreviation>ISO</abbreviation>
179
+ </organization>
180
+ </contributor>
181
+ </bibitem>
182
+ </references></bibliography>
183
+ </bsi-standard>
184
+ OUTPUT
185
+ end
186
+
187
+ it "processes localities in term sources" do
188
+ expect(xmlpp(strip_guid(Asciidoctor.convert(<<~"INPUT", backend: :bsi, header_footer: true)))).to be_equivalent_to xmlpp(<<~"OUTPUT")
189
+ #{ASCIIDOC_BLANK_HDR}
190
+ == Terms and Definitions
191
+
192
+ === Term1
193
+
194
+ [.source]
195
+ <<ISO2191,section=1>>
196
+ INPUT
197
+ #{@blank_hdr}
198
+ <sections>
199
+ <terms id="_" obligation="normative">
200
+ <title>Terms and definitions</title>
201
+ <p id="_">For the purposes of this British Standard, the following terms and definitions apply.</p>
202
+ #{TERMS_BOILERPLATE}
203
+ <term id="term-term1">
204
+ <preferred>Term1</preferred>
205
+ <termsource status="identical">
206
+ <origin bibitemid="ISO2191" type="inline" citeas="">
207
+ <localityStack>
208
+ <locality type="section"><referenceFrom>1</referenceFrom></locality>
209
+ </localityStack>
210
+ </origin>
211
+ </termsource>
212
+ </term>
213
+ </terms>
214
+ </sections>
215
+ </bsi-standard>
216
+ OUTPUT
217
+ end
218
+
219
+ it "removes extraneous material from Normative References" do
220
+ expect(xmlpp(strip_guid(Asciidoctor.convert(<<~"INPUT", backend: :bsi, header_footer: true)))).to be_equivalent_to xmlpp(<<~"OUTPUT")
221
+ #{ASCIIDOC_BLANK_HDR}
222
+ [bibliography]
223
+ == Normative References
224
+
225
+ This is extraneous information
226
+
227
+ * [[[iso216,ISO 216]]], _Reference_
228
+ INPUT
229
+ #{@blank_hdr}
230
+ <sections></sections>
231
+ <bibliography><references id="_" obligation="informative" normative="true"><title>Normative references</title>
232
+ <p id="_">The following documents are referred to in the text in such a way that some or all of their content constitutes provisions of this document. For dated references, only the edition cited applies. For undated references, the latest edition of the referenced document (including any amendments) applies.</p>
233
+ <bibitem id="iso216" type="standard">
234
+ <title format="text/plain">Reference</title>
235
+ <docidentifier type='metanorma'>[N1]</docidentifier>
236
+ <docidentifier>ISO 216</docidentifier>
237
+ <docnumber>216</docnumber>
238
+ <contributor>
239
+ <role type="publisher"/>
240
+ <organization>
241
+ <name>International Organization for Standardization</name>
242
+ <abbreviation>ISO</abbreviation>
243
+ </organization>
244
+ </contributor>
245
+ </bibitem>
246
+ </references>
247
+ </bibliography>
248
+ </bsi-standard>
249
+ OUTPUT
250
+ end
251
+
252
+ it "inserts IDs into paragraphs" do
253
+ expect(xmlpp(strip_guid(Asciidoctor.convert(<<~"INPUT", backend: :bsi, header_footer: true)))).to be_equivalent_to xmlpp(<<~"OUTPUT")
254
+ #{ASCIIDOC_BLANK_HDR}
255
+ Paragraph
256
+ INPUT
257
+ #{@blank_hdr}
258
+ <sections>
259
+ <p id="_">Paragraph</p>
260
+ </sections>
261
+ </bsi-standard>
262
+ OUTPUT
263
+ end
264
+
265
+ it "inserts IDs into notes" do
266
+ expect(xmlpp(strip_guid(Asciidoctor.convert(<<~"INPUT", backend: :bsi, header_footer: true)))).to be_equivalent_to xmlpp(<<~"OUTPUT")
267
+ #{ASCIIDOC_BLANK_HDR}
268
+ [example]
269
+ ====
270
+ NOTE: This note has no ID
271
+ ====
272
+ INPUT
273
+ #{@blank_hdr}
274
+ <sections>
275
+ <example id="_">
276
+ <note id="_">
277
+ <p id="_">This note has no ID</p>
278
+ </note>
279
+ </example>
280
+ </sections>
281
+ </bsi-standard>
282
+ OUTPUT
283
+ end
284
+
285
+ it "moves footnotes inside figures" do
286
+ expect(xmlpp(strip_guid(Asciidoctor.convert(<<~"INPUT", backend: :bsi, header_footer: true)))).to be_equivalent_to xmlpp(<<~"OUTPUT")
287
+ #{ASCIIDOC_BLANK_HDR}
288
+ image::spec/examples/rice_images/rice_image1.png[]
289
+
290
+ footnote:[This is a footnote to a figure]
291
+
292
+ footnote:[This is another footnote to a figure]
293
+ INPUT
294
+ #{@blank_hdr}
295
+ <sections><figure id="_">
296
+ <image src="spec/examples/rice_images/rice_image1.png" id="_" mimetype="image/png" height="auto" width="auto"/>
297
+ <fn reference="A">
298
+ <p id="_">This is a footnote to a figure</p>
299
+ </fn><fn reference="B">
300
+ <p id="_">This is another footnote to a figure</p>
301
+ </fn></figure>
302
+
303
+ </sections>
304
+
305
+ </bsi-standard>
306
+ OUTPUT
307
+ end
308
+
309
+ it "footnotes tables" do
310
+ expect(xmlpp(strip_guid(Asciidoctor.convert(<<~"INPUT", backend: :bsi, header_footer: true)))).to be_equivalent_to xmlpp(<<~"OUTPUT")
311
+ #{ASCIIDOC_BLANK_HDR}
312
+
313
+ |===
314
+ | a | b footnote:[footnote text]
315
+ |===
316
+ INPUT
317
+ #{@blank_hdr}
318
+ <sections>
319
+ <table id='_'>
320
+ <tbody>
321
+ <tr>
322
+ <td valign='top' align='left'>a</td>
323
+ <td valign='top' align='left'>
324
+ b
325
+ <fn reference='A'>
326
+ <p id='_'>footnote text</p>
327
+ </fn>
328
+ </td>
329
+ </tr>
330
+ </tbody>
331
+ </table>
332
+ </sections>
333
+ </bsi-standard>
334
+ OUTPUT
335
+ end
336
+
337
+ it "defaults section obligations" do
338
+ expect(xmlpp(strip_guid(Asciidoctor.convert(<<~"INPUT", backend: :bsi, header_footer: true)))).to be_equivalent_to xmlpp(<<~"OUTPUT")
339
+ #{ASCIIDOC_BLANK_HDR}
340
+
341
+ == Clause
342
+ Text
343
+
344
+ [appendix]
345
+ == Clause
346
+
347
+ Text
348
+ INPUT
349
+ #{@blank_hdr}
350
+ <sections><clause id="_" inline-header="false" obligation="normative">
351
+ <title>Clause</title>
352
+ <p id="_">Text</p>
353
+ </clause>
354
+ </sections><annex id="_" inline-header="false" obligation="normative">
355
+ <title>Clause</title>
356
+ <p id="_">Text</p>
357
+ </annex>
358
+ </bsi-standard>
359
+ OUTPUT
360
+ end
361
+
362
+ it "styles ordered lists" do
363
+ expect(xmlpp(strip_guid(Asciidoctor.convert(<<~"INPUT", backend: :bsi, header_footer: true)))).to be_equivalent_to xmlpp(<<~"OUTPUT")
364
+ #{ASCIIDOC_BLANK_HDR}
365
+
366
+ == Clause1
367
+
368
+ . A
369
+ .. B
370
+ ... C
371
+ .... D
372
+ ..... E
373
+ ...... F
374
+ ....... G
375
+ ........ H
376
+
377
+ [note]
378
+ --
379
+ . A
380
+ .. B
381
+ --
382
+
383
+ . A
384
+ .. B
385
+ ... C
386
+ .... D
387
+ ..... E
388
+ .. F
389
+ .. G
390
+ ... H
391
+ .... I
392
+ ..... J
393
+
394
+ [note]
395
+ --
396
+ . A
397
+ .. B
398
+ --
399
+
400
+ . A
401
+ .. B
402
+ ... C
403
+ .... D
404
+ ..... E
405
+
406
+ INPUT
407
+ #{@blank_hdr}
408
+ <sections>
409
+ <clause id='_' inline-header='false' obligation='normative'>
410
+ <title>Clause1</title>
411
+ <ol id='_' type='alphabet'>
412
+ <li>
413
+ <p id='_'>A</p>
414
+ <ol id='_' type='arabic'>
415
+ <li>
416
+ <p id='_'>B</p>
417
+ <ol id='_' type='roman'>
418
+ <li>
419
+ <p id='_'>C</p>
420
+ <ol id='_' type='alphabet'>
421
+ <li>
422
+ <p id='_'>D</p>
423
+ <ol id='_' type='arabic'>
424
+ <li>
425
+ <p id='_'>E</p>
426
+ <ol id='_' type='roman'>
427
+ <li>
428
+ <p id='_'>F</p>
429
+ <ol id='_' type='alphabet'>
430
+ <li>
431
+ <p id='_'>G</p>
432
+ <ol id='_' type='arabic'>
433
+ <li>
434
+ <p id='_'>H</p>
435
+ </li>
436
+ </ol>
437
+ </li>
438
+ </ol>
439
+ </li>
440
+ </ol>
441
+ </li>
442
+ </ol>
443
+ </li>
444
+ </ol>
445
+ </li>
446
+ </ol>
447
+ </li>
448
+ </ol>
449
+ </li>
450
+ </ol>
451
+ <ol id='_' type='arabic'>
452
+ <li>
453
+ <p id='_'>A</p>
454
+ <ol id='_' type='roman'>
455
+ <li>
456
+ <p id='_'>B</p>
457
+ </li>
458
+ </ol>
459
+ </li>
460
+ </ol>
461
+ <ol id='_' type='roman'>
462
+ <li>
463
+ <p id='_'>A</p>
464
+ <ol id='_' type='alphabet'>
465
+ <li>
466
+ <p id='_'>B</p>
467
+ <ol id='_' type='arabic'>
468
+ <li>
469
+ <p id='_'>C</p>
470
+ <ol id='_' type='roman'>
471
+ <li>
472
+ <p id='_'>D</p>
473
+ <ol id='_' type='alphabet'>
474
+ <li>
475
+ <p id='_'>E</p>
476
+ </li>
477
+ </ol>
478
+ </li>
479
+ </ol>
480
+ </li>
481
+ </ol>
482
+ </li>
483
+ <li>
484
+ <p id='_'>F</p>
485
+ </li>
486
+ <li>
487
+ <p id='_'>G</p>
488
+ <ol id='_' type='arabic'>
489
+ <li>
490
+ <p id='_'>H</p>
491
+ <ol id='_' type='roman'>
492
+ <li>
493
+ <p id='_'>I</p>
494
+ <ol id='_' type='alphabet'>
495
+ <li>
496
+ <p id='_'>J</p>
497
+ </li>
498
+ </ol>
499
+ </li>
500
+ </ol>
501
+ </li>
502
+ </ol>
503
+ </li>
504
+ </ol>
505
+ </li>
506
+ </ol>
507
+ <ol id='_' type='alphabet'>
508
+ <li>
509
+ <p id='_'>A</p>
510
+ <ol id='_' type='arabic'>
511
+ <li>
512
+ <p id='_'>B</p>
513
+ </li>
514
+ </ol>
515
+ </li>
516
+ </ol>
517
+ <ol id='_' type='arabic'>
518
+ <li>
519
+ <p id='_'>A</p>
520
+ <ol id='_' type='roman'>
521
+ <li>
522
+ <p id='_'>B</p>
523
+ <ol id='_' type='alphabet'>
524
+ <li>
525
+ <p id='_'>C</p>
526
+ <ol id='_' type='arabic'>
527
+ <li>
528
+ <p id='_'>D</p>
529
+ <ol id='_' type='roman'>
530
+ <li>
531
+ <p id='_'>E</p>
532
+ </li>
533
+ </ol>
534
+ </li>
535
+ </ol>
536
+ </li>
537
+ </ol>
538
+ </li>
539
+ </ol>
540
+ </li>
541
+ </ol>
542
+ </clause>
543
+ </sections>
544
+ </bsi-standard>
545
+ OUTPUT
546
+ end
547
+ end