metanorma-iec 1.2.9 → 1.2.14

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/.github/workflows/rake.yml +3 -0
  3. data/.rubocop.yml +0 -4
  4. data/lib/asciidoctor/iec/basicdoc.rng +52 -3
  5. data/lib/asciidoctor/iec/converter.rb +20 -0
  6. data/lib/asciidoctor/iec/front.rb +29 -58
  7. data/lib/asciidoctor/iec/iec.rng +47 -2
  8. data/lib/asciidoctor/iec/iec_intro_en.xml +37 -12
  9. data/lib/asciidoctor/iec/iec_intro_fr.xml +38 -6
  10. data/lib/asciidoctor/iec/isodoc.rng +114 -3
  11. data/lib/asciidoctor/iec/isostandard.rng +19 -10
  12. data/lib/isodoc/iec/base_convert.rb +2 -2
  13. data/lib/isodoc/iec/html/html_iec_intro.html +1 -1
  14. data/lib/isodoc/iec/html/word_iec_intro.html +1 -1
  15. data/lib/isodoc/iec/html_convert.rb +2 -2
  16. data/lib/isodoc/iec/i18n-en.yaml +1 -0
  17. data/lib/isodoc/iec/i18n-fr.yaml +1 -0
  18. data/lib/isodoc/iec/iec.international-standard.xsl +848 -363
  19. data/lib/isodoc/iec/word_convert.rb +2 -2
  20. data/lib/metanorma/iec/processor.rb +11 -0
  21. data/lib/metanorma/iec/version.rb +1 -1
  22. data/metanorma-iec.gemspec +2 -2
  23. data/spec/asciidoctor-iec/base_spec.rb +436 -10
  24. data/spec/asciidoctor-iec/blocks_spec.rb +24 -20
  25. data/spec/asciidoctor-iec/cleanup_spec.rb +99 -14
  26. data/spec/asciidoctor-iec/iev_spec.rb +12 -6
  27. data/spec/asciidoctor-iec/inline_spec.rb +11 -7
  28. data/spec/asciidoctor-iec/lists_spec.rb +7 -3
  29. data/spec/asciidoctor-iec/section_spec.rb +9 -5
  30. data/spec/asciidoctor-iec/validate_spec.rb +22 -21
  31. data/spec/isodoc/iso_spec.rb +2 -2
  32. data/spec/metanorma/processor_spec.rb +1 -1
  33. data/spec/spec_helper.rb +25 -33
  34. metadata +6 -7
  35. data/lib/metanorma/iec/fonts_manifest.yaml +0 -5
@@ -1,6 +1,10 @@
1
1
  require "spec_helper"
2
2
 
3
3
  RSpec.describe Asciidoctor::Iec do
4
+ before(:all) do
5
+ @blank_hdr = blank_hdr_gen
6
+ end
7
+
4
8
  it "processes inline_quoted formatting" do
5
9
  expect(xmlpp(strip_guid(Asciidoctor.convert(<<~"INPUT", backend: :iec, header_footer: true)))).to be_equivalent_to xmlpp(<<~"OUTPUT")
6
10
  #{ASCIIDOC_BLANK_HDR}
@@ -19,7 +23,7 @@ RSpec.describe Asciidoctor::Iec do
19
23
  [strike]#strike#
20
24
  [smallcap]#smallcap#
21
25
  INPUT
22
- #{BLANK_HDR}
26
+ #{@blank_hdr}
23
27
  <sections>
24
28
  <em>emphasis</em>
25
29
  <strong>strong</strong>
@@ -56,7 +60,7 @@ RSpec.describe Asciidoctor::Iec do
56
60
 
57
61
  <<<
58
62
  INPUT
59
- #{BLANK_HDR}
63
+ #{@blank_hdr}
60
64
  <sections><p id="_">Line break<br/>
61
65
  line break</p>
62
66
  <hr/>
@@ -72,7 +76,7 @@ RSpec.describe Asciidoctor::Iec do
72
76
  http://example.com[]
73
77
  http://example.com[Link]
74
78
  INPUT
75
- #{BLANK_HDR}
79
+ #{@blank_hdr}
76
80
  <sections>
77
81
  <p id="_">mailto:fred@example.com
78
82
  <link target="http://example.com"/>
@@ -87,7 +91,7 @@ RSpec.describe Asciidoctor::Iec do
87
91
  #{ASCIIDOC_BLANK_HDR}
88
92
  Text [[bookmark]] Text
89
93
  INPUT
90
- #{BLANK_HDR}
94
+ #{@blank_hdr}
91
95
  <sections>
92
96
  <p id="_">Text <bookmark id="bookmark"/> Text</p>
93
97
  </sections>
@@ -106,7 +110,7 @@ RSpec.describe Asciidoctor::Iec do
106
110
  Inline Reference with Text to <<reference,text>>
107
111
  Footnoted Reference with Text to <<reference,fn: text>>
108
112
  INPUT
109
- #{BLANK_HDR}
113
+ #{@blank_hdr}
110
114
  <sections>
111
115
  <clause id="reference" inline-header="false" obligation="normative">
112
116
  <title>Section</title>
@@ -130,7 +134,7 @@ RSpec.describe Asciidoctor::Iec do
130
134
  * [[[ISO713]]] Reference
131
135
 
132
136
  INPUT
133
- #{BLANK_HDR}
137
+ #{@blank_hdr}
134
138
  <sections>
135
139
 
136
140
  </sections><bibliography><references id="_" obligation="informative" normative="true">
@@ -156,7 +160,7 @@ RSpec.describe Asciidoctor::Iec do
156
160
  #{ASCIIDOC_BLANK_HDR}
157
161
  Hello!footnote:[Footnote text]
158
162
  INPUT
159
- #{BLANK_HDR}
163
+ #{@blank_hdr}
160
164
  <sections>
161
165
  <p id="_">Hello!<fn reference="1">
162
166
  <p id="_">Footnote text</p>
@@ -1,6 +1,10 @@
1
1
  require "spec_helper"
2
2
 
3
3
  RSpec.describe Asciidoctor::Iec do
4
+ before(:all) do
5
+ @blank_hdr = blank_hdr_gen
6
+ end
7
+
4
8
  it "processes simple lists" do
5
9
  output = Asciidoctor.convert(<<~"INPUT", backend: :iec, header_footer: true)
6
10
  #{ASCIIDOC_BLANK_HDR}
@@ -17,7 +21,7 @@ RSpec.describe Asciidoctor::Iec do
17
21
 
18
22
  INPUT
19
23
  expect(xmlpp(strip_guid(output))).to be_equivalent_to xmlpp(<<~"OUTPUT")
20
- #{BLANK_HDR}
24
+ #{@blank_hdr}
21
25
  <sections>
22
26
  <ul id="_">
23
27
  <li>
@@ -99,7 +103,7 @@ RSpec.describe Asciidoctor::Iec do
99
103
 
100
104
  INPUT
101
105
  expect(xmlpp(strip_guid(output))).to be_equivalent_to xmlpp(<<~"OUTPUT")
102
- #{BLANK_HDR}
106
+ #{@blank_hdr}
103
107
  <sections><ul id="id">
104
108
  <li>
105
109
  <p id="_">First</p>
@@ -172,7 +176,7 @@ RSpec.describe Asciidoctor::Iec do
172
176
  * Hello [[id3]] List item
173
177
 
174
178
  INPUT
175
- #{BLANK_HDR}
179
+ #{@blank_hdr}
176
180
  <sections>
177
181
  <ul id="id1">
178
182
  <li id="id2">
@@ -1,6 +1,10 @@
1
1
  require "spec_helper"
2
2
 
3
3
  RSpec.describe Asciidoctor::Iec do
4
+ before(:all) do
5
+ @blank_hdr = blank_hdr_gen
6
+ end
7
+
4
8
  it "processes sections" do
5
9
  expect(xmlpp(strip_guid(Asciidoctor.convert(<<~"INPUT", backend: :iec, header_footer: true)))).to be_equivalent_to xmlpp(<<~"OUTPUT")
6
10
  #{ASCIIDOC_BLANK_HDR}
@@ -52,7 +56,7 @@ RSpec.describe Asciidoctor::Iec do
52
56
 
53
57
  === Bibliography Subsection
54
58
  INPUT
55
- #{BLANK_HDR}
59
+ #{@blank_hdr}
56
60
  <preface><foreword id="_" obligation="informative">
57
61
  <title>FOREWORD</title>
58
62
  <p id="_">Text</p>
@@ -189,7 +193,7 @@ RSpec.describe Asciidoctor::Iec do
189
193
 
190
194
  === Bibliography Subsection
191
195
  INPUT
192
- #{BLANK_HDR}
196
+ #{@blank_hdr}
193
197
  <preface>
194
198
  <foreword id="_" obligation="informative">
195
199
  <title>FOREWORD</title>
@@ -298,7 +302,7 @@ RSpec.describe Asciidoctor::Iec do
298
302
  [appendix,obligation=informative]
299
303
  == Annex
300
304
  INPUT
301
- #{BLANK_HDR}
305
+ #{@blank_hdr}
302
306
  <sections><clause id="_" inline-header="false" obligation="informative">
303
307
  <title>Clause 1</title>
304
308
  <clause id="_" inline-header="false" obligation="informative">
@@ -329,7 +333,7 @@ RSpec.describe Asciidoctor::Iec do
329
333
  [%inline-header]
330
334
  === Clause Aa
331
335
  INPUT
332
- #{BLANK_HDR}
336
+ #{@blank_hdr}
333
337
  <sections><clause id="_" inline-header="false" obligation="normative">
334
338
  <title>Clause 1</title>
335
339
  <clause id="_" inline-header="true" obligation="normative">
@@ -354,7 +358,7 @@ RSpec.describe Asciidoctor::Iec do
354
358
  === {blank}
355
359
 
356
360
  INPUT
357
- #{BLANK_HDR}
361
+ #{@blank_hdr}
358
362
  <sections>
359
363
  <clause id="_" inline-header="false" obligation="normative">
360
364
  <title>Clause 1</title>
@@ -15,41 +15,42 @@ RSpec.describe Asciidoctor::Iec do
15
15
 
16
16
  it "generates error file" do
17
17
  expect do
18
+ mock_pdf
18
19
  Metanorma::Compile
19
20
  .new
20
- .compile("spec/assets/xref_error.adoc", type: "iec")
21
+ .compile("spec/assets/xref_error.adoc", type: "iec", no_install_fonts: true)
21
22
  end.to(change { File.exist?("spec/assets/xref_error.err") }
22
23
  .from(false).to(true))
23
24
  end
24
25
  end
25
26
 
26
- it "Warns of illegal doctype" do
27
+ it "Warns of illegal doctype" do
27
28
  FileUtils.rm_f "test.err"
28
29
  Asciidoctor.convert(<<~"INPUT", backend: :iec, header_footer: true)
29
- = Document title
30
- Author
31
- :docfile: test.adoc
32
- :nodoc:
33
- :no-isobib:
34
- :doctype: pizza
30
+ = Document title
31
+ Author
32
+ :docfile: test.adoc
33
+ :nodoc:
34
+ :no-isobib:
35
+ :doctype: pizza
35
36
 
36
- text
37
- INPUT
37
+ text
38
+ INPUT
38
39
  expect(File.read("test.err")).to include "pizza is not a recognised document type"
39
- end
40
+ end
40
41
 
41
- it "Warns of illegal function" do
42
+ it "Warns of illegal function" do
42
43
  FileUtils.rm_f "test.err"
43
44
  Asciidoctor.convert(<<~"INPUT", backend: :iec, header_footer: true)
44
- = Document title
45
- Author
46
- :docfile: test.adoc
47
- :nodoc:
48
- :no-isobib:
49
- :function: pizza
45
+ = Document title
46
+ Author
47
+ :docfile: test.adoc
48
+ :nodoc:
49
+ :no-isobib:
50
+ :function: pizza
50
51
 
51
- text
52
- INPUT
52
+ text
53
+ INPUT
53
54
  expect(File.read("test.err")).to include "pizza is not a recognised document function"
54
- end
55
+ end
55
56
  end
@@ -32,8 +32,8 @@ RSpec.describe IsoDoc::Iec do
32
32
  INPUT
33
33
  html = File.read("test.html", encoding: "utf-8")
34
34
  expect(html).to match(%r[\bpre[^{]+\{[^{]+font-family: "Courier New", monospace;]m)
35
- expect(html).to match(%r[blockquote[^{]+\{[^{]+font-family: "SimSun", serif;]m)
36
- expect(html).to match(%r[\.h2Annex[^{]+\{[^{]+font-family: "SimHei", sans-serif;]m)
35
+ expect(html).to match(%r[blockquote[^{]+\{[^{]+font-family: "Source Han Sans", serif;]m)
36
+ expect(html).to match(%r[\.h2Annex[^{]+\{[^{]+font-family: "Source Han Sans", sans-serif;]m)
37
37
  end
38
38
 
39
39
  it "processes isodoc as ISO: user nominated fonts" do
@@ -27,7 +27,7 @@ RSpec.describe Metanorma::Iec::Processor do
27
27
  expect(xmlpp(strip_guid(processor.input_to_isodoc(<<~"INPUT", nil)))).to be_equivalent_to xmlpp(<<~"OUTPUT")
28
28
  #{ASCIIDOC_BLANK_HDR}
29
29
  INPUT
30
- #{BLANK_HDR}
30
+ #{blank_hdr_gen}
31
31
  <sections/>
32
32
  </iec-standard>
33
33
  OUTPUT
data/spec/spec_helper.rb CHANGED
@@ -112,38 +112,17 @@ TERMS_BOILERPLATE = <<~"BOILERPLATE"
112
112
  </ul>
113
113
  BOILERPLATE
114
114
 
115
- BOILERPLATE =
116
- HTMLEntities.new.decode(
117
- File.read(File.join(File.dirname(__FILE__), "..", "lib", "asciidoctor", "iec", "iec_intro_en.xml"), encoding: "utf-8").
118
- gsub(/\{\{ agency \}\}/, "IEC").gsub(/\{\{ docyear \}\}/, Date.today.year.to_s).
119
- gsub(/\{% if unpublished %\}.*\{% endif %\}/m, "").
120
- gsub(/(?<=\p{Alnum})'(?=\p{Alpha})/, "’").
121
- gsub(/<p>/, "<p id='_'>").
122
- gsub(/<ol>/, "<ol id='_'>").
123
- gsub(/ - /, " — ").
124
- gsub(/\.\.\./, "…")
125
- )
126
-
127
- BOILERPLATE_LICENSE = <<~END
128
- <license-statement>
129
- <clause>
130
- <title>Warning for CDs, CDVs and FDISs</title>
131
- <p id='_'>
132
- This document is not an IEC International Standard. It is distributed
133
- for review and comment. It is subject to change without notice and may
134
- not be referred to as an International Standard.
135
- </p>
136
- <p id='_'>
137
- Recipients of this draft are invited to submit, with their comments,
138
- notification of any relevant patent rights of which they are aware and
139
- to provide supporting documentation.
140
- </p>
141
- </clause>
142
- </license-statement>
143
- END
144
-
145
- UNPUBLISHED_BOILERPLATE = BOILERPLATE.sub(/<\/boilerplate>/, "#{BOILERPLATE_LICENSE}</boilerplate>")
146
-
115
+ def boilerplate(xmldoc)
116
+ file = File.read(File.join(File.dirname(__FILE__), "..", "lib", "asciidoctor", "iec", "iec_intro_en.xml"), encoding: "utf-8")
117
+ conv = Asciidoctor::Iec::Converter.new(nil, backend: :iec, header_footer: true)
118
+ conv.init(Asciidoctor::Document.new [])
119
+ ret = Nokogiri::XML(
120
+ conv.boilerplate_isodoc(xmldoc).populate_template(file, nil).
121
+ gsub(/<p>/, "<p id='_'>").
122
+ gsub(/<ol>/, "<ol id='_'>"))
123
+ conv.smartquotes_cleanup(ret)
124
+ HTMLEntities.new.decode(ret.to_xml)
125
+ end
147
126
 
148
127
  BLANK_HDR = <<~"HDR"
149
128
  <?xml version="1.0" encoding="UTF-8"?>
@@ -189,9 +168,16 @@ BLANK_HDR = <<~"HDR"
189
168
  <stagename>International standard</stagename>
190
169
  </ext>
191
170
  </bibdata>
192
- #{BOILERPLATE}
193
171
  HDR
194
172
 
173
+ def blank_hdr_gen
174
+ <<~"HDR"
175
+ #{BLANK_HDR}
176
+ #{boilerplate(Nokogiri::XML(BLANK_HDR + "</iec-standard>"))}
177
+ HDR
178
+ end
179
+
180
+
195
181
  IEC_TITLE = <<~END
196
182
  <p class="zzSTDTitle1">INTERNATIONAL ELECTROTECHNICAL COMMISSION</p>
197
183
  <p class="zzSTDTitle1">____________</p>
@@ -275,6 +261,12 @@ def stub_fetch_ref(**opts)
275
261
  end.at_least :once
276
262
  end
277
263
 
264
+ def mock_pdf
265
+ allow(::Mn2pdf).to receive(:convert) do |url, output, c, d|
266
+ FileUtils.cp(url.gsub(/"/, ""), output.gsub(/"/, ""))
267
+ end
268
+ end
269
+
278
270
  private
279
271
 
280
272
  def get_xml(search, code, opts)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: metanorma-iec
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.9
4
+ version: 1.2.14
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-11-30 00:00:00.000000000 Z
11
+ date: 2021-02-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ruby-jing
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 1.5.10
33
+ version: 1.7.0
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: 1.5.10
40
+ version: 1.7.0
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: byebug
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -193,7 +193,7 @@ dependencies:
193
193
  - !ruby/object:Gem::Version
194
194
  version: 0.2.0
195
195
  description: |
196
- metanorma-iso lets you write IEC standards in AsciiDoc syntax.
196
+ metanorma-iec lets you write IEC standards in AsciiDoc syntax.
197
197
 
198
198
  This gem is in active development.
199
199
  email:
@@ -249,7 +249,6 @@ files:
249
249
  - lib/isodoc/iec/xref.rb
250
250
  - lib/metanorma-iec.rb
251
251
  - lib/metanorma/iec.rb
252
- - lib/metanorma/iec/fonts_manifest.yaml
253
252
  - lib/metanorma/iec/processor.rb
254
253
  - lib/metanorma/iec/version.rb
255
254
  - metanorma-iec.gemspec
@@ -308,7 +307,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
308
307
  - !ruby/object:Gem::Version
309
308
  version: '0'
310
309
  requirements: []
311
- rubygems_version: 3.0.3
310
+ rubygems_version: 3.1.4
312
311
  signing_key:
313
312
  specification_version: 4
314
313
  summary: metanorma-iec lets you write IEC standards in AsciiDoc.
@@ -1,5 +0,0 @@
1
- ---
2
- Arial:
3
- Times New Roman:
4
- Source Han Sans:
5
- Courier New: