metanorma-iso 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (103) hide show
  1. checksums.yaml +7 -0
  2. data/.gitattributes +4 -0
  3. data/.gitignore +11 -0
  4. data/.hound.yml +3 -0
  5. data/.oss-guides.rubocop.yml +1077 -0
  6. data/.rubocop.ribose.yml +66 -0
  7. data/.rubocop.tb.yml +650 -0
  8. data/.rubocop.yml +15 -0
  9. data/.travis.yml +21 -0
  10. data/CODE_OF_CONDUCT.md +46 -0
  11. data/Gemfile +7 -0
  12. data/LICENSE +25 -0
  13. data/Makefile +39 -0
  14. data/README.adoc +882 -0
  15. data/Rakefile +6 -0
  16. data/asciidoctor-iso.gemspec.old +50 -0
  17. data/bin/rspec +18 -0
  18. data/docs/customisation.adoc +186 -0
  19. data/docs/guidance.adoc +436 -0
  20. data/docs/htmloutput.adoc +115 -0
  21. data/docs/quickstart.adoc +375 -0
  22. data/lib/asciidoctor-iso.rb +11 -0
  23. data/lib/asciidoctor/iso/base.rb +48 -0
  24. data/lib/asciidoctor/iso/biblio.rng +836 -0
  25. data/lib/asciidoctor/iso/cleanup.rb +39 -0
  26. data/lib/asciidoctor/iso/converter.rb +19 -0
  27. data/lib/asciidoctor/iso/front.rb +131 -0
  28. data/lib/asciidoctor/iso/isodoc.rng +1059 -0
  29. data/lib/asciidoctor/iso/isostandard.rnc +176 -0
  30. data/lib/asciidoctor/iso/isostandard.rng +1001 -0
  31. data/lib/asciidoctor/iso/section.rb +72 -0
  32. data/lib/asciidoctor/iso/validate.rb +190 -0
  33. data/lib/asciidoctor/iso/validate_requirements.rb +105 -0
  34. data/lib/asciidoctor/iso/validate_section.rb +214 -0
  35. data/lib/asciidoctor/iso/validate_style.rb +134 -0
  36. data/lib/asciidoctor/iso/version.rb +5 -0
  37. data/lib/isodoc/iso/html/header.html +206 -0
  38. data/lib/isodoc/iso/html/html_iso_intro.html +34 -0
  39. data/lib/isodoc/iso/html/html_iso_titlepage.html +34 -0
  40. data/lib/isodoc/iso/html/htmlstyle.scss +46 -0
  41. data/lib/isodoc/iso/html/isodoc.scss +696 -0
  42. data/lib/isodoc/iso/html/scripts.html +174 -0
  43. data/lib/isodoc/iso/html/style-human.scss +1277 -0
  44. data/lib/isodoc/iso/html/style-iso.scss +1257 -0
  45. data/lib/isodoc/iso/html/word_iso_intro.html +72 -0
  46. data/lib/isodoc/iso/html/word_iso_titlepage.html +62 -0
  47. data/lib/isodoc/iso/html/wordstyle.scss +1175 -0
  48. data/lib/isodoc/iso/html_convert.rb +118 -0
  49. data/lib/isodoc/iso/metadata.rb +107 -0
  50. data/lib/isodoc/iso/word_convert.rb +141 -0
  51. data/lib/metanorma/iso.rb +7 -0
  52. data/lib/metanorma/iso/processor.rb +44 -0
  53. data/spec/asciidoctor-iso/base_spec.rb +350 -0
  54. data/spec/asciidoctor-iso/blocks_spec.rb +469 -0
  55. data/spec/asciidoctor-iso/cleanup_spec.rb +765 -0
  56. data/spec/asciidoctor-iso/inline_spec.rb +162 -0
  57. data/spec/asciidoctor-iso/isobib_cache_spec.rb +332 -0
  58. data/spec/asciidoctor-iso/lists_spec.rb +190 -0
  59. data/spec/asciidoctor-iso/macros_spec.rb +111 -0
  60. data/spec/asciidoctor-iso/refs_spec.rb +643 -0
  61. data/spec/asciidoctor-iso/section_spec.rb +334 -0
  62. data/spec/asciidoctor-iso/table_spec.rb +307 -0
  63. data/spec/asciidoctor-iso/validate_spec.rb +907 -0
  64. data/spec/assets/header.html +7 -0
  65. data/spec/assets/html.css +2 -0
  66. data/spec/assets/htmlcover.html +4 -0
  67. data/spec/assets/htmlintro.html +5 -0
  68. data/spec/assets/i18n.yaml +2 -0
  69. data/spec/assets/iso.doc +1093 -0
  70. data/spec/assets/iso.headless.html +33 -0
  71. data/spec/assets/iso.html +278 -0
  72. data/spec/assets/iso.xml +8 -0
  73. data/spec/assets/rice_image1.png +0 -0
  74. data/spec/assets/scripts.html +3 -0
  75. data/spec/assets/std.css +2 -0
  76. data/spec/assets/word.css +2 -0
  77. data/spec/assets/wordcover.html +3 -0
  78. data/spec/assets/wordintro.html +4 -0
  79. data/spec/examples/103_01_02.html +247 -0
  80. data/spec/examples/english.yaml +69 -0
  81. data/spec/examples/iso_123_.xml +45 -0
  82. data/spec/examples/iso_123_all_parts.xml +45 -0
  83. data/spec/examples/iso_123_no_year_note.xml +46 -0
  84. data/spec/examples/iso_124_.xml +41 -0
  85. data/spec/examples/iso_216_.xml +47 -0
  86. data/spec/examples/iso_iec_12382_.xml +48 -0
  87. data/spec/examples/rice.adoc +715 -0
  88. data/spec/examples/rice.preview.html +1877 -0
  89. data/spec/examples/rice.sh +4 -0
  90. data/spec/examples/rice_images/rice_image1.png +0 -0
  91. data/spec/examples/rice_images/rice_image2.png +0 -0
  92. data/spec/examples/rice_images/rice_image3_1.png +0 -0
  93. data/spec/examples/rice_images/rice_image3_2.png +0 -0
  94. data/spec/examples/rice_images/rice_image3_3.png +0 -0
  95. data/spec/isodoc/i18n_spec.rb +642 -0
  96. data/spec/isodoc/iso_spec.rb +168 -0
  97. data/spec/isodoc/metadata_spec.rb +152 -0
  98. data/spec/isodoc/postproc_spec.rb +405 -0
  99. data/spec/isodoc/section_spec.rb +522 -0
  100. data/spec/isodoc/xref_spec.rb +1337 -0
  101. data/spec/metanorma/processor_spec.rb +70 -0
  102. data/spec/spec_helper.rb +227 -0
  103. metadata +402 -0
@@ -0,0 +1,162 @@
1
+ require "spec_helper"
2
+
3
+ RSpec.describe Asciidoctor::ISO do
4
+ it "processes inline_quoted formatting" do
5
+ expect(strip_guid(Asciidoctor.convert(<<~"INPUT", backend: :iso, header_footer: true))).to be_equivalent_to <<~"OUTPUT"
6
+ #{ASCIIDOC_BLANK_HDR}
7
+ _emphasis_
8
+ *strong*
9
+ `monospace`
10
+ "double quote"
11
+ 'single quote'
12
+ super^script^
13
+ sub~script~
14
+ stem:[a_90]
15
+ stem:[<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">&#x391;</mml:mi> </mml:mrow> </mml:mrow> </mml:msub> </mml:math>]
16
+ [alt]#alt#
17
+ [deprecated]#deprecated#
18
+ [domain]#domain#
19
+ [strike]#strike#
20
+ [smallcap]#smallcap#
21
+ INPUT
22
+ #{BLANK_HDR}
23
+ <sections>
24
+ <em>emphasis</em>
25
+ <strong>strong</strong>
26
+ <tt>monospace</tt>
27
+ "double quote"
28
+ 'single quote'
29
+ super<sup>script</sup>
30
+ sub<sub>script</sub>
31
+ <stem type="AsciiMath">a_90</stem>
32
+ <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>
33
+ <admitted>alt</admitted>
34
+ <deprecates>deprecated</deprecates>
35
+ <domain>domain</domain>
36
+ <strike>strike</strike>
37
+ <smallcap>smallcap</smallcap>
38
+ </sections>
39
+ </iso-standard>
40
+ OUTPUT
41
+ end
42
+
43
+ it "processes breaks" do
44
+ expect(strip_guid(Asciidoctor.convert(<<~"INPUT", backend: :iso, header_footer: true))).to be_equivalent_to <<~"OUTPUT"
45
+ #{ASCIIDOC_BLANK_HDR}
46
+ Line break +
47
+ line break
48
+
49
+ '''
50
+
51
+ <<<
52
+ INPUT
53
+ #{BLANK_HDR}
54
+ <sections><p id="_">Line break<br/>
55
+ line break</p>
56
+ <hr/>
57
+ <pagebreak/></sections>
58
+ </iso-standard>
59
+ OUTPUT
60
+ end
61
+
62
+ it "processes links" do
63
+ expect(strip_guid(Asciidoctor.convert(<<~"INPUT", backend: :iso, header_footer: true))).to be_equivalent_to <<~"OUTPUT"
64
+ #{ASCIIDOC_BLANK_HDR}
65
+ mailto:fred@example.com
66
+ http://example.com[]
67
+ http://example.com[Link]
68
+ INPUT
69
+ #{BLANK_HDR}
70
+ <sections>
71
+ <p id="_">mailto:fred@example.com
72
+ <link target="http://example.com"/>
73
+ <link target="http://example.com">Link</link></p>
74
+ </sections>
75
+ </iso-standard>
76
+ OUTPUT
77
+ end
78
+
79
+ it "processes bookmarks" do
80
+ expect(strip_guid(Asciidoctor.convert(<<~"INPUT", backend: :iso, header_footer: true))).to be_equivalent_to <<~"OUTPUT"
81
+ #{ASCIIDOC_BLANK_HDR}
82
+ Text [[bookmark]] Text
83
+ INPUT
84
+ #{BLANK_HDR}
85
+ <sections>
86
+ <p id="_">Text <bookmark id="bookmark"/> Text</p>
87
+ </sections>
88
+ </iso-standard>
89
+ OUTPUT
90
+ end
91
+
92
+ it "processes crossreferences" do
93
+ expect(strip_guid(Asciidoctor.convert(<<~"INPUT", backend: :iso, header_footer: true))).to be_equivalent_to <<~"OUTPUT"
94
+ #{ASCIIDOC_BLANK_HDR}
95
+ [[reference]]
96
+ == Section
97
+
98
+ Inline Reference to <<reference>>
99
+ Footnoted Reference to <<reference,fn>>
100
+ Inline Reference with Text to <<reference,text>>
101
+ Footnoted Reference with Text to <<reference,fn: text>>
102
+ INPUT
103
+ #{BLANK_HDR}
104
+ <sections>
105
+ <clause id="reference" inline-header="false" obligation="normative">
106
+ <title>Section</title>
107
+ <p id="_">Inline Reference to <xref target="reference"/>
108
+ Footnoted Reference to <xref target="reference"/>
109
+ Inline Reference with Text to <xref target="reference">text</xref>
110
+ Footnoted Reference with Text to <xref target="reference">text</xref></p>
111
+ </clause>
112
+ </sections>
113
+ </iso-standard>
114
+ OUTPUT
115
+ end
116
+
117
+ it "processes bibliographic anchors" do
118
+ expect(strip_guid(Asciidoctor.convert(<<~"INPUT", backend: :iso, header_footer: true))).to be_equivalent_to <<~"OUTPUT"
119
+ #{ASCIIDOC_BLANK_HDR}
120
+ [bibliography]
121
+ == Normative References
122
+
123
+ * [[[ISO712,x]]] Reference
124
+ * [[[ISO713]]] Reference
125
+
126
+ INPUT
127
+ #{BLANK_HDR}
128
+ <sections>
129
+
130
+ </sections><bibliography><references id="_" obligation="informative">
131
+ <title>Normative References</title>
132
+ <bibitem id="ISO712">
133
+ <formattedref format="application/x-isodoc+xml">Reference</formattedref>
134
+ <docidentifier>x</docidentifier>
135
+ </bibitem>
136
+ <bibitem id="ISO713">
137
+ <formattedref format="application/x-isodoc+xml">Reference</formattedref>
138
+ <docidentifier>ISO713</docidentifier>
139
+ </bibitem>
140
+ </references>
141
+ </bibliography>
142
+ </iso-standard>
143
+ OUTPUT
144
+ end
145
+
146
+ it "processes footnotes" do
147
+ expect(strip_guid(Asciidoctor.convert(<<~"INPUT", backend: :iso, header_footer: true))).to be_equivalent_to <<~"OUTPUT"
148
+ #{ASCIIDOC_BLANK_HDR}
149
+ Hello!footnote:[Footnote text]
150
+ INPUT
151
+ #{BLANK_HDR}
152
+ <sections>
153
+ <p id="_">Hello!<fn reference="1">
154
+ <p id="_">Footnote text</p>
155
+ </fn></p>
156
+ </sections>
157
+ </iso-standard>
158
+ OUTPUT
159
+ end
160
+
161
+
162
+ end
@@ -0,0 +1,332 @@
1
+ require "spec_helper"
2
+ require "isobib"
3
+
4
+ RSpec.describe Asciidoctor::ISO do
5
+
6
+ ISO_123_SHORT = <<~EOS
7
+ <bibitem type="international-standard" id="ISO123">
8
+ <title format="text/plain" language="en" script="Latn">Rubber latex -- Sampling</title>
9
+ <docidentifier>ISO 123</docidentifier>
10
+ <contributor> <role type="publisher"/> <organization> <name>International Organization for Standardization</name> <abbreviation>ISO</abbreviation> <uri>www.iso.org</uri> </organization> </contributor>
11
+ <status>Published</status>
12
+ </bibitem>
13
+ EOS
14
+
15
+ ISO_124_SHORT = <<~EOS
16
+ <bibitem type="international-standard" id="ISO124">
17
+ <title format="text/plain" language="en" script="Latn">Latex, rubber -- Determination of total solids content</title>
18
+ <docidentifier>ISO 124</docidentifier>
19
+ <contributor> <role type="publisher"/> <organization> <name>International Organization for Standardization</name> <abbreviation>ISO</abbreviation> <uri>www.iso.org</uri> </organization> </contributor>
20
+ <status>Published</status>
21
+ </bibitem>
22
+ EOS
23
+
24
+ ISO_124_SHORT_ALT = <<~EOS
25
+ <bibitem type="international-standard" id="ISO124">
26
+ <title format="text/plain" language="en" script="Latn">Latex, rubber -- Replacement</title>
27
+ <docidentifier>ISO 124</docidentifier>
28
+ <contributor> <role type="publisher"/> <organization> <name>International Organization for Standardization</name> <abbreviation>ISO</abbreviation> <uri>www.iso.org</uri> </organization> </contributor>
29
+ <status>Published</status>
30
+ </bibitem>
31
+ EOS
32
+
33
+ ISOBIB_123_DATED = <<~EOS
34
+ <bibitem type="international-standard" id="ISO123"> <title format="text/plain" language="en" script="Latn">Rubber latex -- Sampling</title> <title format="text/plain" language="fr" script="Latn">Latex de caoutchouc -- ?chantillonnage</title> <uri type="src">https://www.iso.org/standard/23281.html</uri> <uri type="obp">https://www.iso.org/obp/ui/#!iso:std:23281:en</uri> <uri type="rss">https://www.iso.org/contents/data/standard/02/32/23281.detail.rss</uri> <docidentifier>ISO 123</docidentifier> <date type="published"> <on>2001</on> </date> <contributor> <role type="publisher"/> <organization> <name>International Organization for Standardization</name> <abbreviation>ISO</abbreviation> <uri>www.iso.org</uri> </organization> </contributor> <edition>3</edition> <language>en</language> <language>fr</language> <script>Latn</script> <status>Published</status> <copyright> <from>2001</from> <owner> <organization> <name>ISO</name> </organization> </owner> </copyright> <relation type="obsoletes"> <bibitem> <formattedref>ISO 123:1985</formattedref> </bibitem> </relation> <relation type="updates"> <bibitem> <formattedref>ISO 123:2001</formattedref> </bibitem> </relation></bibitem>
35
+ EOS
36
+
37
+ ISOBIB_123_UNDATED = <<~EOS
38
+ <bibitem type="international-standard" id="ISO123"> <title format="text/plain" language="en" script="Latn">Rubber latex -- Sampling</title> <title format="text/plain" language="fr" script="Latn">Latex de caoutchouc -- ?chantillonnage</title> <uri type="src">https://www.iso.org/standard/23281.html</uri> <uri type="obp">https://www.iso.org/obp/ui/#!iso:std:23281:en</uri> <uri type="rss">https://www.iso.org/contents/data/standard/02/32/23281.detail.rss</uri> <docidentifier>ISO 123</docidentifier> <date type="published"> <on>2001</on> </date> <contributor> <role type="publisher"/> <organization> <name>International Organization for Standardization</name> <abbreviation>ISO</abbreviation> <uri>www.iso.org</uri> </organization> </contributor> <edition>3</edition> <language>en</language> <language>fr</language> <script>Latn</script> <status>Published</status> <copyright> <from>2001</from> <owner> <organization> <name>ISO</name> </organization> </owner> </copyright> <relation type="obsoletes"> <bibitem> <formattedref>ISO 123:1985</formattedref> </bibitem> </relation> <relation type="updates"> <bibitem> <formattedref>ISO 123:2001</formattedref> </bibitem> </relation></bibitem>
39
+ EOS
40
+
41
+
42
+ ISOBIB_124_DATED = <<~EOS
43
+ <bibitem type="international-standard" id="ISO124"> <title format="text/plain" language="en" script="Latn">Latex, rubber -- Determination of total solids content</title> <title format="text/plain" language="fr" script="Latn">Latex de caoutchouc -- Détermination des matières solides totales</title> <uri type="src">https://www.iso.org/standard/61884.html</uri> <uri type="obp">https://www.iso.org/obp/ui/#!iso:std:61884:en</uri> <uri type="rss">https://www.iso.org/contents/data/standard/06/18/61884.detail.rss</uri> <docidentifier>ISO 124</docidentifier> <date type="published"> <on>2014</on> </date> <contributor> <role type="publisher"/> <organization> <name>International Organization for Standardization</name> <abbreviation>ISO</abbreviation> <uri>www.iso.org</uri> </organization> </contributor> <edition>7</edition> <language>en</language> <language>fr</language> <script>Latn</script> <abstract format="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> <abstract format="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> <status>Published</status> <copyright> <from>2014</from> <owner> <organization> <name>ISO</name> </organization> </owner> </copyright> <relation type="obsoletes"> <bibitem> <formattedref>ISO 124:2011</formattedref> </bibitem> </relation></bibitem>
44
+ EOS
45
+
46
+ it "does not activate biblio caches if isobib disabled" do
47
+ system "mv ~/.relaton-bib.pstore ~/.relaton-bib.pstore1"
48
+ system "mv ~/.iev.pstore ~/.iev.pstore1"
49
+ system "rm -f test.relaton.pstore"
50
+ system "rm -f test.iev.pstore"
51
+ Asciidoctor.convert(<<~"INPUT", backend: :iso, header_footer: true)
52
+ #{ASCIIDOC_BLANK_HDR}
53
+ [bibliography]
54
+ == Normative References
55
+
56
+ * [[[iso123,ISO 123:2001]]] _Standard_
57
+ INPUT
58
+ expect(File.exist?("#{Dir.home}/.relaton-bib.pstore")).to be false
59
+ expect(File.exist?("#{Dir.home}/.iev.pstore")).to be false
60
+ expect(File.exist?("test.relaton.pstore")).to be false
61
+ expect(File.exist?("test.iev.pstore")).to be false
62
+
63
+ system "rm ~/.relaton-bib.pstore"
64
+ system "rm ~/.iev.pstore"
65
+ system "mv ~/.relaton-bib.pstore1 ~/.relaton-bib.pstore"
66
+ system "mv ~/.iev.pstore1 ~/.iev.pstore"
67
+ end
68
+
69
+ it "does not activate biblio caches if isobib caching disabled" do
70
+ system "mv ~/.relaton-bib.pstore ~/.relaton-bib.pstore1"
71
+ system "mv ~/.iev.pstore ~/.iev.pstore1"
72
+ system "rm -f test.relaton.pstore"
73
+ system "rm -f test.iev.pstore"
74
+ mock_isobib_get_123
75
+ Asciidoctor.convert(<<~"INPUT", backend: :iso, header_footer: true)
76
+ #{ISOBIB_BLANK_HDR}
77
+ [bibliography]
78
+ == Normative References
79
+
80
+ * [[[iso123,ISO 123:2001]]] _Standard_
81
+ INPUT
82
+ expect(File.exist?("#{Dir.home}/.relaton-bib.pstore")).to be false
83
+ expect(File.exist?("#{Dir.home}/.iev.pstore")).to be false
84
+ expect(File.exist?("test.relaton.pstore")).to be false
85
+ expect(File.exist?("test.iev.pstore")).to be false
86
+
87
+ system "rm ~/.relaton-bib.pstore"
88
+ system "rm ~/.iev.pstore"
89
+ system "mv ~/.relaton-bib.pstore1 ~/.relaton-bib.pstore"
90
+ system "mv ~/.iev.pstore1 ~/.iev.pstore"
91
+ end
92
+
93
+ it "flushes biblio caches" do
94
+ system "cp ~/.relaton-bib.pstore ~/.relaton-bib.pstore1"
95
+ system "cp ~/.iev.pstore ~/.iev.pstore1"
96
+
97
+ File.open("#{Dir.home}/.relaton-bib.pstore", "w") { |f| f.write "XXX" }
98
+ system "rm ~/.iev.pstore"
99
+
100
+ mock_isobib_get_123
101
+ Asciidoctor.convert(<<~"INPUT", backend: :iso, header_footer: true)
102
+ #{FLUSH_CACHE_ISOBIB_BLANK_HDR}
103
+ [bibliography]
104
+ == Normative References
105
+
106
+ * [[[iso123,ISO 123:2001]]] _Standard_
107
+ INPUT
108
+ expect(File.exist?("#{Dir.home}/.relaton-bib.pstore")).to be true
109
+ expect(File.exist?("#{Dir.home}/.iev.pstore")).to be true
110
+
111
+ db = Relaton::Db.new "#{Dir.home}/.relaton-bib.pstore", nil
112
+ entry = db.load_entry("ISO 123:2001")
113
+ expect(entry["fetched"].to_s).to eq(Date.today.to_s)
114
+ expect(entry["bib"].to_xml).to be_equivalent_to(ISOBIB_123_DATED)
115
+
116
+ system "rm ~/.relaton-bib.pstore"
117
+ system "rm ~/.iev.pstore"
118
+ system "mv ~/.relaton-bib.pstore1 ~/.relaton-bib.pstore"
119
+ system "mv ~/.iev.pstore1 ~/.iev.pstore"
120
+ end
121
+
122
+ it "activates global cache" do
123
+ system "mv ~/.relaton-bib.pstore ~/.relaton-bib.pstore1"
124
+ system "rm -f test.relaton.pstore"
125
+ mock_isobib_get_123
126
+ Asciidoctor.convert(<<~"INPUT", backend: :iso, header_footer: true)
127
+ #{CACHED_ISOBIB_BLANK_HDR}
128
+ [bibliography]
129
+ == Normative References
130
+
131
+ * [[[iso123,ISO 123:2001]]] _Standard_
132
+ INPUT
133
+ expect(File.exist?("#{Dir.home}/.relaton-bib.pstore")).to be true
134
+ expect(File.exist?("test.relaton.pstore")).to be false
135
+
136
+ db = Relaton::Db.new "#{Dir.home}/.relaton-bib.pstore", nil
137
+ entry = db.load_entry("ISO 123:2001")
138
+ expect(entry).to_not be nil
139
+
140
+ system "rm ~/.relaton-bib.pstore"
141
+ system "mv ~/.relaton-bib.pstore1 ~/.relaton-bib.pstore"
142
+ end
143
+
144
+ it "activates local cache" do
145
+ system "mv ~/.relaton-bib.pstore ~/.relaton-bib.pstore1"
146
+ system "rm -f test.relaton.pstore"
147
+ mock_isobib_get_123
148
+ Asciidoctor.convert(<<~"INPUT", backend: :iso, header_footer: true)
149
+ #{LOCAL_CACHED_ISOBIB_BLANK_HDR}
150
+ [bibliography]
151
+ == Normative References
152
+
153
+ * [[[iso123,ISO 123:2001]]] _Standard_
154
+ INPUT
155
+ expect(File.exist?("#{Dir.home}/.relaton-bib.pstore")).to be true
156
+ expect(File.exist?("test.relaton.pstore")).to be true
157
+
158
+ db = Relaton::Db.new "#{Dir.home}/.relaton-bib.pstore", nil
159
+ entry = db.load_entry("ISO 123:2001")
160
+ expect(entry).to_not be nil
161
+
162
+ db = Relaton::Db.new "test.relaton.pstore", nil
163
+ entry = db.load_entry("ISO 123:2001")
164
+ expect(entry).to_not be nil
165
+
166
+ system "rm ~/.relaton-bib.pstore"
167
+ system "mv ~/.relaton-bib.pstore1 ~/.relaton-bib.pstore"
168
+ end
169
+
170
+
171
+ it "fetches uncached references" do
172
+ system "mv ~/.relaton-bib.pstore ~/.relaton-bib.pstore1"
173
+ db = Relaton::Db.new "#{Dir.home}/.relaton-bib.pstore", nil
174
+ db.save_entry("ISO 123:2001",
175
+ {
176
+ "fetched" => Date.today.to_s,
177
+ "bib" => IsoBibItem.from_xml(ISO_123_SHORT)
178
+ }
179
+ )
180
+
181
+ mock_isobib_get_124
182
+
183
+ Asciidoctor.convert(<<~"INPUT", backend: :iso, header_footer: true)
184
+ #{CACHED_ISOBIB_BLANK_HDR}
185
+ [bibliography]
186
+ == Normative References
187
+
188
+ * [[[iso123,ISO 123:2001]]] _Standard_
189
+ * [[[iso124,ISO 124:2014]]] _Standard_
190
+ INPUT
191
+
192
+ entry = db.load_entry("ISO 123:2001")
193
+ expect(entry["fetched"].to_s).to eq(Date.today.to_s)
194
+ expect(entry["bib"].to_xml).to be_equivalent_to(ISO_123_SHORT)
195
+ entry = db.load_entry("ISO 124:2014")
196
+ expect(entry["fetched"].to_s).to eq(Date.today.to_s)
197
+ expect(entry["bib"].to_xml).to be_equivalent_to(ISOBIB_124_DATED)
198
+
199
+ system "rm ~/.relaton-bib.pstore"
200
+ system "mv ~/.relaton-bib.pstore1 ~/.relaton-bib.pstore"
201
+ end
202
+
203
+ it "expires stale undated references" do
204
+ system "mv ~/.relaton-bib.pstore ~/.relaton-bib.pstore1"
205
+
206
+ db = Relaton::Db.new "#{Dir.home}/.relaton-bib.pstore", nil
207
+ db.save_entry("ISO 123",
208
+ {
209
+ "fetched" => (Date.today - 90),
210
+ "bib" => IsoBibItem.from_xml(ISO_123_SHORT)
211
+ }
212
+ )
213
+
214
+ mock_isobib_get_123_undated
215
+
216
+ Asciidoctor.convert(<<~"INPUT", backend: :iso, header_footer: true)
217
+ #{CACHED_ISOBIB_BLANK_HDR}
218
+ [bibliography]
219
+ == Normative References
220
+
221
+ * [[[iso123,ISO 123]]] _Standard_
222
+ INPUT
223
+
224
+ entry = db.load_entry("ISO 123")
225
+ expect(entry["fetched"].to_s).to eq(Date.today.to_s)
226
+ expect(entry["bib"].to_xml).to be_equivalent_to(ISOBIB_123_UNDATED)
227
+
228
+ system "rm ~/.relaton-bib.pstore"
229
+ system "mv ~/.relaton-bib.pstore1 ~/.relaton-bib.pstore"
230
+ end
231
+
232
+ it "does not expire stale dated references" do
233
+ system "mv ~/.relaton-bib.pstore ~/.relaton-bib.pstore1"
234
+
235
+ db = Relaton::Db.new "#{Dir.home}/.relaton-bib.pstore", nil
236
+ db.save_entry("ISO 123:2001",
237
+ {
238
+ "fetched" => (Date.today - 90),
239
+ "bib" => IsoBibItem.from_xml(ISO_123_SHORT)
240
+ }
241
+ )
242
+
243
+ Asciidoctor.convert(<<~"INPUT", backend: :iso, header_footer: true)
244
+ #{CACHED_ISOBIB_BLANK_HDR}
245
+ [bibliography]
246
+ == Normative References
247
+
248
+ * [[[iso123,ISO 123:2001]]] _Standard_
249
+ INPUT
250
+
251
+ entry = db.load_entry("ISO 123:2001")
252
+ expect(entry["fetched"].to_s).to eq((Date.today - 90).to_s)
253
+ expect(entry["bib"].to_xml).to be_equivalent_to(ISO_123_SHORT)
254
+
255
+ system "rm ~/.relaton-bib.pstore"
256
+ system "mv ~/.relaton-bib.pstore1 ~/.relaton-bib.pstore"
257
+ end
258
+
259
+ it "prioritises local over global cache values" do
260
+ system "mv ~/.relaton-bib.pstore ~/.relaton-bib.pstore1"
261
+ system "rm test.relaton.pstore"
262
+
263
+ db = Relaton::Db.new "#{Dir.home}/.relaton-bib.pstore", nil
264
+ db.save_entry("ISO 123:2001",
265
+ {
266
+ "fetched" => Date.today,
267
+ "bib" => IsoBibItem.from_xml(ISO_123_SHORT)
268
+ }
269
+ )
270
+ db.save_entry("ISO 124",
271
+ {
272
+ "fetched" => Date.today,
273
+ "bib" => IsoBibItem.from_xml(ISO_124_SHORT)
274
+ }
275
+ )
276
+
277
+ localdb = Relaton::Db.new "test.relaton.pstore", nil
278
+ localdb.save_entry("ISO 124",
279
+ {
280
+ "fetched" => Date.today,
281
+ "bib" => IsoBibItem.from_xml(ISO_124_SHORT_ALT)
282
+ }
283
+ )
284
+
285
+ input = <<~EOS
286
+ #{LOCAL_CACHED_ISOBIB_BLANK_HDR}
287
+ [bibliography]
288
+ == Normative References
289
+
290
+ * [[[ISO123,ISO 123:2001]]] _Standard_
291
+ * [[[ISO124,ISO 124]]] _Standard_
292
+ EOS
293
+
294
+ output = <<~EOS
295
+ #{BLANK_HDR}
296
+ <sections>
297
+ </sections>
298
+ <bibliography>
299
+ <references id="_" obligation="informative">
300
+ <title>Normative References</title>
301
+ #{ISO_123_SHORT}
302
+ #{ISO_124_SHORT_ALT}
303
+ </references></bibliography>
304
+ </iso-standard>
305
+ EOS
306
+
307
+ expect(strip_guid(Asciidoctor.convert(input, backend: :iso, header_footer: true))).to be_equivalent_to(output)
308
+
309
+ expect(db.load_entry("ISO 123:2001")["bib"].to_xml).to be_equivalent_to(ISO_123_SHORT)
310
+ expect(db.load_entry("ISO 124")["bib"].to_xml).to be_equivalent_to(ISO_124_SHORT)
311
+ expect(localdb.load_entry("ISO 123:2001")["bib"].to_xml).to be_equivalent_to(ISO_123_SHORT)
312
+ expect(localdb.load_entry("ISO 124")["bib"].to_xml).to be_equivalent_to(ISO_124_SHORT_ALT)
313
+
314
+ system "rm ~/.relaton-bib.pstore"
315
+ system "mv ~/.relaton-bib.pstore1 ~/.relaton-bib.pstore"
316
+ end
317
+
318
+ private
319
+
320
+ def mock_isobib_get_123
321
+ expect(Isobib::IsoBibliography).to receive(:get).with("ISO 123", "2001", {}).and_return(IsoBibItem.from_xml(ISOBIB_123_DATED))
322
+ end
323
+
324
+ def mock_isobib_get_123_undated
325
+ expect(Isobib::IsoBibliography).to receive(:get).with("ISO 123", nil, {}).and_return(IsoBibItem.from_xml(ISOBIB_123_UNDATED))
326
+ end
327
+
328
+ def mock_isobib_get_124
329
+ expect(Isobib::IsoBibliography).to receive(:get).with("ISO 124", "2014", {}).and_return(IsoBibItem.from_xml(ISOBIB_124_DATED))
330
+ end
331
+
332
+ end