metanorma-standoc 1.3.24 → 1.3.25

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 (41) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/macos.yml +2 -1
  3. data/.github/workflows/ubuntu.yml +5 -3
  4. data/.github/workflows/windows.yml +0 -1
  5. data/lib/asciidoctor/standoc/base.rb +22 -8
  6. data/lib/asciidoctor/standoc/biblio.rng +53 -26
  7. data/lib/asciidoctor/standoc/cleanup.rb +8 -7
  8. data/lib/asciidoctor/standoc/cleanup_inline.rb +3 -0
  9. data/lib/asciidoctor/standoc/cleanup_ref.rb +4 -0
  10. data/lib/asciidoctor/standoc/cleanup_section.rb +21 -6
  11. data/lib/asciidoctor/standoc/front.rb +5 -3
  12. data/lib/asciidoctor/standoc/inline.rb +42 -17
  13. data/lib/asciidoctor/standoc/isodoc.rng +28 -1
  14. data/lib/asciidoctor/standoc/macros.rb +2 -1
  15. data/lib/asciidoctor/standoc/macros_yaml2text.rb +142 -0
  16. data/lib/asciidoctor/standoc/ref.rb +5 -3
  17. data/lib/asciidoctor/standoc/section.rb +5 -0
  18. data/lib/asciidoctor/standoc/utils.rb +2 -11
  19. data/lib/metanorma/standoc/latexml_requirement.rb +14 -12
  20. data/lib/metanorma/standoc/version.rb +1 -1
  21. data/metanorma-standoc.gemspec +2 -2
  22. data/spec/asciidoctor-standoc/base_spec.rb +8 -0
  23. data/spec/asciidoctor-standoc/blocks_spec.rb +56 -1
  24. data/spec/asciidoctor-standoc/cleanup_spec.rb +26 -2
  25. data/spec/asciidoctor-standoc/inline_spec.rb +3 -2
  26. data/spec/asciidoctor-standoc/macros_spec.rb +4 -4
  27. data/spec/asciidoctor-standoc/macros_yaml2text_spec.rb +564 -0
  28. data/spec/asciidoctor-standoc/refs_spec.rb +234 -146
  29. data/spec/asciidoctor-standoc/section_spec.rb +58 -0
  30. data/spec/asciidoctor-standoc/validate_spec.rb +34 -0
  31. data/spec/assets/codes.yml +695 -0
  32. data/spec/examples/codes_table.html +3174 -0
  33. data/spec/metanorma/processor_spec.rb +2 -2
  34. data/spec/spec_helper.rb +1 -0
  35. data/spec/vcr_cassettes/dated_iso_ref_joint_iso_iec.yml +71 -265
  36. data/spec/vcr_cassettes/isobib_get_123.yml +38 -84
  37. data/spec/vcr_cassettes/isobib_get_123_2001.yml +20 -43
  38. data/spec/vcr_cassettes/isobib_get_124.yml +19 -101
  39. data/spec/vcr_cassettes/rfcbib_get_rfc8341.yml +8 -8
  40. data/spec/vcr_cassettes/separates_iev_citations_by_top_level_clause.yml +35 -35
  41. metadata +10 -6
@@ -0,0 +1,564 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe Asciidoctor::Standoc::Yaml2TextPreprocessor do
4
+ describe '#process' do
5
+ let(:example_file) { 'example.yml' }
6
+
7
+ before do
8
+ if defined?(example_yaml_content)
9
+ File.open(example_file, 'w') { |n| n.puts(example_yaml_content) }
10
+ end
11
+ end
12
+
13
+ after do
14
+ FileUtils.rm_rf(example_file)
15
+ end
16
+
17
+ context 'Array of hashes' do
18
+ let(:example_yaml_content) do
19
+ <<~TEXT
20
+ ---
21
+ - name: spaghetti
22
+ desc: wheat noodles of 9mm diameter
23
+ symbol: SPAG
24
+ symbol_def: the situation is message like spaghetti at a kid's meal
25
+ TEXT
26
+ end
27
+ let(:input) do
28
+ <<~TEXT
29
+ = Document title
30
+ Author
31
+ :docfile: test.adoc
32
+ :nodoc:
33
+ :novalid:
34
+ :no-isobib:
35
+ :imagesdir: spec/assets
36
+
37
+ [yaml2text,#{example_file},my_context]
38
+ ----
39
+ {my_context.*,item,EOF}
40
+ {item.name}:: {item.desc}
41
+ {EOF}
42
+ ----
43
+ TEXT
44
+ end
45
+ let(:output) do
46
+ <<~TEXT
47
+ #{BLANK_HDR}
48
+ <sections>
49
+ <dl id='_'>
50
+ <dt>spaghetti</dt>
51
+ <dd>
52
+ <p id='_'>wheat noodles of 9mm diameter</p>
53
+ </dd>
54
+ </dl>
55
+ </sections>
56
+ </standard-document>
57
+ TEXT
58
+ end
59
+
60
+ it 'correctly renders input yaml' do
61
+ expect(
62
+ xmlpp(
63
+ strip_guid(
64
+ Asciidoctor.convert(input,
65
+ backend: :standoc,
66
+ header_footer: true),
67
+ ),
68
+ ),
69
+ ).to(be_equivalent_to(xmlpp(output)))
70
+ end
71
+ end
72
+
73
+ context 'An array of strings' do
74
+ let(:example_yaml_content) do
75
+ <<~TEXT
76
+ ---
77
+ - lorem
78
+ - ipsum
79
+ - dolor
80
+ TEXT
81
+ end
82
+ let(:input) do
83
+ <<~TEXT
84
+ = Document title
85
+ Author
86
+ :docfile: test.adoc
87
+ :nodoc:
88
+ :novalid:
89
+ :no-isobib:
90
+ :imagesdir: spec/assets
91
+
92
+ [yaml2text,#{example_file},ar]
93
+ ----
94
+ {ar.*,s,EOS}
95
+ === {s.#} {s}
96
+
97
+ This section is about {s}.
98
+
99
+ {EOS}
100
+ ----
101
+ TEXT
102
+ end
103
+ let(:output) do
104
+ <<~TEXT
105
+ #{BLANK_HDR}
106
+ <sections>
107
+ <clause id="_" inline-header="false" obligation="normative">
108
+ <title>0 lorem</title>
109
+ <p id='_'>This section is about lorem.</p>
110
+ </clause>
111
+ <clause id='_' inline-header='false' obligation='normative'>
112
+ <title>1 ipsum</title>
113
+ <p id='_'>This section is about ipsum.</p>
114
+ </clause>
115
+ <clause id='_' inline-header='false' obligation='normative'>
116
+ <title>2 dolor</title>
117
+ <p id='_'>This section is about dolor.</p>
118
+ </clause>
119
+ </sections>
120
+ </standard-document>
121
+ TEXT
122
+ end
123
+
124
+ it 'correctly renders input yaml' do
125
+ expect(
126
+ xmlpp(
127
+ strip_guid(
128
+ Asciidoctor.convert(input,
129
+ backend: :standoc,
130
+ header_footer: true),
131
+ ),
132
+ ),
133
+ ).to(be_equivalent_to(xmlpp(output)))
134
+ end
135
+ end
136
+
137
+ context 'A simple hash' do
138
+ let(:example_yaml_content) do
139
+ <<~TEXT
140
+ ---
141
+ name: Lorem ipsum
142
+ desc: dolor sit amet
143
+ TEXT
144
+ end
145
+ let(:input) do
146
+ <<~TEXT
147
+ = Document title
148
+ Author
149
+ :docfile: test.adoc
150
+ :nodoc:
151
+ :novalid:
152
+ :no-isobib:
153
+ :imagesdir: spec/assets
154
+
155
+ [yaml2text,#{example_file},my_item]
156
+ ----
157
+ === {my_item.name}
158
+
159
+ {my_item.desc}
160
+ ----
161
+ TEXT
162
+ end
163
+ let(:output) do
164
+ <<~TEXT
165
+ #{BLANK_HDR}
166
+ <sections>
167
+ <clause id="_" inline-header="false" obligation="normative">
168
+ <title>Lorem ipsum</title>
169
+ <p id='_'>dolor sit amet</p>
170
+ </clause>
171
+ </sections>
172
+ </standard-document>
173
+ TEXT
174
+ end
175
+
176
+ it 'correctly renders input yaml' do
177
+ expect(
178
+ xmlpp(
179
+ strip_guid(
180
+ Asciidoctor.convert(input,
181
+ backend: :standoc,
182
+ header_footer: true),
183
+ ),
184
+ ),
185
+ ).to(be_equivalent_to(xmlpp(output)))
186
+ end
187
+ end
188
+
189
+ context 'A simple hash with free keys' do
190
+ let(:example_yaml_content) do
191
+ <<~TEXT
192
+ ---
193
+ name: Lorem ipsum
194
+ desc: dolor sit amet
195
+ TEXT
196
+ end
197
+ let(:input) do
198
+ <<~TEXT
199
+ = Document title
200
+ Author
201
+ :docfile: test.adoc
202
+ :nodoc:
203
+ :novalid:
204
+ :no-isobib:
205
+ :imagesdir: spec/assets
206
+
207
+ [yaml2text,#{example_file},my_item]
208
+ ----
209
+ {my_item.*,key,EOI}
210
+ === {key}
211
+
212
+ {my_item[key]}
213
+
214
+ {EOI}
215
+ ----
216
+ TEXT
217
+ end
218
+ let(:output) do
219
+ <<~TEXT
220
+ #{BLANK_HDR}
221
+ <sections>
222
+ <clause id="_" inline-header="false" obligation="normative">
223
+ <title>name</title>
224
+ <p id='_'>Lorem ipsum</p>
225
+ </clause>
226
+ <clause id='_' inline-header='false' obligation='normative'>
227
+ <title>desc</title>
228
+ <p id='_'>dolor sit amet</p>
229
+ </clause>
230
+ </sections>
231
+ </standard-document>
232
+ TEXT
233
+ end
234
+
235
+ it 'correctly renders input yaml' do
236
+ expect(
237
+ xmlpp(
238
+ strip_guid(
239
+ Asciidoctor.convert(input,
240
+ backend: :standoc,
241
+ header_footer: true),
242
+ ),
243
+ ),
244
+ ).to(be_equivalent_to(xmlpp(output)))
245
+ end
246
+ end
247
+
248
+ context 'An array of hashes' do
249
+ let(:example_yaml_content) do
250
+ <<~TEXT
251
+ ---
252
+ - name: Lorem
253
+ desc: ipsum
254
+ nums: [2]
255
+ - name: dolor
256
+ desc: sit
257
+ nums: []
258
+ - name: amet
259
+ desc: lorem
260
+ nums: [2, 4, 6]
261
+ TEXT
262
+ end
263
+ let(:input) do
264
+ <<~TEXT
265
+ = Document title
266
+ Author
267
+ :docfile: test.adoc
268
+ :nodoc:
269
+ :novalid:
270
+ :no-isobib:
271
+ :imagesdir: spec/assets
272
+
273
+ [yaml2text,#{example_file},ar]
274
+ ----
275
+ {ar.*,item,EOF}
276
+
277
+ {item.name}:: {item.desc}
278
+
279
+ {item.nums.*,num,EON}
280
+ - {item.name}: {num}
281
+ {EON}
282
+
283
+ {EOF}
284
+ ----
285
+ TEXT
286
+ end
287
+ let(:output) do
288
+ <<~TEXT
289
+ #{BLANK_HDR}
290
+ <sections>
291
+ <dl id='_'>
292
+ <dt>Lorem</dt>
293
+ <dd>
294
+ <p id='_'>ipsum</p>
295
+ <ul id='_'>
296
+ <li>
297
+ <p id='_'>Lorem: 2</p>
298
+ </li>
299
+ </ul>
300
+ </dd>
301
+ <dt>dolor</dt>
302
+ <dd>
303
+ <p id='_'>sit</p>
304
+ </dd>
305
+ <dt>amet</dt>
306
+ <dd>
307
+ <p id='_'>lorem</p>
308
+ <ul id='_'>
309
+ <li>
310
+ <p id='_'>amet: 2</p>
311
+ </li>
312
+ <li>
313
+ <p id='_'>amet: 4</p>
314
+ </li>
315
+ <li>
316
+ <p id='_'>amet: 6</p>
317
+ </li>
318
+ </ul>
319
+ </dd>
320
+ </dl>
321
+ </sections>
322
+ </standard-document>
323
+ TEXT
324
+ end
325
+
326
+ it 'correctly renders input yaml' do
327
+ expect(
328
+ xmlpp(
329
+ strip_guid(
330
+ Asciidoctor.convert(input,
331
+ backend: :standoc,
332
+ header_footer: true),
333
+ ),
334
+ ),
335
+ ).to(be_equivalent_to(xmlpp(output)))
336
+ end
337
+ end
338
+
339
+ context "An array with interpolated file names, etc. \
340
+ for Asciidoc's consumption" do
341
+ let(:example_yaml_content) do
342
+ <<~TEXT
343
+ ---
344
+ prefix: doc-
345
+ items:
346
+ - lorem
347
+ - ipsum
348
+ - dolor
349
+ TEXT
350
+ end
351
+ let(:input) do
352
+ <<~TEXT
353
+ = Document title
354
+ Author
355
+ :docfile: test.adoc
356
+ :nodoc:
357
+ :novalid:
358
+ :no-isobib:
359
+ :imagesdir: spec/assets
360
+
361
+ [yaml2text,#{example_file},yaml]
362
+ ------
363
+ First item is {yaml.items[0]}.
364
+ Last item is {yaml.items[-1]}.
365
+
366
+ {yaml.items.*,s,EOS}
367
+ === {s.#} -> {s.# + 1} {s} == {yaml.items[s.#]}
368
+
369
+ [source,ruby]
370
+ ----
371
+ include::{yaml.prefix}{s.#}.rb[]
372
+ ----
373
+
374
+ {EOS}
375
+ ------
376
+ TEXT
377
+ end
378
+ let(:output) do
379
+ <<~TEXT
380
+ #{BLANK_HDR}
381
+ <preface>
382
+ <foreword id='_' obligation='informative'>
383
+ <title>Foreword</title>
384
+ <p id='_'>First item is lorem. Last item is dolor.</p>
385
+ </foreword>
386
+ </preface>
387
+ <sections>
388
+ <clause id='_' inline-header='false' obligation='normative'>
389
+ <title>0 → 1 lorem == lorem</title>
390
+ <sourcecode lang='ruby' id='_'>link:doc-0.rb[]</sourcecode>
391
+ </clause>
392
+ <clause id='_' inline-header='false' obligation='normative'>
393
+ <title>1 → 2 ipsum == ipsum</title>
394
+ <sourcecode lang='ruby' id='_'>link:doc-1.rb[]</sourcecode>
395
+ </clause>
396
+ <clause id='_' inline-header='false' obligation='normative'>
397
+ <title>2 → 3 dolor == dolor</title>
398
+ <sourcecode lang='ruby' id='_'>link:doc-2.rb[]</sourcecode>
399
+ </clause>
400
+ </sections>
401
+ </standard-document>
402
+ TEXT
403
+ end
404
+
405
+ it 'correctly renders input yaml' do
406
+ expect(
407
+ xmlpp(
408
+ strip_guid(
409
+ Asciidoctor.convert(input,
410
+ backend: :standoc,
411
+ header_footer: true),
412
+ ),
413
+ ),
414
+ ).to(be_equivalent_to(xmlpp(output)))
415
+ end
416
+ end
417
+
418
+ context "Array of language codes" do
419
+ let(:input) do
420
+ <<~TEXT
421
+ = Document title
422
+ Author
423
+ :docfile: test.adoc
424
+ :nodoc:
425
+ :novalid:
426
+ :no-isobib:
427
+ :imagesdir: spec/assets
428
+
429
+ [yaml2text,#{File.expand_path('../assets/codes.yml', __dir__)},ar]
430
+ ----
431
+ {ar.*,item,EOF}
432
+ .{item.values[1]}
433
+ [%noheader,cols="h,1"]
434
+ |===
435
+ {item.*,key,EOK}
436
+ | {key} | {item[key]}
437
+
438
+ {EOK}
439
+ |===
440
+ {EOF}
441
+ ----
442
+ TEXT
443
+ end
444
+ let(:output) do
445
+ <<~TEXT
446
+ #{BLANK_HDR}
447
+ <sections>
448
+ #{File.read(File.expand_path('../examples/codes_table.html', __dir__))}
449
+ </sections>
450
+ </standard-document>
451
+ TEXT
452
+ end
453
+
454
+ it 'correctly renders input yaml' do
455
+ expect(
456
+ xmlpp(
457
+ strip_guid(
458
+ Asciidoctor.convert(input,
459
+ backend: :standoc,
460
+ header_footer: true),
461
+ ),
462
+ ),
463
+ ).to(be_equivalent_to(xmlpp(output)))
464
+ end
465
+ end
466
+
467
+ context "Nested hash dot notation" do
468
+ let(:example_yaml_content) do
469
+ <<~TEXT
470
+ data:
471
+ acadsin-zho-hani-latn-2002:
472
+ code: acadsin-zho-hani-latn-2002
473
+ name:
474
+ en: Academica Sinica -- Chinese Tongyong Pinyin (2002)
475
+ authority: acadsin
476
+ lang:
477
+ system: iso-639-2
478
+ code: zho
479
+ source_script: Hani
480
+ target_script: Latn
481
+ system:
482
+ id: '2002'
483
+ specification: Academica Sinica -- Chinese Tongyong Pinyin (2002)
484
+ notes: 'NOTE: OGC 11-122r1 code `zho_Hani2Latn_AcadSin_2002`'
485
+ TEXT
486
+ end
487
+ let(:input) do
488
+ <<~TEXT
489
+ = Document title
490
+ Author
491
+ :docfile: test.adoc
492
+ :nodoc:
493
+ :novalid:
494
+ :no-isobib:
495
+ :imagesdir: spec/assets
496
+
497
+ [yaml2text,#{example_file},authorities]
498
+ ----
499
+ [cols="a,a,a,a",options="header"]
500
+ |===
501
+ | Script conversion system authority code | Name in English | Notes | Name en
502
+
503
+ {authorities.data.*,key,EOI}
504
+ | {key} | {authorities.data[key]['code']} | {authorities.data[key]['notes']} | {authorities.data[key].name.en}
505
+ {EOI}
506
+
507
+ |===
508
+ ----
509
+ TEXT
510
+ end
511
+ let(:output) do
512
+ <<~TEXT
513
+ #{BLANK_HDR}
514
+ <sections>
515
+ <table id='_'>
516
+ <thead>
517
+ <tr>
518
+ <th align='left'>Script conversion system authority code</th>
519
+ <th align='left'>Name in English</th>
520
+ <th align='left'>Notes</th>
521
+ <th align='left'>Name en</th>
522
+ </tr>
523
+ </thead>
524
+ <tbody>
525
+ <tr>
526
+ <td align='left'>
527
+ <p id='_'>acadsin-zho-hani-latn-2002</p>
528
+ </td>
529
+ <td align='left'>
530
+ <p id='_'>acadsin-zho-hani-latn-2002</p>
531
+ </td>
532
+ <td align='left'>
533
+ <note id='_'>
534
+ <p id='_'>
535
+ OGC 11-122r1 code
536
+ <tt>zho_Hani2Latn_AcadSin_2002</tt>
537
+ </p>
538
+ </note>
539
+ </td>
540
+ <td align='left'>
541
+ <p id='_'>Academica Sinica — Chinese Tongyong Pinyin (2002)</p>
542
+ </td>
543
+ </tr>
544
+ </tbody>
545
+ </table>
546
+ </sections>
547
+ </standard-document>
548
+ TEXT
549
+ end
550
+
551
+ it 'correctly renders input yaml' do
552
+ expect(
553
+ xmlpp(
554
+ strip_guid(
555
+ Asciidoctor.convert(input,
556
+ backend: :standoc,
557
+ header_footer: true),
558
+ ),
559
+ ),
560
+ ).to(be_equivalent_to(xmlpp(output)))
561
+ end
562
+ end
563
+ end
564
+ end