metanorma-standoc 1.0.7 → 1.0.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (35) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +212 -0
  3. data/lib/asciidoctor/standoc/base.rb +7 -6
  4. data/lib/asciidoctor/standoc/biblio.rng +42 -3
  5. data/lib/asciidoctor/standoc/cleanup.rb +1 -1
  6. data/lib/asciidoctor/standoc/cleanup_footnotes.rb +1 -1
  7. data/lib/asciidoctor/standoc/front.rb +10 -0
  8. data/lib/asciidoctor/standoc/inline.rb +1 -0
  9. data/lib/asciidoctor/standoc/macros.rb +3 -1
  10. data/lib/asciidoctor/standoc/ref.rb +3 -4
  11. data/lib/asciidoctor/standoc/utils.rb +13 -1
  12. data/lib/metanorma/standoc/processor.rb +2 -2
  13. data/lib/metanorma/standoc/version.rb +1 -1
  14. data/metanorma-standoc.gemspec +4 -4
  15. data/spec/asciidoctor-standoc/base_spec.rb +17 -5
  16. data/spec/asciidoctor-standoc/cleanup_spec.rb +151 -113
  17. data/spec/asciidoctor-standoc/inline_spec.rb +10 -2
  18. data/spec/asciidoctor-standoc/isobib_cache_spec.rb +167 -129
  19. data/spec/asciidoctor-standoc/macros_spec.rb +1 -1
  20. data/spec/asciidoctor-standoc/refs_spec.rb +283 -215
  21. data/spec/asciidoctor-standoc/validate_spec.rb +10 -9
  22. data/spec/examples/iso_123_.xml +1 -0
  23. data/spec/examples/iso_123_all_parts.xml +1 -0
  24. data/spec/examples/iso_123_no_year_note.xml +1 -0
  25. data/spec/examples/iso_124_.xml +1 -0
  26. data/spec/examples/iso_216_.xml +2 -1
  27. data/spec/examples/iso_iec_12382_.xml +2 -1
  28. data/spec/metanorma/processor_spec.rb +5 -5
  29. data/spec/spec_helper.rb +7 -0
  30. data/spec/vcr_cassettes/dated_iso_ref_joint_iso_iec.yml +879 -0
  31. data/spec/vcr_cassettes/isobib_get_123.yml +667 -0
  32. data/spec/vcr_cassettes/isobib_get_124.yml +1201 -0
  33. data/spec/vcr_cassettes/rfcbib_get_rfc8341.yml +129 -0
  34. data/spec/vcr_cassettes/separates_iev_citations_by_top_level_clause.yml +424 -0
  35. metadata +34 -28
@@ -5,7 +5,7 @@ require "json"
5
5
  require "pathname"
6
6
  require "open-uri"
7
7
  require "uuidtools"
8
- require "pp"
8
+ require "sterile"
9
9
 
10
10
  module Asciidoctor
11
11
  module Standoc
@@ -32,6 +32,18 @@ module Asciidoctor
32
32
  "??"
33
33
  end
34
34
 
35
+ def smart_render_xml(x)
36
+ xstr = x.to_xml if x.respond_to? :to_xml
37
+ xml = Nokogiri::XML(xstr)
38
+ xml.traverse do |n|
39
+ next unless n.text?
40
+ n.replace(n.text.gsub(/ -- /, " — ").
41
+ gsub(/--/, "—").gsub(/\.\.\./, "…").
42
+ smart_format)
43
+ end
44
+ xml.to_xml.sub(/<\?[^>]+>/, "")
45
+ end
46
+
35
47
  def warning(node, msg, text)
36
48
  return if @novalid
37
49
  warntext = "asciidoctor: WARNING"\
@@ -21,8 +21,8 @@ module Metanorma
21
21
  "Metanorma::Standoc #{Metanorma::Standoc::VERSION}/IsoDoc #{IsoDoc::VERSION}"
22
22
  end
23
23
 
24
- def input_to_isodoc(file)
25
- Metanorma::Input::Asciidoc.new.process(file, @asciidoctor_backend)
24
+ def input_to_isodoc(file, filename)
25
+ Metanorma::Input::Asciidoc.new.process(file, filename, @asciidoctor_backend)
26
26
  end
27
27
 
28
28
  def output(isodoc_node, outname, format, options={})
@@ -1,5 +1,5 @@
1
1
  module Metanorma
2
2
  module Standoc
3
- VERSION = "1.0.7".freeze
3
+ VERSION = "1.0.8".freeze
4
4
  end
5
5
  end
@@ -30,7 +30,8 @@ Gem::Specification.new do |spec|
30
30
  spec.add_dependency "ruby-jing"
31
31
  spec.add_dependency "isodoc", "~> 0.9.0"
32
32
  spec.add_dependency "iev", "~> 0.2.0"
33
- spec.add_dependency "relaton", "~> 0.2.2"
33
+ spec.add_dependency "relaton", "~> 0.3.0"
34
+ spec.add_dependency "sterile"
34
35
 
35
36
  spec.add_development_dependency "bundler", "~> 1.15"
36
37
  spec.add_development_dependency "byebug"
@@ -43,7 +44,6 @@ Gem::Specification.new do |spec|
43
44
  spec.add_development_dependency "simplecov", "~> 0.15"
44
45
  spec.add_development_dependency "timecop", "~> 0.9"
45
46
  spec.add_development_dependency "metanorma", "~> 0.2.6"
46
- spec.add_development_dependency "isobib", "~> 0.3.0"
47
- spec.add_development_dependency "ietfbib", "~> 0.4.0"
48
- spec.add_development_dependency "iecbib", "~> 0.1.1"
47
+ spec.add_development_dependency "vcr"
48
+ spec.add_development_dependency "webmock"
49
49
  end
@@ -1,4 +1,5 @@
1
1
  require "spec_helper"
2
+ require "fileutils"
2
3
 
3
4
  RSpec.describe Asciidoctor::Standoc do
4
5
  it "has a version number" do
@@ -16,7 +17,7 @@ RSpec.describe Asciidoctor::Standoc do
16
17
  end
17
18
 
18
19
  it "converts a blank document" do
19
- system "rm -f test.doc"
20
+ FileUtils.rm_f "test.doc"
20
21
  expect(Asciidoctor.convert(<<~"INPUT", backend: :standoc, header_footer: true)).to be_equivalent_to <<~"OUTPUT"
21
22
  = Document title
22
23
  Author
@@ -119,11 +120,22 @@ RSpec.describe Asciidoctor::Standoc do
119
120
  :language: el
120
121
  :script: Grek
121
122
  :publisher: IEC,IETF,ISO
123
+ :uri: A
124
+ :xml-uri: B
125
+ :html-uri: C
126
+ :pdf-uri: D
127
+ :doc-uri: E
128
+ :relaton-uri: F
122
129
  INPUT
123
130
  <?xml version="1.0" encoding="UTF-8"?>
124
131
  <standard-document xmlns="http://riboseinc.com/isoxml">
125
132
  <bibdata type="article">
126
-
133
+ <source>A</source>
134
+ <source type="xml">B</source>
135
+ <source type="html">C</source>
136
+ <source type="pdf">D</source>
137
+ <source type="doc">E</source>
138
+ <source type="relaton">F</source>
127
139
  <docidentifier>
128
140
  <project-number part="1" subpart="1">ISO/IEC/IETF 1000</project-number>
129
141
  </docidentifier>
@@ -200,7 +212,7 @@ RSpec.describe Asciidoctor::Standoc do
200
212
  end
201
213
 
202
214
  it "reads scripts into blank HTML document" do
203
- system "rm -f test.html"
215
+ FileUtils.rm_f "test.html"
204
216
  Asciidoctor.convert(<<~"INPUT", backend: :standoc, header_footer: true)
205
217
  = Document title
206
218
  Author
@@ -213,7 +225,7 @@ RSpec.describe Asciidoctor::Standoc do
213
225
  end
214
226
 
215
227
  it "uses specified fonts and assets in HTML" do
216
- system "rm -f test.html"
228
+ FileUtils.rm_f "test.html"
217
229
  Asciidoctor.convert(<<~"INPUT", backend: :standoc, header_footer: true)
218
230
  = Document title
219
231
  Author
@@ -238,7 +250,7 @@ RSpec.describe Asciidoctor::Standoc do
238
250
  end
239
251
 
240
252
  it "uses specified fonts and assets in Word" do
241
- system "rm -f test.doc"
253
+ FileUtils.rm_f "test.doc"
242
254
  Asciidoctor.convert(<<~"INPUT", backend: :standoc, header_footer: true)
243
255
  = Document title
244
256
  Author
@@ -1,5 +1,6 @@
1
1
  require "spec_helper"
2
2
  require "iecbib"
3
+ require "fileutils"
3
4
 
4
5
  RSpec.describe Asciidoctor::Standoc do
5
6
  it "removes empty text elements" do
@@ -806,132 +807,169 @@ r = 1 %</stem>
806
807
  end
807
808
 
808
809
  it "separates IEV citations by top-level clause" do
809
- system "mv ~/.iev.pstore ~/.iev.pstore1"
810
- system "rm test.iev.pstore"
811
- system "mv ~/.relaton-bib.pstore ~/.relaton-bib.pstore1"
812
- system "rm test.relaton.pstore"
813
- mock_iecbib_get_iec60050_102_01
814
- mock_iecbib_get_iec60050_103_01
815
- mock_iev
810
+ FileUtils.rm_rf File.expand_path("~/.relaton-bib.pstore1")
811
+ FileUtils.mv File.expand_path("~/.relaton-bib.pstore"), File.expand_path("~/.relaton-bib.pstore1"), force: true
812
+ FileUtils.rm_rf File.expand_path("~/.iev.pstore1")
813
+ FileUtils.mv File.expand_path("~/.iev.pstore"), File.expand_path("~/.iev.pstore1"), force: true
814
+ FileUtils.rm_rf "test.relaton.pstore"
815
+ FileUtils.rm_rf "test.iev.pstore"
816
+ # mock_iecbib_get_iec60050_102_01
817
+ # mock_iecbib_get_iec60050_103_01
818
+ # mock_iev
819
+ VCR.use_cassette "separates_iev_citations_by_top_level_clause" do
816
820
  expect(strip_guid(Asciidoctor.convert(<<~"INPUT", backend: :standoc, header_footer: true))).to be_equivalent_to <<~"OUTPUT"
817
- #{CACHED_ISOBIB_BLANK_HDR}
821
+ #{CACHED_ISOBIB_BLANK_HDR}
818
822
 
819
- [bibliography]
820
- == Normative References
821
- * [[[iev,IEV]]], _iev_
822
-
823
- == Terms and definitions
824
- === Automation1
823
+ [bibliography]
824
+ == Normative References
825
+ * [[[iev,IEV]]], _iev_
825
826
 
826
- [.source]
827
- <<iev,clause="103-01-02">>
827
+ == Terms and definitions
828
+ === Automation1
828
829
 
829
- === Automation2
830
+ [.source]
831
+ <<iev,clause="103-01-02">>
830
832
 
831
- [.source]
832
- <<iev,clause="102-01-02">>
833
+ === Automation2
833
834
 
834
- === Automation3
835
+ [.source]
836
+ <<iev,clause="102-01-02">>
835
837
 
836
- [.source]
837
- <<iev,clause="103-01-02">>
838
- INPUT
839
- #{BLANK_HDR}
838
+ === Automation3
840
839
 
841
- <sections>
842
- <terms id="_" obligation="normative"><title>Terms and definitions</title><term id="_">
843
- <preferred>Automation1</preferred>
844
- <termsource status="identical">
845
- <origin bibitemid="IEC60050-103" type="inline" citeas="IEC 60050-103:2009"><locality type="clause"><referenceFrom>103-01-02</referenceFrom></locality></origin>
846
- </termsource>
847
- </term>
848
- <term id="_">
849
- <preferred>Automation2</preferred>
850
- <termsource status="identical">
851
- <origin bibitemid="IEC60050-102" type="inline" citeas="IEC 60050-102:2007"><locality type="clause"><referenceFrom>102-01-02</referenceFrom></locality></origin>
852
- </termsource>
853
- </term>
854
- <term id="_">
855
- <preferred>Automation3</preferred>
856
- <termsource status="identical">
857
- <origin bibitemid="IEC60050-103" type="inline" citeas="IEC 60050-103:2009"><locality type="clause"><referenceFrom>103-01-02</referenceFrom></locality></origin>
858
- </termsource>
859
- </term></terms></sections><bibliography><references id="_" obligation="informative">
860
- <title>Normative References</title>
861
- <bibitem type="international-standard" id="IEC60050-102">
862
- <title format="text/plain" language="en" script="Latn">International Electrotechnical Vocabulary</title>
863
- <docidentifier>IEC 60050-102:2007</docidentifier>
864
- <date type="published">
865
- <on>2007</on>
866
- </date>
867
- <contributor>
868
- <role type="publisher"/>
869
- <organization>
870
- <name>International Electrotechnical Commission</name>
871
- <abbreviation>IEC</abbreviation>
872
- <uri>www.iec.ch</uri>
873
- </organization>
874
- </contributor>
875
- <language>en</language>
876
- <language>fr</language>
877
- <script>Latn</script>
878
- <status>
879
- <stage>60</stage>
880
- </status>
881
- <copyright>
882
- <from>2018</from>
883
- <owner>
884
- <organization>
885
- <name>International Electrotechnical Commission</name>
886
- <abbreviation>IEC</abbreviation>
887
- <uri>www.iec.ch</uri>
888
- </organization>
889
- </owner>
890
- </copyright>
891
- </bibitem><bibitem type="international-standard" id="IEC60050-103">
892
- <title format="text/plain" language="en" script="Latn">International Electrotechnical Vocabulary</title>
893
- <docidentifier>IEC 60050-103:2009</docidentifier>
894
- <date type="published">
895
- <on>2009</on>
896
- </date>
897
- <contributor>
898
- <role type="publisher"/>
899
- <organization>
900
- <name>International Electrotechnical Commission</name>
901
- <abbreviation>IEC</abbreviation>
902
- <uri>www.iec.ch</uri>
903
- </organization>
904
- </contributor>
905
- <language>en</language>
906
- <language>fr</language>
907
- <script>Latn</script>
908
- <status>
909
- <stage>60</stage>
910
- </status>
911
- <copyright>
912
- <from>2018</from>
913
- <owner>
914
- <organization>
915
- <name>International Electrotechnical Commission</name>
916
- <abbreviation>IEC</abbreviation>
917
- <uri>www.iec.ch</uri>
918
- </organization>
919
- </owner>
920
- </copyright>
921
- </bibitem>
922
- </references></bibliography>
923
- </standard-document>
840
+ [.source]
841
+ <<iev,clause="103-01-02">>
842
+ INPUT
843
+ #{BLANK_HDR}
844
+
845
+ <sections>
846
+ <terms id="_" obligation="normative"><title>Terms and definitions</title><term id="_">
847
+ <preferred>Automation1</preferred>
848
+ <termsource status="identical">
849
+ <origin bibitemid="IEC60050-103" type="inline" citeas="IEC 60050-103:2009"><locality type="clause"><referenceFrom>103-01-02</referenceFrom></locality></origin>
850
+ </termsource>
851
+ </term>
852
+ <term id="_">
853
+ <preferred>Automation2</preferred>
854
+ <termsource status="identical">
855
+ <origin bibitemid="IEC60050-102" type="inline" citeas="IEC 60050-102:2007"><locality type="clause"><referenceFrom>102-01-02</referenceFrom></locality></origin>
856
+ </termsource>
857
+ </term>
858
+ <term id="_">
859
+ <preferred>Automation3</preferred>
860
+ <termsource status="identical">
861
+ <origin bibitemid="IEC60050-103" type="inline" citeas="IEC 60050-103:2009"><locality type="clause"><referenceFrom>103-01-02</referenceFrom></locality></origin>
862
+ </termsource>
863
+ </term></terms></sections><bibliography><references id="_" obligation="informative">
864
+ <title>Normative References</title>
865
+ <bibitem type="international-standard" id="IEC60050-102">
866
+ <fetched>#{Date.today}</fetched>
867
+ <title format="text/plain" language="en" script="Latn">International Electrotechnical Vocabulary -- Part 102: Mathematics -- General concepts and linear algebra</title>
868
+ <uri type="src">https://webstore.iec.ch/publication/160</uri>
869
+ <uri type="obp">/preview/info_iec60050-102%7Bed1.0%7Db.pdf</uri>
870
+ <docidentifier type="IEC">IEC 60050-102:2007</docidentifier>
871
+ <date type="published">
872
+ <on>2007</on>
873
+ </date>
874
+ <contributor>
875
+ <role type="publisher"/>
876
+ <organization>
877
+ <name>International Electrotechnical Commission</name>
878
+ <abbreviation>IEC</abbreviation>
879
+ <uri>www.iec.ch</uri>
880
+ </organization>
881
+ </contributor>
882
+ <edition>1.0</edition>
883
+ <language>en</language>
884
+ <script>Latn</script>
885
+ <abstract format="plain" language="en" script="Latn">This part of IEC 60050 gives the general mathematical terminology used in the fields of electricity, electronics and telecommunications, together with basic concepts in linear algebra. It maintains a clear distinction between mathematical concepts and physical concepts, even if some terms are used in both cases. Another part will deal with functions. It has the status of a horizontal standard in accordance with IEC Guide 108.</abstract>
886
+ <status>
887
+ <stage>60</stage>
888
+ <substage>60</substage>
889
+ </status>
890
+ <copyright>
891
+ <from>2007</from>
892
+ <owner>
893
+ <organization>
894
+ <name>International Electrotechnical Commission</name>
895
+ <abbreviation>IEC</abbreviation>
896
+ <uri>www.iec.ch</uri>
897
+ </organization>
898
+ </owner>
899
+ </copyright>
900
+ <editorialgroup>
901
+ <technical-committee number="1" type="technicalCommittee">TC 1 - Terminology</technical-committee>
902
+ </editorialgroup>
903
+ <ics>
904
+ <code>01.040.07</code>
905
+ <text>Natural and applied sciences (Vocabularies)</text>
906
+ </ics>
907
+ <ics>
908
+ <code>07.020</code>
909
+ <text>Mathematics</text>
910
+ </ics>
911
+ </bibitem><bibitem type="international-standard" id="IEC60050-103">
912
+ <fetched>#{Date.today}</fetched>
913
+ <title format="text/plain" language="en" script="Latn">International Electrotechnical Vocabulary -- Part 103: Mathematics -- Functions </title>
914
+ <uri type="src">https://webstore.iec.ch/publication/161</uri>
915
+ <uri type="obp">/preview/info_iec60050-103%7Bed1.0%7Db.pdf</uri>
916
+ <docidentifier type="IEC">IEC 60050-103:2009</docidentifier>
917
+ <date type="published">
918
+ <on>2009</on>
919
+ </date>
920
+ <contributor>
921
+ <role type="publisher"/>
922
+ <organization>
923
+ <name>International Electrotechnical Commission</name>
924
+ <abbreviation>IEC</abbreviation>
925
+ <uri>www.iec.ch</uri>
926
+ </organization>
927
+ </contributor>
928
+ <edition>1.0</edition>
929
+ <language>en</language>
930
+ <script>Latn</script>
931
+ <abstract format="plain" language="en" script="Latn">IEC 60050-103:2009 gives the terminology relative to functions of one or more variables. Together with IEC 60050-102, it covers the mathematical terminology used in the fields of electricity, electronics and telecommunications. It maintains a clear distinction between mathematical concepts and physical concepts, even if some terms are used in both cases. Mathematical symbols are generally in accordance with IEC 60027-1 and ISO 80000-2. This standard cancels and replaces Sections 101-13, 101-14 and 101-15 of International Standard IEC 60050-101:1998. It has the status of a horizontal standard in accordance with IEC Guide 108.</abstract>
932
+ <status>
933
+ <stage>60</stage>
934
+ <substage>60</substage>
935
+ </status>
936
+ <copyright>
937
+ <from>2009</from>
938
+ <owner>
939
+ <organization>
940
+ <name>International Electrotechnical Commission</name>
941
+ <abbreviation>IEC</abbreviation>
942
+ <uri>www.iec.ch</uri>
943
+ </organization>
944
+ </owner>
945
+ </copyright>
946
+ <editorialgroup>
947
+ <technical-committee number="1" type="technicalCommittee">TC 1 - Terminology</technical-committee>
948
+ </editorialgroup>
949
+ <ics>
950
+ <code>01.040.07</code>
951
+ <text>Natural and applied sciences (Vocabularies)</text>
952
+ </ics>
953
+ <ics>
954
+ <code>07.020</code>
955
+ <text>Mathematics</text>
956
+ </ics>
957
+ </bibitem>
958
+ </references></bibliography>
959
+ </standard-document>
924
960
  OUTPUT
925
- system "mv ~/.iev.pstore1 ~/.iev.pstore"
926
- system "rm ~/.relaton-bib.pstore"
927
- system "mv ~/.relaton-bib.pstore1 ~/.relaton-bib.pstore"
961
+ end
962
+ FileUtils.rm_rf File.expand_path("~/.iev.pstore")
963
+ FileUtils.mv File.expand_path("~/.iev.pstore1"), File.expand_path("~/.iev.pstore"), force: true
964
+ FileUtils.rm_rf File.expand_path("~/.relaton-bib.pstore")
965
+ FileUtils.mv File.expand_path("~/.relaton-bib.pstore1"), File.expand_path("~/.relaton-bib.pstore"), force: true
928
966
  end
929
967
 
930
968
  private
931
969
 
932
970
  def mock_iecbib_get_iec60050_103_01
933
971
  expect(Iecbib::IecBibliography).to receive(:get).with("IEC 60050-103", nil, {keep_year: true}) do
934
- IsoBibItem.from_xml(<<~"OUTPUT")
972
+ IsoBibItem::XMLParser.from_xml(<<~"OUTPUT")
935
973
  <bibitem type="international-standard" id="IEC60050-103">
936
974
  <title format="text/plain" language="en" script="Latn">International Electrotechnical Vocabulary</title>
937
975
  <docidentifier>IEC 60050-103:2009</docidentifier>
@@ -969,7 +1007,7 @@ end
969
1007
 
970
1008
  def mock_iecbib_get_iec60050_102_01
971
1009
  expect(Iecbib::IecBibliography).to receive(:get).with("IEC 60050-102", nil, {keep_year: true}) do
972
- IsoBibItem.from_xml(<<~"OUTPUT")
1010
+ IsoBibItem::XMLParser.from_xml(<<~"OUTPUT")
973
1011
  <bibitem type="international-standard" id="IEC60050-102">
974
1012
  <title format="text/plain" language="en" script="Latn">International Electrotechnical Vocabulary</title>
975
1013
  <docidentifier>IEC 60050-102:2007</docidentifier>
@@ -1007,7 +1045,7 @@ end
1007
1045
 
1008
1046
  def mock_iev
1009
1047
  expect(Iecbib::IecBibliography).to receive(:get).with("IEV", nil, {}) do
1010
- IsoBibItem.from_xml(<<~"OUTPUT")
1048
+ IsoBibItem::XMLParser.from_xml(<<~"OUTPUT")
1011
1049
  <bibitem type="international-standard" id="IEC60050:2001">
1012
1050
  <title format="text/plain" language="en" script="Latn">International Electrotechnical Vocabulary</title>
1013
1051
  <docidentifier>IEC 60050:2011</docidentifier>
@@ -147,13 +147,21 @@ RSpec.describe Asciidoctor::Standoc do
147
147
  expect(strip_guid(Asciidoctor.convert(<<~"INPUT", backend: :standoc, header_footer: true))).to be_equivalent_to <<~"OUTPUT"
148
148
  #{ASCIIDOC_BLANK_HDR}
149
149
  Hello!footnote:[Footnote text]
150
+
151
+ == Title footnote:[Footnote text 2]
150
152
  INPUT
151
153
  #{BLANK_HDR}
152
- <sections>
154
+ <preface><foreword obligation="informative">
155
+ <title>Foreword</title>
153
156
  <p id="_">Hello!<fn reference="1">
154
157
  <p id="_">Footnote text</p>
155
158
  </fn></p>
156
- </sections>
159
+ </foreword></preface><sections>
160
+ <clause id="_" inline-header="false" obligation="normative">
161
+ <title>Title<fn reference="2">
162
+ <p id="_">Footnote text 2</p>
163
+ </fn></title>
164
+ </clause></sections>
157
165
  </standard-document>
158
166
  OUTPUT
159
167
  end