metanorma-standoc 1.4.4 → 1.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (74) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/macos.yml +4 -9
  3. data/.github/workflows/ubuntu.yml +1 -5
  4. data/.github/workflows/windows.yml +2 -12
  5. data/.rubocop.yml +1 -1
  6. data/lib/asciidoctor/standoc/base.rb +11 -5
  7. data/lib/asciidoctor/standoc/base_structured_text_preprocessor.rb +123 -0
  8. data/lib/asciidoctor/standoc/basicdoc.rng +23 -0
  9. data/lib/asciidoctor/standoc/cleanup.rb +32 -12
  10. data/lib/asciidoctor/standoc/cleanup_amend.rb +54 -0
  11. data/lib/asciidoctor/standoc/cleanup_block.rb +0 -2
  12. data/lib/asciidoctor/standoc/cleanup_boilerplate.rb +11 -24
  13. data/lib/asciidoctor/standoc/cleanup_footnotes.rb +0 -3
  14. data/lib/asciidoctor/standoc/cleanup_inline.rb +62 -1
  15. data/lib/asciidoctor/standoc/cleanup_ref.rb +10 -7
  16. data/lib/asciidoctor/standoc/cleanup_section.rb +91 -8
  17. data/lib/asciidoctor/standoc/cleanup_terms.rb +12 -2
  18. data/lib/asciidoctor/standoc/converter.rb +3 -3
  19. data/lib/asciidoctor/standoc/front.rb +0 -12
  20. data/lib/asciidoctor/standoc/front_contributor.rb +51 -10
  21. data/lib/asciidoctor/standoc/inline.rb +21 -31
  22. data/lib/asciidoctor/standoc/isodoc.rng +137 -21
  23. data/lib/asciidoctor/standoc/json2_text_preprocessor.rb +44 -0
  24. data/lib/asciidoctor/standoc/log.rb +10 -1
  25. data/lib/asciidoctor/standoc/macros.rb +45 -33
  26. data/lib/asciidoctor/standoc/ref.rb +45 -45
  27. data/lib/asciidoctor/standoc/section.rb +39 -30
  28. data/lib/asciidoctor/standoc/table.rb +3 -2
  29. data/lib/asciidoctor/standoc/utils.rb +18 -1
  30. data/lib/asciidoctor/standoc/validate.rb +30 -18
  31. data/lib/asciidoctor/standoc/validate_section.rb +1 -1
  32. data/lib/asciidoctor/standoc/views/datamodel/model_representation.adoc.erb +10 -10
  33. data/lib/asciidoctor/standoc/yaml2_text_preprocessor.rb +46 -0
  34. data/lib/liquid/custom_blocks/key_iterator.rb +21 -0
  35. data/lib/liquid/custom_filters/values.rb +7 -0
  36. data/lib/metanorma/standoc.rb +0 -5
  37. data/lib/metanorma/standoc/version.rb +20 -1
  38. data/metanorma-standoc.gemspec +4 -5
  39. data/spec/asciidoctor-standoc/base_spec.rb +140 -7
  40. data/spec/asciidoctor-standoc/blocks_spec.rb +275 -149
  41. data/spec/asciidoctor-standoc/cleanup_spec.rb +1372 -56
  42. data/spec/asciidoctor-standoc/inline_spec.rb +133 -6
  43. data/spec/asciidoctor-standoc/isobib_cache_spec.rb +9 -7
  44. data/spec/asciidoctor-standoc/macros_json2text_spec.rb +10 -0
  45. data/spec/asciidoctor-standoc/macros_spec.rb +43 -23
  46. data/spec/asciidoctor-standoc/macros_yaml2text_spec.rb +5 -560
  47. data/spec/asciidoctor-standoc/refs_dl_spec.rb +9 -7
  48. data/spec/asciidoctor-standoc/refs_spec.rb +43 -34
  49. data/spec/asciidoctor-standoc/section_spec.rb +42 -39
  50. data/spec/asciidoctor-standoc/table_spec.rb +119 -113
  51. data/spec/asciidoctor-standoc/validate_spec.rb +45 -1
  52. data/spec/assets/i18n.yaml +17 -2
  53. data/spec/examples/codes_table.html +1365 -1365
  54. data/spec/fixtures/macros_datamodel/address_class_profile.xml +46 -46
  55. data/spec/fixtures/macros_datamodel/address_component_profile.xml +21 -21
  56. data/spec/fixtures/macros_datamodel/blank_definition_profile.xml +21 -21
  57. data/spec/metanorma/processor_spec.rb +1 -2
  58. data/spec/spec_helper.rb +110 -109
  59. data/spec/support/shared_examples/structured_data_2_text_preprocessor.rb +629 -0
  60. data/spec/vcr_cassettes/dated_iso_ref_joint_iso_iec.yml +71 -71
  61. data/spec/vcr_cassettes/isobib_get_123.yml +16 -16
  62. data/spec/vcr_cassettes/isobib_get_123_1.yml +36 -36
  63. data/spec/vcr_cassettes/isobib_get_123_2001.yml +16 -16
  64. data/spec/vcr_cassettes/isobib_get_124.yml +17 -17
  65. data/spec/vcr_cassettes/rfcbib_get_rfc8341.yml +8 -8
  66. data/spec/vcr_cassettes/separates_iev_citations_by_top_level_clause.yml +39 -37
  67. metadata +29 -14
  68. data/lib/asciidoctor-yaml/i18n-en.yaml +0 -20
  69. data/lib/asciidoctor-yaml/i18n-fr.yaml +0 -13
  70. data/lib/asciidoctor-yaml/i18n-zh-Hans.yaml +0 -15
  71. data/lib/asciidoctor/standoc/i18n.rb +0 -39
  72. data/lib/asciidoctor/standoc/macros_yaml2text.rb +0 -165
  73. data/lib/metanorma/standoc/latexml_requirement.rb +0 -62
  74. data/lib/metanorma/standoc/requirement.rb +0 -13
@@ -10,7 +10,7 @@ RSpec.describe Asciidoctor::Standoc do
10
10
  text, including **__nest__**ed markup.
11
11
  INPUT
12
12
  <?xml version="1.0" encoding="UTF-8"?>
13
- <standard-document xmlns="https://www.metanorma.org/ns/standoc">
13
+ <standard-document xmlns="https://www.metanorma.org/ns/standoc" type="semantic" version="#{Metanorma::Standoc::VERSION}">
14
14
  <bibdata type="standard">
15
15
  <title language="en" format="text/plain">Document title</title>
16
16
  <language>en</language>
@@ -77,42 +77,147 @@ text, including <strong><em>nest</em></strong>ed markup.</p>
77
77
  OUTPUT
78
78
  end
79
79
 
80
+ it "process mtext spaces" do
81
+ expect(xmlpp(strip_guid(Asciidoctor.convert(<<~"INPUT", backend: :standoc, header_footer: true)))).to be_equivalent_to xmlpp(<<~"OUTPUT")
82
+ #{DUMBQUOTE_BLANK_HDR}
83
+
84
+ stem:[n < 1 " for all text "]
85
+ INPUT
86
+ #{BLANK_HDR}
87
+ <sections>
88
+ <p id='_'>
89
+ <stem type='MathML'>
90
+ <math xmlns='http://www.w3.org/1998/Math/MathML'>
91
+ <mi>n</mi>
92
+ <mo/>
93
+ <mn>1</mn>
94
+ <mtext> for all text </mtext>
95
+ </math>
96
+ </stem>
97
+ </p>
98
+ </sections>
99
+ </standard-document>
100
+ OUTPUT
101
+ end
102
+
80
103
  it "properly handles inline substitution" do
81
104
  expect(xmlpp(strip_guid(Asciidoctor.convert(<<~"INPUT", backend: :standoc, header_footer: true)))).to be_equivalent_to xmlpp(<<~"OUTPUT")
82
105
  #{DUMBQUOTE_BLANK_HDR}
83
106
 
84
107
  stem:[n < 1] +
85
108
  latexmath:[n < 1]
109
+ stem:["&#x200c;"^199 "Hg"^+]
86
110
  INPUT
87
111
  #{BLANK_HDR}
88
112
  <sections>
89
113
  <p id="_">
90
114
  <stem type="MathML"><math xmlns="http://www.w3.org/1998/Math/MathML"><mi>n</mi><mo>&lt;</mo><mn>1</mn></math></stem><br/>
91
115
  <stem type="MathML"> <math xmlns="http://www.w3.org/1998/Math/MathML"> <mrow> <mi>n</mi> <mo>&lt;</mo> <mn>1</mn> </mrow> </math></stem>
116
+ <stem type='MathML'>
117
+ <math xmlns='http://www.w3.org/1998/Math/MathML'>
118
+ <msup>
119
+ <mrow>
120
+ <mtext>‌</mtext>
121
+ </mrow>
122
+ <mrow>
123
+ <mn>199</mn>
124
+ </mrow>
125
+ </msup>
126
+ <msup>
127
+ <mrow>
128
+ <mtext>Hg</mtext>
129
+ </mrow>
130
+ <mrow>
131
+ <mo>+</mo>
132
+ </mrow>
133
+ </msup>
134
+ </math>
135
+ </stem>
92
136
  </p>
93
137
  </sections>
94
138
  </standard-document>
95
139
  OUTPUT
96
140
  end
97
141
 
98
- it "normalises inline stem" do
142
+ it "normalises inline stem, straight quotes" do
99
143
  expect(xmlpp(strip_guid(Asciidoctor.convert(<<~"INPUT", backend: :standoc, header_footer: true)))).to be_equivalent_to xmlpp(<<~"OUTPUT")
100
144
  #{DUMBQUOTE_BLANK_HDR}
101
145
 
102
146
  stem:[n < 1]
103
147
  latexmath:[n < 1]
148
+ stem:["&#x200c;"^199 "Hg"^+]
149
+ INPUT
150
+ #{BLANK_HDR}
151
+ <sections>
152
+ <p id="_">
153
+ <stem type="MathML"><math xmlns="http://www.w3.org/1998/Math/MathML"><mi>n</mi><mo>&lt;</mo><mn>1</mn></math></stem>
154
+ <stem type="MathML"> <math xmlns="http://www.w3.org/1998/Math/MathML"> <mrow> <mi>n</mi> <mo>&lt;</mo> <mn>1</mn> </mrow> </math></stem>
155
+ <stem type='MathML'>
156
+ <math xmlns='http://www.w3.org/1998/Math/MathML'>
157
+ <msup>
158
+ <mrow>
159
+ <mtext>‌</mtext>
160
+ </mrow>
161
+ <mrow>
162
+ <mn>199</mn>
163
+ </mrow>
164
+ </msup>
165
+ <msup>
166
+ <mrow>
167
+ <mtext>Hg</mtext>
168
+ </mrow>
169
+ <mrow>
170
+ <mo>+</mo>
171
+ </mrow>
172
+ </msup>
173
+ </math>
174
+ </stem>
175
+ </p>
176
+ </sections>
177
+ </standard-document>
178
+ OUTPUT
179
+ end
180
+
181
+ it "normalises inline stem, smart quotes" do
182
+ expect(xmlpp(strip_guid(Asciidoctor.convert(<<~"INPUT", backend: :standoc, header_footer: true)))).to be_equivalent_to xmlpp(<<~"OUTPUT")
183
+ #{ASCIIDOC_BLANK_HDR}
184
+
185
+ stem:[n < 1]
186
+ latexmath:[n < 1]
187
+ stem:["&#x200c;"^199 "Hg"^+]
104
188
  INPUT
105
189
  #{BLANK_HDR}
106
190
  <sections>
107
191
  <p id="_">
108
192
  <stem type="MathML"><math xmlns="http://www.w3.org/1998/Math/MathML"><mi>n</mi><mo>&lt;</mo><mn>1</mn></math></stem>
109
193
  <stem type="MathML"> <math xmlns="http://www.w3.org/1998/Math/MathML"> <mrow> <mi>n</mi> <mo>&lt;</mo> <mn>1</mn> </mrow> </math></stem>
194
+ <stem type='MathML'>
195
+ <math xmlns='http://www.w3.org/1998/Math/MathML'>
196
+ <msup>
197
+ <mrow>
198
+ <mtext>‌</mtext>
199
+ </mrow>
200
+ <mrow>
201
+ <mn>199</mn>
202
+ </mrow>
203
+ </msup>
204
+ <msup>
205
+ <mrow>
206
+ <mtext>Hg</mtext>
207
+ </mrow>
208
+ <mrow>
209
+ <mo>+</mo>
210
+ </mrow>
211
+ </msup>
212
+ </math>
213
+ </stem>
110
214
  </p>
111
215
  </sections>
112
216
  </standard-document>
113
217
  OUTPUT
114
218
  end
115
219
 
220
+
116
221
  it "generates desired smart quotes for 'dd'" do
117
222
  expect(xmlpp(strip_guid(Asciidoctor.convert(<<~"INPUT", backend: :standoc, header_footer: true)))).to be_equivalent_to xmlpp(<<~"OUTPUT")
118
223
  #{ASCIIDOC_BLANK_HDR}
@@ -162,13 +267,16 @@ text, including <strong><em>nest</em></strong>ed markup.</p>
162
267
  http://example.com[]
163
268
  http://example.com[Link]
164
269
  http://example.com[Link,title="tip"]
270
+ link:++https://asciidoctor.org/now_this__link_works.html++[]
165
271
  INPUT
166
272
  #{BLANK_HDR}
167
273
  <sections>
168
274
  <p id="_">mailto:fred@example.com
169
275
  <link target="http://example.com"/>
170
276
  <link target="http://example.com">Link</link>
171
- <link target="http://example.com" alt="tip">Link</link></p>
277
+ <link target="http://example.com" alt="tip">Link</link>
278
+ <link target='https://asciidoctor.org/now_this__link_works.html'/>
279
+ </p>
172
280
  </sections>
173
281
  </standard-document>
174
282
  OUTPUT
@@ -198,8 +306,14 @@ text, including <strong><em>nest</em></strong>ed markup.</p>
198
306
  Inline Reference with Text to <<reference,text>>
199
307
  Footnoted Reference with Text to <<reference,fn: text>>
200
308
  Anchored Crossreference to other document <<a.adoc#b>>
309
+ Capitalised Reference to <<reference,droploc%capital%>>
310
+ Lowercase Footnoted Reference to <<reference,capital%droploc%fn>>
201
311
  Capitalised Reference to <<reference,capital%>>
202
312
  Lowercase Footnoted Reference to <<reference,capital%fn>>
313
+ Capitalised Reference to <<reference,droploc%>>
314
+ Lowercase Footnoted Reference to <<reference,droploc%fn>>
315
+ Capitalised Reference to <<reference,droploc%capital%>>
316
+ Lowercase Footnoted Reference to <<reference,droploc%capital%fn>>
203
317
  INPUT
204
318
  #{BLANK_HDR}
205
319
  <sections>
@@ -210,8 +324,21 @@ text, including <strong><em>nest</em></strong>ed markup.</p>
210
324
  Inline Reference with Text to <xref target="reference">text</xref>
211
325
  Footnoted Reference with Text to <xref target="reference">text</xref>
212
326
  Anchored Crossreference to other document <xref target="a#b"/>
213
- Capitalised Reference to <xref target='reference' case='capital'></xref>
214
- Lowercase Footnoted Reference to <xref target='reference' case='capital'></xref></p>
327
+ Capitalised Reference to <xref target='reference' case='capital' droploc="true"></xref>
328
+ Lowercase Footnoted Reference to <xref target='reference' case='capital' droploc="true"></xref>
329
+ Capitalised Reference to
330
+ <xref target='reference' case='capital'/>
331
+ Lowercase Footnoted Reference to
332
+ <xref target='reference' case='capital'/>
333
+ Capitalised Reference to
334
+ <xref target='reference' droploc='true'/>
335
+ Lowercase Footnoted Reference to
336
+ <xref target='reference' droploc='true'/>
337
+ Capitalised Reference to
338
+ <xref target='reference' case='capital' droploc='true'/>
339
+ Lowercase Footnoted Reference to
340
+ <xref target='reference' case='capital' droploc='true'/>
341
+ </p>
215
342
  </clause>
216
343
  </sections>
217
344
  </standard-document>
@@ -232,7 +359,7 @@ text, including <strong><em>nest</em></strong>ed markup.</p>
232
359
  <sections>
233
360
 
234
361
  </sections><bibliography><references id="_" obligation="informative" normative="true">
235
- <title>Normative References</title>
362
+ <title>Normative references</title>
236
363
  <p id="_">The following documents are referred to in the text in such a way that some or all of their content constitutes requirements 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>
237
364
  <bibitem id="ISO712">
238
365
  <formattedref format="application/x-isodoc+xml">Reference</formattedref>
@@ -55,6 +55,7 @@ EOS
55
55
  <uri type="obp">https://www.iso.org/obp/ui/#!iso:std:61884:en</uri>
56
56
  <uri type="rss">https://www.iso.org/contents/data/standard/06/18/61884.detail.rss</uri>
57
57
  <docidentifier type="ISO">ISO 124:2014</docidentifier>
58
+ <docidentifier type='URN'>urn:iso:std:iso:124:stage-90.93:ed-7:en,fr</docidentifier>
58
59
  <docnumber>124</docnumber>
59
60
  <date type="published">
60
61
  <on>2014</on>
@@ -225,6 +226,7 @@ EOS
225
226
  <uri type="obp">https://www.iso.org/obp/ui/#!iso:std:23281:en</uri>
226
227
  <uri type="rss">https://www.iso.org/contents/data/standard/02/32/23281.detail.rss</uri>
227
228
  <docidentifier type="ISO">ISO 123:2001</docidentifier>
229
+ <docidentifier type='URN'>urn:iso:std:iso:123:stage-90.93:ed-3:en,fr</docidentifier>
228
230
  <docnumber>123</docnumber>
229
231
  <date type="published">
230
232
  <on>2001</on>
@@ -340,7 +342,7 @@ EOS
340
342
  FileUtils.rm_rf File.expand_path("~/.iev/cache")
341
343
 
342
344
  # mock_isobib_get_123
343
- VCR.use_cassette "isobib_get_123_2001" do
345
+ VCR.use_cassette "isobib_get_123_2001", :re_record_interval => 25200 do
344
346
  Asciidoctor.convert(<<~"INPUT", backend: :standoc, header_footer: true)
345
347
  #{FLUSH_CACHE_ISOBIB_BLANK_HDR}
346
348
  [bibliography]
@@ -421,7 +423,7 @@ EOS
421
423
  it "activates global cache" do
422
424
  FileUtils.mv File.expand_path("~/.relaton/cache"), File.expand_path("~/.relaton-bib.pstore1"), force: true
423
425
  FileUtils.rm_rf "relaton/cache"
424
- VCR.use_cassette "isobib_get_123_2001" do
426
+ VCR.use_cassette "isobib_get_123_2001", :re_record_interval => 25200 do
425
427
  Asciidoctor.convert(<<~"INPUT", backend: :standoc, header_footer: true)
426
428
  #{CACHED_ISOBIB_BLANK_HDR}
427
429
  [bibliography]
@@ -541,7 +543,7 @@ EOS
541
543
  #)
542
544
 
543
545
  # mock_isobib_get_124
544
- VCR.use_cassette "isobib_get_124" do
546
+ VCR.use_cassette "isobib_get_124", :re_record_interval => 25200 do
545
547
  Asciidoctor.convert(<<~"INPUT", backend: :standoc, header_footer: true)
546
548
  #{CACHED_ISOBIB_BLANK_HDR}
547
549
  [bibliography]
@@ -580,7 +582,7 @@ EOS
580
582
  #)
581
583
 
582
584
  # mock_isobib_get_123_undated
583
- VCR.use_cassette "isobib_get_123" do
585
+ VCR.use_cassette "isobib_get_123", :re_record_interval => 25200 do
584
586
  Asciidoctor.convert(<<~"INPUT", backend: :standoc, header_footer: true)
585
587
  #{CACHED_ISOBIB_BLANK_HDR}
586
588
  [bibliography]
@@ -601,7 +603,7 @@ EOS
601
603
  end
602
604
 
603
605
  it "does not expire stale dated references" do
604
- VCR.use_cassette "isobib_get_123_2001" do
606
+ VCR.use_cassette "isobib_get_123_2001", :re_record_interval => 25200 do
605
607
  FileUtils.rm_rf File.expand_path("~/.relaton-bib.pstore1")
606
608
  FileUtils.mv File.expand_path("~/.relaton/cache"), File.expand_path("~/.relaton-bib.pstore1"), force: true
607
609
 
@@ -635,8 +637,8 @@ EOS
635
637
  end
636
638
 
637
639
  it "prioritises local over global cache values" do
638
- VCR.use_cassette "isobib_get_123_2001" do
639
- VCR.use_cassette "isobib_get_124" do
640
+ VCR.use_cassette "isobib_get_123_2001", :re_record_interval => 25200 do
641
+ VCR.use_cassette "isobib_get_124", :re_record_interval => 25200 do
640
642
  FileUtils.rm_rf File.expand_path("~/.relaton-bib.pstore1")
641
643
  FileUtils.mv File.expand_path("~/.relaton/cache"), File.expand_path("~/.relaton-bib.pstore1"), force: true
642
644
  FileUtils.rm_rf "relaton/cache"
@@ -0,0 +1,10 @@
1
+ require "spec_helper"
2
+
3
+ RSpec.describe Asciidoctor::Standoc::Json2TextPreprocessor do
4
+ it_behaves_like "structured data 2 text preprocessor" do
5
+ let(:extention) { "json" }
6
+ def transform_to_type(data)
7
+ data.to_json
8
+ end
9
+ end
10
+ end
@@ -8,6 +8,7 @@ RSpec.describe Asciidoctor::Standoc do
8
8
  deprecated:[term1]
9
9
  domain:[term1]
10
10
  inherit:[<<ref1>>]
11
+ autonumber:table[3]
11
12
 
12
13
  [bibliography]
13
14
  == Bibliography
@@ -23,6 +24,7 @@ RSpec.describe Asciidoctor::Standoc do
23
24
  <inherit>
24
25
  <eref type='inline' bibitemid='ref1' citeas='XYZ 123'/>
25
26
  </inherit>
27
+ <autonumber type='table'>3</autonumber>
26
28
  </foreword>
27
29
  </preface>
28
30
  <sections> </sections>
@@ -293,29 +295,47 @@ OUTPUT
293
295
  <formula id='_'>
294
296
  <stem type='MathML'>
295
297
  <math xmlns='http://www.w3.org/1998/Math/MathML'>
296
- <mover>
297
- <mi>X</mi>
298
- <mo>¯</mo>
299
- </mover>
300
- <mo>′</mo>
301
- <mo>=</mo>
302
- <mfrac>
303
- <mn>1</mn>
304
- <mi>v</mi>
305
- </mfrac>
306
- <munderover>
307
- <mo>∑</mo>
308
- <mrow>
309
- <mi>i</mi>
310
- <mo>=</mo>
311
- <mn>1</mn>
312
- </mrow>
313
- <mi>v</mi>
314
- </munderover>
315
- <msub>
316
- <mi>t</mi>
317
- <mi>i</mi>
318
- </msub>
298
+ <mover>
299
+ <mrow>
300
+ <mi>X</mi>
301
+ </mrow>
302
+ <mrow>
303
+ <mo>¯</mo>
304
+ </mrow>
305
+ </mover>
306
+ <mo>′</mo>
307
+ <mo>=</mo>
308
+ <mfrac>
309
+ <mrow>
310
+ <mn>1</mn>
311
+ </mrow>
312
+ <mrow>
313
+ <mi>v</mi>
314
+ </mrow>
315
+ </mfrac>
316
+ <munderover>
317
+ <mrow>
318
+ <mo>∑</mo>
319
+ </mrow>
320
+ <mrow>
321
+ <mrow>
322
+ <mi>i</mi>
323
+ <mo>=</mo>
324
+ <mn>1</mn>
325
+ </mrow>
326
+ </mrow>
327
+ <mrow>
328
+ <mi>v</mi>
329
+ </mrow>
330
+ </munderover>
331
+ <msub>
332
+ <mrow>
333
+ <mi>t</mi>
334
+ </mrow>
335
+ <mrow>
336
+ <mi>i</mi>
337
+ </mrow>
338
+ </msub>
319
339
  </math>
320
340
  </stem>
321
341
  </formula>
@@ -1,565 +1,10 @@
1
- require 'spec_helper'
1
+ require "spec_helper"
2
2
 
3
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
- # TODO: fix frozen string error
406
- xit 'correctly renders input yaml' do
407
- expect(
408
- xmlpp(
409
- strip_guid(
410
- Asciidoctor.convert(input,
411
- backend: :standoc,
412
- header_footer: true),
413
- ),
414
- ),
415
- ).to(be_equivalent_to(xmlpp(output)))
416
- end
417
- end
418
-
419
- context "Array of language codes" do
420
- let(:input) do
421
- <<~TEXT
422
- = Document title
423
- Author
424
- :docfile: test.adoc
425
- :nodoc:
426
- :novalid:
427
- :no-isobib:
428
- :imagesdir: spec/assets
429
-
430
- [yaml2text,#{File.expand_path('../assets/codes.yml', __dir__)},ar]
431
- ----
432
- {ar.*,item,EOF}
433
- .{item.values[1]}
434
- [%noheader,cols="h,1"]
435
- |===
436
- {item.*,key,EOK}
437
- | {key} | {item[key]}
438
-
439
- {EOK}
440
- |===
441
- {EOF}
442
- ----
443
- TEXT
444
- end
445
- let(:output) do
446
- <<~TEXT
447
- #{BLANK_HDR}
448
- <sections>
449
- #{File.read(File.expand_path('../examples/codes_table.html', __dir__))}
450
- </sections>
451
- </standard-document>
452
- TEXT
453
- end
454
-
455
- it 'correctly renders input yaml' do
456
- expect(
457
- xmlpp(
458
- strip_guid(
459
- Asciidoctor.convert(input,
460
- backend: :standoc,
461
- header_footer: true),
462
- ),
463
- ),
464
- ).to(be_equivalent_to(xmlpp(output)))
465
- end
466
- end
467
-
468
- context "Nested hash dot notation" do
469
- let(:example_yaml_content) do
470
- <<~TEXT
471
- data:
472
- acadsin-zho-hani-latn-2002:
473
- code: acadsin-zho-hani-latn-2002
474
- name:
475
- en: Academica Sinica -- Chinese Tongyong Pinyin (2002)
476
- authority: acadsin
477
- lang:
478
- system: iso-639-2
479
- code: zho
480
- source_script: Hani
481
- target_script: Latn
482
- system:
483
- id: '2002'
484
- specification: Academica Sinica -- Chinese Tongyong Pinyin (2002)
485
- notes: 'NOTE: OGC 11-122r1 code `zho_Hani2Latn_AcadSin_2002`'
486
- TEXT
487
- end
488
- let(:input) do
489
- <<~TEXT
490
- = Document title
491
- Author
492
- :docfile: test.adoc
493
- :nodoc:
494
- :novalid:
495
- :no-isobib:
496
- :imagesdir: spec/assets
497
-
498
- [yaml2text,#{example_file},authorities]
499
- ----
500
- [cols="a,a,a,a",options="header"]
501
- |===
502
- | Script conversion system authority code | Name in English | Notes | Name en
503
-
504
- {authorities.data.*,key,EOI}
505
- | {key} | {authorities.data[key]['code']} | {authorities.data[key]['notes']} | {authorities.data[key].name.en}
506
- {EOI}
507
-
508
- |===
509
- ----
510
- TEXT
511
- end
512
- let(:output) do
513
- <<~TEXT
514
- #{BLANK_HDR}
515
- <sections>
516
- <table id='_'>
517
- <thead>
518
- <tr>
519
- <th align='left'>Script conversion system authority code</th>
520
- <th align='left'>Name in English</th>
521
- <th align='left'>Notes</th>
522
- <th align='left'>Name en</th>
523
- </tr>
524
- </thead>
525
- <tbody>
526
- <tr>
527
- <td align='left'>
528
- <p id='_'>acadsin-zho-hani-latn-2002</p>
529
- </td>
530
- <td align='left'>
531
- <p id='_'>acadsin-zho-hani-latn-2002</p>
532
- </td>
533
- <td align='left'>
534
- <note id='_'>
535
- <p id='_'>
536
- OGC 11-122r1 code
537
- <tt>zho_Hani2Latn_AcadSin_2002</tt>
538
- </p>
539
- </note>
540
- </td>
541
- <td align='left'>
542
- <p id='_'>Academica Sinica — Chinese Tongyong Pinyin (2002)</p>
543
- </td>
544
- </tr>
545
- </tbody>
546
- </table>
547
- </sections>
548
- </standard-document>
549
- TEXT
550
- end
551
-
552
- it 'correctly renders input yaml' do
553
- expect(
554
- xmlpp(
555
- strip_guid(
556
- Asciidoctor.convert(input,
557
- backend: :standoc,
558
- header_footer: true),
559
- ),
560
- ),
561
- ).to(be_equivalent_to(xmlpp(output)))
562
- end
4
+ it_behaves_like "structured data 2 text preprocessor" do
5
+ let(:extention) { "yaml" }
6
+ def transform_to_type(data)
7
+ data.to_yaml
563
8
  end
564
9
  end
565
10
  end