metanorma-standoc 1.6.0 → 1.6.5

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 (63) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/rake.yml +66 -0
  3. data/README.adoc +1 -3
  4. data/lib/asciidoctor/standoc/base.rb +8 -16
  5. data/lib/asciidoctor/standoc/basicdoc.rng +32 -0
  6. data/lib/asciidoctor/standoc/cleanup.rb +52 -4
  7. data/lib/asciidoctor/standoc/cleanup_block.rb +41 -4
  8. data/lib/asciidoctor/standoc/cleanup_boilerplate.rb +14 -0
  9. data/lib/asciidoctor/standoc/cleanup_footnotes.rb +25 -0
  10. data/lib/asciidoctor/standoc/cleanup_inline.rb +6 -2
  11. data/lib/asciidoctor/standoc/cleanup_ref.rb +18 -25
  12. data/lib/asciidoctor/standoc/cleanup_terms.rb +3 -0
  13. data/lib/asciidoctor/standoc/converter.rb +61 -3
  14. data/lib/asciidoctor/standoc/front.rb +9 -3
  15. data/lib/asciidoctor/standoc/front_contributor.rb +34 -10
  16. data/lib/asciidoctor/standoc/isodoc.rng +29 -44
  17. data/lib/asciidoctor/standoc/lists.rb +4 -2
  18. data/lib/asciidoctor/standoc/macros.rb +45 -63
  19. data/lib/asciidoctor/standoc/macros_terms.rb +82 -0
  20. data/lib/asciidoctor/standoc/ref.rb +24 -36
  21. data/lib/asciidoctor/standoc/ref_sect.rb +16 -8
  22. data/lib/asciidoctor/standoc/section.rb +5 -9
  23. data/lib/asciidoctor/standoc/table.rb +12 -0
  24. data/lib/asciidoctor/standoc/term_lookup_cleanup.rb +86 -0
  25. data/lib/liquid/custom_blocks/with_json_nested_context.rb +18 -0
  26. data/lib/liquid/custom_blocks/with_yaml_nested_context.rb +19 -0
  27. data/lib/metanorma/standoc/version.rb +1 -1
  28. data/metanorma-standoc.gemspec +6 -3
  29. data/spec/asciidoctor-standoc/base_spec.rb +127 -8
  30. data/spec/asciidoctor-standoc/blocks_spec.rb +8 -8
  31. data/spec/asciidoctor-standoc/cleanup_sections_spec.rb +1514 -0
  32. data/spec/asciidoctor-standoc/cleanup_spec.rb +450 -1554
  33. data/spec/asciidoctor-standoc/isobib_cache_spec.rb +22 -31
  34. data/spec/asciidoctor-standoc/lists_spec.rb +10 -1
  35. data/spec/asciidoctor-standoc/macros_json2text_spec.rb +1 -1
  36. data/spec/asciidoctor-standoc/macros_lutaml_spec.rb +80 -0
  37. data/spec/asciidoctor-standoc/macros_plantuml_spec.rb +307 -0
  38. data/spec/asciidoctor-standoc/macros_spec.rb +378 -169
  39. data/spec/asciidoctor-standoc/macros_yaml2text_spec.rb +1 -1
  40. data/spec/asciidoctor-standoc/refs_dl_spec.rb +8 -8
  41. data/spec/asciidoctor-standoc/refs_spec.rb +350 -101
  42. data/spec/asciidoctor-standoc/section_spec.rb +11 -11
  43. data/spec/asciidoctor-standoc/table_spec.rb +86 -0
  44. data/spec/asciidoctor-standoc/validate_spec.rb +26 -0
  45. data/spec/fixtures/diagram_definitions.lutaml +22 -0
  46. data/spec/fixtures/test.exp +121 -0
  47. data/spec/spec_helper.rb +33 -0
  48. data/spec/support/shared_examples/structured_data_2_text_preprocessor.rb +156 -4
  49. data/spec/vcr_cassettes/dated_iso_ref_joint_iso_iec.yml +49 -233
  50. data/spec/vcr_cassettes/isobib_get_123.yml +12 -58
  51. data/spec/vcr_cassettes/isobib_get_123_1.yml +27 -119
  52. data/spec/vcr_cassettes/isobib_get_123_1_fr.yml +361 -0
  53. data/spec/vcr_cassettes/isobib_get_123_2001.yml +12 -58
  54. data/spec/vcr_cassettes/isobib_get_124.yml +11 -57
  55. data/spec/vcr_cassettes/rfcbib_get_rfc8341.yml +8 -8
  56. data/spec/vcr_cassettes/separates_iev_citations_by_top_level_clause.yml +276 -158
  57. metadata +61 -14
  58. data/.github/workflows/macos.yml +0 -41
  59. data/.github/workflows/ubuntu.yml +0 -45
  60. data/.github/workflows/windows.yml +0 -43
  61. data/lib/asciidoctor/standoc/base_structured_text_preprocessor.rb +0 -123
  62. data/lib/asciidoctor/standoc/json2_text_preprocessor.rb +0 -44
  63. data/lib/asciidoctor/standoc/yaml2_text_preprocessor.rb +0 -46
@@ -48,17 +48,14 @@ EOS
48
48
  <title type="title-intro" format="text/plain" language="en" script="Latn">Latex, rubber</title>
49
49
  <title type="title-main" format="text/plain" language="en" script="Latn">Determination of total solids content</title>
50
50
  <title type='main' format='text/plain' language='en' script='Latn'>Latex, rubber - Determination of total solids content</title>
51
- <title type="title-intro" format="text/plain" language="fr" script="Latn">Latex de caoutchouc</title>
52
- <title type="title-main" format="text/plain" language="fr" script="Latn">Détermination des matières solides totales</title>
53
- <title type='main' format='text/plain' language='fr' script='Latn'>Latex de caoutchouc - Détermination des matières solides totales</title>
54
51
  <uri type="src">https://www.iso.org/standard/61884.html</uri>
55
52
  <uri type="obp">https://www.iso.org/obp/ui/#!iso:std:61884:en</uri>
56
53
  <uri type="rss">https://www.iso.org/contents/data/standard/06/18/61884.detail.rss</uri>
57
54
  <docidentifier type="ISO">ISO 124:2014</docidentifier>
58
- <docidentifier type='URN'>urn:iso:std:iso:124:stage-90.93:ed-7:en,fr</docidentifier>
55
+ <docidentifier type='URN'>urn:iso:std:iso:124:stage-90.93:ed-7:en</docidentifier>
59
56
  <docnumber>124</docnumber>
60
57
  <date type="published">
61
- <on>2014</on>
58
+ <on>2014-03</on>
62
59
  </date>
63
60
  <contributor>
64
61
  <role type="publisher"/>
@@ -70,10 +67,8 @@ EOS
70
67
  </contributor>
71
68
  <edition>7</edition>
72
69
  <language>en</language>
73
- <language>fr</language>
74
70
  <script>Latn</script>
75
71
  <abstract format="text/plain" language="en" script="Latn">ISO 124:2014 specifies methods for the determination of the total solids content of natural rubber field and concentrated latices and synthetic rubber latex. These methods are not necessarily suitable for latex from natural sources other than the Hevea brasiliensis, for vulcanized latex, for compounded latex, or for artificial dispersions of rubber.</abstract>
76
- <abstract format="text/plain" language="fr" script="Latn">L'ISO 124:2014 spécifie des méthodes pour la détermination des matières solides totales dans le latex de plantation, le latex de concentré de caoutchouc naturel et le latex de caoutchouc synthétique. Ces méthodes ne conviennent pas nécessairement au latex d'origine naturelle autre que celui de l'Hevea brasiliensis, au latex vulcanisé, aux mélanges de latex, ou aux dispersions artificielles de caoutchouc.</abstract>
77
72
  <status>
78
73
  <stage>90</stage>
79
74
  <substage>93</substage>
@@ -114,9 +109,6 @@ EOS
114
109
  <title type="title-intro" format="text/plain" language="en" script="Latn">Rubber latex</title>
115
110
  <title type="title-main" format="text/plain" language="en" script="Latn">Sampling</title>
116
111
  <title type="main" format="text/plain" language="en" script="Latn">Rubber latex – Sampling</title>
117
- <title type="title-intro" format="text/plain" language="fr" script="Latn">Latex de caoutchouc</title>
118
- <title type="title-main" format="text/plain" language="fr" script="Latn">Échantillonnage</title>
119
- <title type="main" format="text/plain" language="fr" script="Latn">Latex de caoutchouc – Échantillonnage</title>
120
112
  <uri type="src">https://www.iso.org/standard/23281.html</uri>
121
113
  <uri type="obp">https://www.iso.org/obp/ui/#!iso:std:23281:en</uri>
122
114
  <uri type="rss">https://www.iso.org/contents/data/standard/02/32/23281.detail.rss</uri>
@@ -132,7 +124,6 @@ EOS
132
124
  </contributor>
133
125
  <edition>3</edition>
134
126
  <language>en</language>
135
- <language>fr</language>
136
127
  <script>Latn</script>
137
128
  <status>
138
129
  <stage>90</stage>
@@ -156,8 +147,6 @@ EOS
156
147
  <fetched>#{Date.today}</fetched>
157
148
  <title type="title-main" format="text/plain" language="en" script="Latn">Rubber latex – Sampling</title>
158
149
  <title type="main" format="text/plain" language="en" script="Latn">Rubber latex – Sampling</title>
159
- <title type="title-main" format="text/plain" language="fr" script="Latn">Latex de caoutchouc – Échantillonnage</title>
160
- <title type="main" format="text/plain" language="fr" script="Latn">Latex de caoutchouc – Échantillonnage</title>
161
150
  <uri type="src">https://www.iso.org/standard/23281.html</uri>
162
151
  <uri type="obp">https://www.iso.org/obp/ui/#!iso:std:23281:en</uri>
163
152
  <uri type="rss">https://www.iso.org/contents/data/standard/02/32/23281.detail.rss</uri>
@@ -176,7 +165,6 @@ EOS
176
165
  </contributor>
177
166
  <edition>3</edition>
178
167
  <language>en</language>
179
- <language>fr</language>
180
168
  <script>Latn</script>
181
169
  <status>
182
170
  <stage>90</stage>
@@ -219,17 +207,14 @@ EOS
219
207
  <title type="title-intro" format="text/plain" language="en" script="Latn">Rubber latex</title>
220
208
  <title type="title-main" format="text/plain" language="en" script="Latn">Sampling</title>
221
209
  <title type='main' format='text/plain' language='en' script='Latn'>Rubber latex - Sampling</title>
222
- <title type="title-intro" format="text/plain" language="fr" script="Latn">Latex de caoutchouc</title>
223
- <title type="title-main" format="text/plain" language="fr" script="Latn">Échantillonnage</title>
224
- <title type='main' format='text/plain' language='fr' script='Latn'>Latex de caoutchouc - Échantillonnage</title>
225
210
  <uri type="src">https://www.iso.org/standard/23281.html</uri>
226
211
  <uri type="obp">https://www.iso.org/obp/ui/#!iso:std:23281:en</uri>
227
212
  <uri type="rss">https://www.iso.org/contents/data/standard/02/32/23281.detail.rss</uri>
228
213
  <docidentifier type="ISO">ISO 123:2001</docidentifier>
229
- <docidentifier type='URN'>urn:iso:std:iso:123:stage-90.93:ed-3:en,fr</docidentifier>
214
+ <docidentifier type='URN'>urn:iso:std:iso:123:stage-90.93:ed-3:en</docidentifier>
230
215
  <docnumber>123</docnumber>
231
216
  <date type="published">
232
- <on>2001</on>
217
+ <on>2001-05</on>
233
218
  </date>
234
219
  <contributor>
235
220
  <role type="publisher"/>
@@ -241,8 +226,14 @@ EOS
241
226
  </contributor>
242
227
  <edition>3</edition>
243
228
  <language>en</language>
244
- <language>fr</language>
245
229
  <script>Latn</script>
230
+ <abstract format='text/plain' language='en' script='Latn'>
231
+ This International Standard specifies procedures for sampling natural rubber
232
+ latex concentrate and for sampling syntheticrubber latices and artificial
233
+ latices. It is also suitable for sampling rubber latex contained in drums,
234
+ tank cars ortanks. The procedures may also be used for sampling plastics
235
+ dispersions.
236
+ </abstract>
246
237
  <status>
247
238
  <stage>90</stage>
248
239
  <substage>93</substage>
@@ -342,7 +333,7 @@ EOS
342
333
  FileUtils.rm_rf File.expand_path("~/.iev/cache")
343
334
 
344
335
  # mock_isobib_get_123
345
- VCR.use_cassette "isobib_get_123_2001", :re_record_interval => 25200 do
336
+ VCR.use_cassette "isobib_get_123_2001" do
346
337
  Asciidoctor.convert(<<~"INPUT", backend: :standoc, header_footer: true)
347
338
  #{FLUSH_CACHE_ISOBIB_BLANK_HDR}
348
339
  [bibliography]
@@ -423,7 +414,7 @@ EOS
423
414
  it "activates global cache" do
424
415
  FileUtils.mv File.expand_path("~/.relaton/cache"), File.expand_path("~/.relaton-bib.pstore1"), force: true
425
416
  FileUtils.rm_rf "relaton/cache"
426
- VCR.use_cassette "isobib_get_123_2001", :re_record_interval => 25200 do
417
+ VCR.use_cassette "isobib_get_123_2001" do
427
418
  Asciidoctor.convert(<<~"INPUT", backend: :standoc, header_footer: true)
428
419
  #{CACHED_ISOBIB_BLANK_HDR}
429
420
  [bibliography]
@@ -543,7 +534,7 @@ EOS
543
534
  #)
544
535
 
545
536
  # mock_isobib_get_124
546
- VCR.use_cassette "isobib_get_124", :re_record_interval => 25200 do
537
+ VCR.use_cassette "isobib_get_124" do
547
538
  Asciidoctor.convert(<<~"INPUT", backend: :standoc, header_footer: true)
548
539
  #{CACHED_ISOBIB_BLANK_HDR}
549
540
  [bibliography]
@@ -582,7 +573,7 @@ EOS
582
573
  #)
583
574
 
584
575
  # mock_isobib_get_123_undated
585
- VCR.use_cassette "isobib_get_123", :re_record_interval => 25200 do
576
+ VCR.use_cassette "isobib_get_123" do
586
577
  Asciidoctor.convert(<<~"INPUT", backend: :standoc, header_footer: true)
587
578
  #{CACHED_ISOBIB_BLANK_HDR}
588
579
  [bibliography]
@@ -603,7 +594,7 @@ EOS
603
594
  end
604
595
 
605
596
  it "does not expire stale dated references" do
606
- VCR.use_cassette "isobib_get_123_2001", :re_record_interval => 25200 do
597
+ VCR.use_cassette "isobib_get_123_2001" do
607
598
  FileUtils.rm_rf File.expand_path("~/.relaton-bib.pstore1")
608
599
  FileUtils.mv File.expand_path("~/.relaton/cache"), File.expand_path("~/.relaton-bib.pstore1"), force: true
609
600
 
@@ -637,8 +628,8 @@ EOS
637
628
  end
638
629
 
639
630
  it "prioritises local over global cache values" 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
631
+ VCR.use_cassette "isobib_get_123_2001" do
632
+ VCR.use_cassette "isobib_get_124" do
642
633
  FileUtils.rm_rf File.expand_path("~/.relaton-bib.pstore1")
643
634
  FileUtils.mv File.expand_path("~/.relaton/cache"), File.expand_path("~/.relaton-bib.pstore1"), force: true
644
635
  FileUtils.rm_rf "relaton/cache"
@@ -689,19 +680,19 @@ EOS
689
680
  private
690
681
 
691
682
  def mock_isobib_get_123
692
- expect(RelatonIso::IsoBibliography).to receive(:get).with("ISO 123", "2001", {:title=>"<em>Standard</em>", :usrlbl=>nil}).and_return(RelatonIsoBib::XMLParser.from_xml(ISO_123_DATED))
683
+ expect(RelatonIso::IsoBibliography).to receive(:get).with("ISO 123", "2001", {:lang=>"en", :title=>"<em>Standard</em>", :usrlbl=>nil}).and_return(RelatonIsoBib::XMLParser.from_xml(ISO_123_DATED))
693
684
  end
694
685
 
695
686
  def mock_isobib_get_123_undated
696
- expect(RelatonIso::IsoBibliography).to receive(:get).with("ISO 123", nil, {:title=>"<em>Standard</em>", :usrlbl=>nil}).and_return(RelatonIsoBib::XMLParser.from_xml(ISO_123_UNDATED))
687
+ expect(RelatonIso::IsoBibliography).to receive(:get).with("ISO 123", nil, {:lang=>"en", :title=>"<em>Standard</em>", :usrlbl=>nil}).and_return(RelatonIsoBib::XMLParser.from_xml(ISO_123_UNDATED))
697
688
  end
698
689
 
699
690
  def mock_isobib_get_124
700
- expect(RelatonIso::IsoBibliography).to receive(:get).with("ISO 124", "2014", {:title=>"<em>Standard</em>", :usrlbl=>nil}).and_return(RelatonIsoBib::XMLParser.from_xml(ISO_124_DATED))
691
+ expect(RelatonIso::IsoBibliography).to receive(:get).with("ISO 124", "2014", {:lang=>"en", :title=>"<em>Standard</em>", :usrlbl=>nil}).and_return(RelatonIsoBib::XMLParser.from_xml(ISO_124_DATED))
701
692
  end
702
693
 
703
694
  def mock_ietfbib_get_123
704
- expect(RelatonIetf::IetfBibliography).to receive(:get).with("RFC 123", nil, {:title=>"<em>Standard</em>", :usrlbl=>nil}).and_return(RelatonIsoBib::XMLParser.from_xml(IETF_123_SHORT))
695
+ expect(RelatonIetf::IetfBibliography).to receive(:get).with("RFC 123", nil, {:lang=>"en", :title=>"<em>Standard</em>", :usrlbl=>nil}).and_return(RelatonIsoBib::XMLParser.from_xml(IETF_123_SHORT))
705
696
  end
706
697
 
707
698
  end
@@ -111,6 +111,9 @@ RSpec.describe Asciidoctor::Standoc do
111
111
  +
112
112
  Note 3.
113
113
 
114
+ [%key]
115
+ a:: b
116
+
114
117
  INPUT
115
118
  expect(xmlpp(strip_guid(output))).to be_equivalent_to xmlpp(<<~"OUTPUT")
116
119
  #{BLANK_HDR}
@@ -174,7 +177,13 @@ RSpec.describe Asciidoctor::Standoc do
174
177
  </li>
175
178
  </ol>
176
179
  </li>
177
- </ol></sections>
180
+ </ol><dl id='_' key='true'>
181
+ <dt>a</dt>
182
+ <dd>
183
+ <p id='_'>b</p>
184
+ </dd>
185
+ </dl>
186
+ </sections>
178
187
  </standard-document>
179
188
  OUTPUT
180
189
  end
@@ -1,6 +1,6 @@
1
1
  require "spec_helper"
2
2
 
3
- RSpec.describe Asciidoctor::Standoc::Json2TextPreprocessor do
3
+ RSpec.describe 'Json2Text macros' do
4
4
  it_behaves_like "structured data 2 text preprocessor" do
5
5
  let(:extention) { "json" }
6
6
  def transform_to_type(data)
@@ -0,0 +1,80 @@
1
+ require "spec_helper"
2
+
3
+ RSpec.describe 'Lutaml macros' do
4
+ let(:example_file) { fixtures_path("test.exp") }
5
+
6
+ context "Array of hashes" do
7
+ let(:input) do
8
+ <<~TEXT
9
+ = Document title
10
+ Author
11
+ :docfile: test.adoc
12
+ :nodoc:
13
+ :novalid:
14
+ :no-isobib:
15
+ :imagesdir: spec/assets
16
+
17
+ [lutaml,#{example_file},my_context]
18
+ ----
19
+
20
+ {% for schema in my_context.schemas %}
21
+ == {{schema.id}}
22
+
23
+ {% for entity in schema.entities %}
24
+ === {{entity.id}}
25
+ supertypes -> {{entity.supertypes.id}}
26
+ explicit -> {{entity.explicit.first.id}}
27
+
28
+ {% endfor %}
29
+
30
+ {% endfor %}
31
+ ----
32
+ TEXT
33
+ end
34
+ let(:output) do
35
+ <<~TEXT
36
+ #{BLANK_METANORMA_HDR}
37
+ <sections>
38
+ <clause id="_" inline-header="false" obligation="normative"><title>annotated_3d_model_data_quality_criteria_schema</title>
39
+ <clause id="_" inline-header="false" obligation="normative">
40
+ <title>a3m_data_quality_criteria_representation</title>
41
+ <p id="_">supertypes →
42
+ explicit → </p>
43
+ </clause>
44
+ <clause id="_" inline-header="false" obligation="normative">
45
+ <title>a3m_data_quality_criterion</title>
46
+ <p id="_">supertypes →
47
+ explicit → </p>
48
+ </clause>
49
+ <clause id="_" inline-header="false" obligation="normative">
50
+ <title>a3m_data_quality_criterion_specific_applied_value</title>
51
+ <p id="_">supertypes →
52
+ explicit → </p>
53
+ </clause>
54
+ <clause id="_" inline-header="false" obligation="normative">
55
+ <title>a3m_data_quality_target_accuracy_association</title>
56
+ <p id="_">supertypes →
57
+ explicit → </p>
58
+ </clause>
59
+ <clause id="_" inline-header="false" obligation="normative">
60
+ <title>a3m_detailed_report_request</title>
61
+ <p id="_">supertypes →
62
+ explicit → </p>
63
+ </clause>
64
+ <clause id="_" inline-header="false" obligation="normative">
65
+ <title>a3m_summary_report_request_with_representative_value</title>
66
+ <p id="_">supertypes →
67
+ explicit → </p>
68
+ </clause></clause>
69
+ </sections>
70
+ </standard-document>
71
+ </body></html>
72
+ TEXT
73
+ end
74
+
75
+ it "correctly renders input" do
76
+ expect(xml_string_conent(metanorma_process(input)))
77
+ .to(be_equivalent_to(output))
78
+ end
79
+ end
80
+ end
@@ -0,0 +1,307 @@
1
+ require "spec_helper"
2
+
3
+ RSpec.describe Asciidoctor::Standoc do
4
+ it "processes the PlantUML macro" do
5
+ expect(xmlpp(strip_guid(Asciidoctor.convert(<<~"INPUT", backend: :standoc, header_footer: true)).gsub(%r{plantuml/plantuml[^./]+\.}, "plantuml/_."))).to be_equivalent_to xmlpp(<<~"OUTPUT")
6
+ #{ASCIIDOC_BLANK_HDR}
7
+
8
+ [plantuml]
9
+ ....
10
+ @startuml
11
+ Alice -> Bob: Authentication Request
12
+ Bob --> Alice: Authentication Response
13
+
14
+ Alice -> Bob: Another authentication Request
15
+ Alice <-- Bob: another authentication Response
16
+ @enduml
17
+ ....
18
+
19
+ [plantuml]
20
+ ....
21
+ Alice -> Bob: Authentication Request
22
+ Bob --> Alice: Authentication Response
23
+
24
+ Alice -> Bob: Another authentication Request
25
+ Alice <-- Bob: another authentication Response
26
+ ....
27
+
28
+ [plantuml]
29
+ ....
30
+ @startuml filename
31
+ Alice -> Bob: Authentication Request
32
+ Bob --> Alice: Authentication Response
33
+
34
+ Alice -> Bob: Another authentication Request
35
+ Alice <-- Bob: another authentication Response
36
+ @enduml
37
+ ....
38
+ INPUT
39
+ #{BLANK_HDR}
40
+ <sections><figure id="_">
41
+ <image src="plantuml/_.png" id="_" mimetype="image/png" height="auto" width="auto"/>
42
+ </figure>
43
+ <figure id="_">
44
+ <image src="plantuml/_.png" id="_" mimetype="image/png" height="auto" width="auto"/>
45
+ </figure>
46
+ <figure id="_">
47
+ <image src="plantuml/filename.png" id="_" mimetype="image/png" height="auto" width="auto"/>
48
+ </figure>
49
+ </sections>
50
+
51
+ </standard-document>
52
+ OUTPUT
53
+ end
54
+
55
+ it "processes the PlantUML macro with imagesdir" do
56
+ expect(xmlpp(strip_guid(Asciidoctor.convert(<<~"INPUT", backend: :standoc, header_footer: true)).gsub(%r{spec/assets/[^./]+\.}, "spec/assets/_."))).to be_equivalent_to xmlpp(<<~"OUTPUT")
57
+ = Document title
58
+ Author
59
+ :docfile: test.adoc
60
+ :nodoc:
61
+ :novalid:
62
+ :no-isobib:
63
+ :imagesdir: spec/assets
64
+
65
+ [plantuml]
66
+ ....
67
+ @startuml
68
+ Alice -> Bob: Authentication Request
69
+ Bob --> Alice: Authentication Response
70
+
71
+ Alice -> Bob: Another authentication Request
72
+ Alice <-- Bob: another authentication Response
73
+ @enduml
74
+ ....
75
+ INPUT
76
+ #{BLANK_HDR}
77
+ <sections>
78
+ <figure id="_">
79
+ <image src="spec/assets/_.png" id="_" mimetype="image/png" height="auto" width="auto"/>
80
+ </figure>
81
+ </sections>
82
+ </standard-document>
83
+ OUTPUT
84
+ end
85
+
86
+ context 'when lutaml_diagram' do
87
+ let(:input) do
88
+ <<~"OUTPUT"
89
+ = Document title
90
+ Author
91
+ :docfile: test.adoc
92
+ :nodoc:
93
+ :novalid:
94
+ :no-isobib:
95
+ :imagesdir: spec/assets
96
+
97
+ [lutaml_diagram]
98
+ ....
99
+ diagram MyView {
100
+ fontname "Arial"
101
+ title "my diagram"
102
+ class Foo {}
103
+ }
104
+ ....
105
+ OUTPUT
106
+ end
107
+ let(:output) do
108
+ <<~"OUTPUT"
109
+ #{BLANK_HDR}
110
+ <sections>
111
+ <figure id="_">
112
+ <image src="spec/assets/_.png" id="_" mimetype="image/png" height="auto" width="auto"/>
113
+ </figure>
114
+ </sections>
115
+ </standard-document>
116
+ OUTPUT
117
+ end
118
+
119
+ it "processes the lutaml_diagram" do
120
+ expect(
121
+ xmlpp(
122
+ strip_guid(Asciidoctor.convert(input, backend: :standoc, header_footer: true))
123
+ .gsub(%r{".+spec\/assets\/lutaml\/[^.\/]+\.}, %q("spec/assets/_.))))
124
+ .to(be_equivalent_to xmlpp(output))
125
+ end
126
+ end
127
+
128
+ context 'when lutaml_uml_attributes_table' do
129
+ let(:example_file) { fixtures_path("diagram_definitions.lutaml") }
130
+ let(:input) do
131
+ <<~"OUTPUT"
132
+ = Document title
133
+ Author
134
+ :docfile: test.adoc
135
+ :nodoc:
136
+ :novalid:
137
+ :no-isobib:
138
+ :imagesdir: spec/assets
139
+
140
+ [lutaml_uml_attributes_table,#{example_file},AttributeProfile]
141
+ OUTPUT
142
+ end
143
+ let(:output) do
144
+ <<~"OUTPUT"
145
+ #{BLANK_HDR}
146
+ <sections>
147
+ <clause id='_' inline-header='false' obligation='normative'>
148
+ <title>AttributeProfile</title>
149
+ <table id='_'>
150
+ <name>AttributeProfile attributes</name>
151
+ <thead>
152
+ <tr>
153
+ <th valign='top' align='left'>Name</th>
154
+ <th valign='top' align='left'>Definition</th>
155
+ <th valign='top' align='left'>Mandatory/ Optional/ Conditional</th>
156
+ <th valign='top' align='left'>Max Occur</th>
157
+ <th valign='top' align='left'>Data Type</th>
158
+ </tr>
159
+ </thead>
160
+ <tbody>
161
+ <tr>
162
+ <td valign='top' align='left'>addressClassProfile</td>
163
+ <td valign='top' align='left'>TODO: enum ‘s definition</td>
164
+ <td valign='top' align='left'>O</td>
165
+ <td valign='top' align='left'>1</td>
166
+ <td valign='top' align='left'>
167
+ <tt>CharacterString</tt>
168
+ </td>
169
+ </tr>
170
+ <tr>
171
+ <td valign='top' align='left'>imlicistAttributeProfile</td>
172
+ <td valign='top' align='left'>this is attribute definition with multiply lines</td>
173
+ <td valign='top' align='left'>O</td>
174
+ <td valign='top' align='left'>1</td>
175
+ <td valign='top' align='left'>
176
+ <tt>CharacterString</tt>
177
+ </td>
178
+ </tr>
179
+ </tbody>
180
+ </table>
181
+ </clause>
182
+ </sections>
183
+ </standard-document>
184
+ OUTPUT
185
+ end
186
+
187
+ it "processes the lutaml_uml_attributes_table macro" do
188
+ expect(
189
+ xmlpp(
190
+ strip_guid(Asciidoctor.convert(input, backend: :standoc, header_footer: true))))
191
+ .to(be_equivalent_to(xmlpp(output)))
192
+ end
193
+ end
194
+
195
+ it "processes the PlantUML macro with PlantUML disabled" do
196
+ mock_plantuml_disabled
197
+ expect { Asciidoctor.convert(<<~"INPUT", backend: :standoc, header_footer: true) }.to output(%r{PlantUML not installed}).to_stderr
198
+ #{ASCIIDOC_BLANK_HDR}
199
+
200
+ [plantuml]
201
+ ....
202
+ @startuml
203
+ Alice -> Bob: Authentication Request
204
+ Bob --> Alice: Authentication Response
205
+
206
+ Alice -> Bob: Another authentication Request
207
+ Alice <-- Bob: another authentication Response
208
+ @enduml
209
+ ....
210
+ INPUT
211
+
212
+ mock_plantuml_disabled
213
+ expect(xmlpp(strip_guid(Asciidoctor.convert(<<~"INPUT", backend: :standoc, header_footer: true)))).to be_equivalent_to xmlpp(<<~"OUTPUT")
214
+ #{ASCIIDOC_BLANK_HDR}
215
+
216
+ [plantuml]
217
+ ....
218
+ @startuml
219
+ Alice -> Bob: Authentication Request
220
+ Bob --> Alice: Authentication Response
221
+
222
+ Alice -> Bob: Another authentication Request
223
+ Alice <-- Bob: another authentication Response
224
+ @enduml
225
+ ....
226
+ INPUT
227
+ #{BLANK_HDR}
228
+ <sections>
229
+ <sourcecode id="_" lang="plantuml">@startuml
230
+ Alice -&gt; Bob: Authentication Request
231
+ Bob --&gt; Alice: Authentication Response
232
+
233
+ Alice -&gt; Bob: Another authentication Request
234
+ Alice &lt;-- Bob: another authentication Response
235
+ @enduml</sourcecode>
236
+ </sections>
237
+ </standard-document>
238
+ OUTPUT
239
+ end
240
+
241
+ it "processes the PlantUML macro with localdir unwritable" do
242
+ mock_localdir_unwritable
243
+ expect { Asciidoctor.convert(<<~"INPUT", backend: :standoc, header_footer: true) }.to output(%r{not writable for PlantUML}).to_stderr
244
+ #{ASCIIDOC_BLANK_HDR}
245
+
246
+ [plantuml]
247
+ ....
248
+ @startuml
249
+ Alice -> Bob: Authentication Request
250
+ Bob --> Alice: Authentication Response
251
+
252
+ Alice -> Bob: Another authentication Request
253
+ Alice <-- Bob: another authentication Response
254
+ @enduml
255
+ ....
256
+ INPUT
257
+
258
+ mock_localdir_unwritable
259
+ expect(xmlpp(strip_guid(Asciidoctor.convert(<<~"INPUT", backend: :standoc, header_footer: true)))).to be_equivalent_to xmlpp(<<~"OUTPUT")
260
+ #{ASCIIDOC_BLANK_HDR}
261
+
262
+ [plantuml]
263
+ ....
264
+ @startuml
265
+ Alice -> Bob: Authentication Request
266
+ Bob --> Alice: Authentication Response
267
+
268
+ Alice -> Bob: Another authentication Request
269
+ Alice <-- Bob: another authentication Response
270
+ @enduml
271
+ ....
272
+ INPUT
273
+ #{BLANK_HDR}
274
+ <sections>
275
+ <sourcecode id="_" lang="plantuml">@startuml
276
+ Alice -&gt; Bob: Authentication Request
277
+ Bob --&gt; Alice: Authentication Response
278
+
279
+ Alice -&gt; Bob: Another authentication Request
280
+ Alice &lt;-- Bob: another authentication Response
281
+ @enduml</sourcecode>
282
+ </sections>
283
+ </standard-document>
284
+ OUTPUT
285
+ end
286
+
287
+ private
288
+
289
+ def mock_plantuml_disabled
290
+ expect(Asciidoctor::Standoc::PlantUMLBlockMacroBackend).to receive(:plantuml_installed?) do
291
+ raise "PlantUML not installed"
292
+ false
293
+ end
294
+ end
295
+
296
+ def mock_localdir_unwritable
297
+ expect(Asciidoctor::Standoc::Utils).to receive(:localdir) do
298
+ "/"
299
+ end.exactly(2).times
300
+ end
301
+
302
+ def mock_localdir_unwritable
303
+ expect(File).to receive(:writable?) do
304
+ false
305
+ end
306
+ end
307
+ end