metanorma-iec 1.3.6 → 1.3.10

Sign up to get free protection for your applications and to get access to all the features.
data/spec/spec_helper.rb CHANGED
@@ -25,216 +25,224 @@ RSpec.configure do |config|
25
25
  end
26
26
  end
27
27
 
28
- def metadata(x)
29
- Hash[x.sort].delete_if{ |k, v| v.nil? || v.respond_to?(:empty?) && v.empty? }
28
+ def metadata(xml)
29
+ xml.sort.to_h.delete_if do |_k, v|
30
+ v.nil? || v.respond_to?(:empty?) && v.empty?
31
+ end
30
32
  end
31
33
 
32
- def strip_guid(x)
33
- x.gsub(%r{ id="_[^"]+"}, ' id="_"').gsub(%r{ target="_[^"]+"}, ' target="_"')
34
+ def strip_guid(xml)
35
+ xml.gsub(%r{ id="_[^"]+"}, ' id="_"').gsub(%r{ target="_[^"]+"},
36
+ ' target="_"')
34
37
  end
35
38
 
36
- def xmlpp(x)
39
+ def xmlpp(xml)
37
40
  s = ""
38
41
  f = REXML::Formatters::Pretty.new(2)
39
42
  f.compact = true
40
- f.write(REXML::Document.new(x),s)
43
+ f.write(REXML::Document.new(xml), s)
41
44
  s
42
45
  end
43
46
 
44
- ASCIIDOC_BLANK_HDR = <<~"HDR"
45
- = Document title
46
- Author
47
- :docfile: test.adoc
48
- :nodoc:
49
- :novalid:
50
- :no-isobib:
47
+ OPTIONS = [backend: :iec, header_footer: true, agree_to_terms: true].freeze
48
+
49
+ ASCIIDOC_BLANK_HDR = <<~"HDR".freeze
50
+ = Document title
51
+ Author
52
+ :docfile: test.adoc
53
+ :nodoc:
54
+ :novalid:
55
+ :no-isobib:
51
56
 
52
57
  HDR
53
58
 
54
- ISOBIB_BLANK_HDR = <<~"HDR"
55
- = Document title
56
- Author
57
- :docfile: test.adoc
58
- :nodoc:
59
- :novalid:
60
- :no-isobib-cache:
59
+ ISOBIB_BLANK_HDR = <<~"HDR".freeze
60
+ = Document title
61
+ Author
62
+ :docfile: test.adoc
63
+ :nodoc:
64
+ :novalid:
65
+ :no-isobib-cache:
61
66
 
62
67
  HDR
63
68
 
64
- FLUSH_CACHE_ISOBIB_BLANK_HDR = <<~"HDR"
65
- = Document title
66
- Author
67
- :docfile: test.adoc
68
- :nodoc:
69
- :novalid:
70
- :flush-caches:
69
+ FLUSH_CACHE_ISOBIB_BLANK_HDR = <<~"HDR".freeze
70
+ = Document title
71
+ Author
72
+ :docfile: test.adoc
73
+ :nodoc:
74
+ :novalid:
75
+ :flush-caches:
71
76
 
72
77
  HDR
73
78
 
74
- CACHED_ISOBIB_BLANK_HDR = <<~"HDR"
75
- = Document title
76
- Author
77
- :docfile: test.adoc
78
- :nodoc:
79
- :novalid:
79
+ CACHED_ISOBIB_BLANK_HDR = <<~"HDR".freeze
80
+ = Document title
81
+ Author
82
+ :docfile: test.adoc
83
+ :nodoc:
84
+ :novalid:
80
85
 
81
86
  HDR
82
87
 
83
- LOCAL_CACHED_ISOBIB_BLANK_HDR = <<~"HDR"
84
- = Document title
85
- Author
86
- :docfile: test.adoc
87
- :nodoc:
88
- :novalid:
89
- :local-cache:
88
+ LOCAL_CACHED_ISOBIB_BLANK_HDR = <<~"HDR".freeze
89
+ = Document title
90
+ Author
91
+ :docfile: test.adoc
92
+ :nodoc:
93
+ :novalid:
94
+ :local-cache:
90
95
 
91
96
  HDR
92
97
 
93
- VALIDATING_BLANK_HDR = <<~"HDR"
94
- = Document title
95
- Author
96
- :docfile: test.adoc
97
- :nodoc:
98
- :no-isobib:
98
+ VALIDATING_BLANK_HDR = <<~"HDR".freeze
99
+ = Document title
100
+ Author
101
+ :docfile: test.adoc
102
+ :nodoc:
103
+ :no-isobib:
99
104
 
100
105
  HDR
101
106
 
102
- TERMS_BOILERPLATE = <<~"BOILERPLATE"
103
- <p id="_">ISO and IEC maintain terminological databases for use in
104
- standardization at the following addresses:</p>
105
-
106
- <ul id="_">
107
- <li> <p id="_">IEC Electropedia: available at
108
- <link target="http://www.electropedia.org"/>
109
- </p> </li>
110
- <li> <p id="_">ISO Online browsing platform: available at
111
- <link target="http://www.iso.org/obp"/></p> </li>
112
- </ul>
107
+ TERMS_BOILERPLATE = <<~"BOILERPLATE".freeze
108
+ <p id="_">ISO and IEC maintain terminological databases for use in
109
+ standardization at the following addresses:</p>
110
+ #{' '}
111
+ <ul id="_">
112
+ <li> <p id="_">IEC Electropedia: available at
113
+ <link target="http://www.electropedia.org"/>
114
+ </p> </li>#{' '}
115
+ <li> <p id="_">ISO Online browsing platform: available at
116
+ <link target="http://www.iso.org/obp"/></p> </li>
117
+ </ul>
113
118
  BOILERPLATE
114
119
 
115
120
  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 [])
121
+ file = File.read(
122
+ File.join(File.dirname(__FILE__), "..", "lib", "asciidoctor", "iec",
123
+ "iec_intro_en.xml"), encoding: "utf-8"
124
+ )
125
+ conv = Asciidoctor::Iec::Converter.new(nil, backend: :iec,
126
+ header_footer: true)
127
+ conv.init(Asciidoctor::Document.new([]))
119
128
  ret = Nokogiri::XML(
120
- conv.boilerplate_isodoc(xmldoc).populate_template(file, nil).
121
- gsub(/<p>/, "<p id='_'>").
122
- gsub(/<ol>/, "<ol id='_'>"))
129
+ conv.boilerplate_isodoc(xmldoc).populate_template(file, nil)
130
+ .gsub(/<p>/, "<p id='_'>")
131
+ .gsub(/<ol>/, "<ol id='_'>"),
132
+ )
123
133
  conv.smartquotes_cleanup(ret)
124
134
  HTMLEntities.new.decode(ret.to_xml)
125
135
  end
126
136
 
127
- BLANK_HDR = <<~"HDR"
128
- <?xml version="1.0" encoding="UTF-8"?>
129
- <iec-standard xmlns="https://www.metanorma.org/ns/iec" type="semantic" version="#{Metanorma::Iec::VERSION}">
130
- <bibdata type="standard">
131
- <contributor>
132
- <role type="author"/>
133
- <organization>
134
- <name>International Electrotechnical Commission</name>
135
- <abbreviation>IEC</abbreviation>
136
- </organization>
137
- </contributor>
138
- <contributor>
139
- <role type="publisher"/>
140
- <organization>
141
- <name>International Electrotechnical Commission</name>
142
- <abbreviation>IEC</abbreviation>
143
- </organization>
144
- </contributor>
145
- <language>en</language>
146
- <script>Latn</script>
147
- <status>
148
- <stage abbreviation="PPUB">60</stage>
149
- <substage abbreviation="PPUB">60</substage>
150
- </status>
151
- <copyright>
152
- <from>#{Time.new.year}</from>
153
- <owner>
137
+ BLANK_HDR = <<~"HDR".freeze
138
+ <?xml version="1.0" encoding="UTF-8"?>
139
+ <iec-standard xmlns="https://www.metanorma.org/ns/iec" type="semantic" version="#{Metanorma::Iec::VERSION}">
140
+ <bibdata type="standard">
141
+ <contributor>
142
+ <role type="author"/>
143
+ <organization>
144
+ <name>International Electrotechnical Commission</name>
145
+ <abbreviation>IEC</abbreviation>
146
+ </organization>
147
+ </contributor>
148
+ <contributor>
149
+ <role type="publisher"/>
154
150
  <organization>
155
151
  <name>International Electrotechnical Commission</name>
156
152
  <abbreviation>IEC</abbreviation>
157
153
  </organization>
158
- </owner>
159
- </copyright>
160
- <ext>
161
- <doctype>article</doctype>
162
- <horizontal>false</horizontal>
163
- <editorialgroup>
164
- <technical-committee/>
165
- <subcommittee/>
166
- <workgroup/>
167
- </editorialgroup>
168
- <stagename>International standard</stagename>
169
- </ext>
170
- </bibdata>
154
+ </contributor>
155
+ <language>en</language>
156
+ <script>Latn</script>
157
+ <status>
158
+ <stage abbreviation="PPUB">60</stage>
159
+ <substage abbreviation="PPUB">60</substage>
160
+ </status>
161
+ <copyright>
162
+ <from>#{Time.new.year}</from>
163
+ <owner>
164
+ <organization>
165
+ <name>International Electrotechnical Commission</name>
166
+ <abbreviation>IEC</abbreviation>
167
+ </organization>
168
+ </owner>
169
+ </copyright>
170
+ <ext>
171
+ <doctype>article</doctype>
172
+ <horizontal>false</horizontal>
173
+ <editorialgroup>
174
+ <technical-committee/>
175
+ <subcommittee/>
176
+ <workgroup/>
177
+ </editorialgroup>
178
+ <stagename>International standard</stagename>
179
+ </ext>
180
+ </bibdata>
171
181
  HDR
172
182
 
173
183
  def blank_hdr_gen
174
- <<~"HDR"
175
- #{BLANK_HDR}
176
- #{boilerplate(Nokogiri::XML(BLANK_HDR + "</iec-standard>"))}
177
- HDR
184
+ <<~"HDR"
185
+ #{BLANK_HDR}
186
+ #{boilerplate(Nokogiri::XML("#{BLANK_HDR}</iec-standard>"))}
187
+ HDR
178
188
  end
179
189
 
190
+ IEC_TITLE = <<~TITLE.freeze
191
+ <p class="zzSTDTitle1">INTERNATIONAL ELECTROTECHNICAL COMMISSION</p>
192
+ <p class="zzSTDTitle1">____________</p>
193
+ <p class="zzSTDTitle1">&#160;</p>
194
+ <p class="zzSTDTitle1">
195
+ <b/>
196
+ </p>
197
+ <p class="zzSTDTitle1">&#160;</p>
198
+ TITLE
199
+
200
+ IEC_TITLE1 = <<~TITLE.freeze
201
+ <p class="zzSTDTitle1">
202
+ <b/>
203
+ </p>
204
+ <p class="zzSTDTitle1">&#160;</p>
205
+ TITLE
206
+
207
+ HTML_HDR = <<~HDR.freeze
208
+ <html xmlns:epub="http://www.idpf.org/2007/ops" lang="en">
209
+ <head/>
210
+ <body lang="en">
211
+ <div class="title-section">
212
+ <p>&#160;</p>
213
+ </div>
214
+ <br/>
215
+ <div class="prefatory-section">
216
+ <p>&#160;</p>
217
+ </div>
218
+ <br/>
219
+ <div class="main-section">
220
+ <br/>
221
+ #{IEC_TITLE}
222
+ HDR
180
223
 
181
- IEC_TITLE = <<~END
182
- <p class="zzSTDTitle1">INTERNATIONAL ELECTROTECHNICAL COMMISSION</p>
183
- <p class="zzSTDTitle1">____________</p>
184
- <p class="zzSTDTitle1">&#160;</p>
185
- <p class="zzSTDTitle1">
186
- <b/>
187
- </p>
188
- <p class="zzSTDTitle1">&#160;</p>
189
- END
190
-
191
- IEC_TITLE1 = <<~END
192
- <p class="zzSTDTitle1">
193
- <b/>
194
- </p>
195
- <p class="zzSTDTitle1">&#160;</p>
196
- END
197
-
198
- HTML_HDR = <<~END
199
- <html xmlns:epub="http://www.idpf.org/2007/ops" lang="en">
200
- <head/>
201
- <body lang="en">
202
- <div class="title-section">
203
- <p>&#160;</p>
204
- </div>
205
- <br/>
206
- <div class="prefatory-section">
207
- <p>&#160;</p>
208
- </div>
209
- <br/>
210
- <div class="main-section">
211
- <br/>
212
- #{IEC_TITLE}
213
- END
214
-
215
- WORD_HDR = <<~END
216
- <html xmlns:epub="http://www.idpf.org/2007/ops">
217
- <head>
218
- <title>test</title>
219
- </head>
220
- <body lang="EN-US" link="blue" vlink="#954F72">
221
- <div class="WordSection1">
222
- <p>&#160;</p>
223
- </div>
224
- <p><br clear="all" class="section"/></p>
225
- <div class="WordSection2">
226
- <p>&#160;</p>
227
- </div>
228
- <p><br clear="all" class="section"/></p>
229
- <div class="WordSection3">
230
- END
231
-
224
+ WORD_HDR = <<~HDR.freeze
225
+ <html xmlns:epub="http://www.idpf.org/2007/ops">
226
+ <head>
227
+ <title>test</title>
228
+ </head>
229
+ <body lang="EN-US" link="blue" vlink="#954F72">
230
+ <div class="WordSection1">
231
+ <p>&#160;</p>
232
+ </div>
233
+ <p><br clear="all" class="section"/></p>
234
+ <div class="WordSection2">
235
+ <p>&#160;</p>
236
+ </div>
237
+ <p><br clear="all" class="section"/></p>
238
+ <div class="WordSection3">
239
+ HDR
232
240
 
233
241
  def stub_fetch_ref(**opts)
234
242
  xml = ""
235
243
 
236
244
  hit = double("hit")
237
- expect(hit).to receive(:"[]").with("title") do
245
+ expect(hit).to receive(:[]).with("title") do
238
246
  Nokogiri::XML(xml).at("//docidentifier").content
239
247
  end.at_least(:once)
240
248
 
@@ -252,8 +260,8 @@ def stub_fetch_ref(**opts)
252
260
  hit_pages = double("hit_pages")
253
261
  expect(hit_pages).to receive(:first).and_return(hit_page).at_least :once
254
262
 
255
- expect(Isobib::IsoBibliography).to receive(:search).
256
- and_wrap_original do |search, *args|
263
+ expect(Isobib::IsoBibliography).to receive(:search)
264
+ .and_wrap_original do |search, *args|
257
265
  code = args[0]
258
266
  expect(code).to be_instance_of String
259
267
  xml = get_xml(search, code, opts)
@@ -262,7 +270,7 @@ def stub_fetch_ref(**opts)
262
270
  end
263
271
 
264
272
  def mock_pdf
265
- allow(::Mn2pdf).to receive(:convert) do |url, output, c, d|
273
+ allow(::Mn2pdf).to receive(:convert) do |url, output, _c, _d|
266
274
  FileUtils.cp(url.gsub(/"/, ""), output.gsub(/"/, ""))
267
275
  end
268
276
  end
@@ -270,7 +278,7 @@ end
270
278
  private
271
279
 
272
280
  def get_xml(search, code, opts)
273
- c = code.gsub(%r{[\/\s:-]}, "_").sub(%r{_+$}, "").downcase
281
+ c = code.gsub(%r{[/\s:-]}, "_").sub(%r{_+$}, "").downcase
274
282
  o = opts.keys.join "_"
275
283
  file = "spec/examples/#{[c, o].join '_'}.xml"
276
284
  if File.exist? file
@@ -285,11 +293,10 @@ def get_xml(search, code, opts)
285
293
  end
286
294
 
287
295
  def mock_open_uri(code)
288
- #expect(OpenURI).to receive(:open_uri).and_wrap_original do |m, *args|
296
+ # expect(OpenURI).to receive(:open_uri).and_wrap_original do |m, *args|
289
297
  expect(Iev).to receive(:get).with(code, "en") do |m, *args|
290
298
  file = "spec/examples/#{code.tr('-', '_')}.html"
291
299
  File.write file, m.call(*args).read unless File.exist? file
292
300
  File.read file
293
301
  end.at_least :once
294
302
  end
295
-
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.3.6
4
+ version: 1.3.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-07-05 00:00:00.000000000 Z
11
+ date: 2021-08-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: metanorma-iso
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 1.8.6
19
+ version: 1.9.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 1.8.6
26
+ version: 1.9.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: ruby-jing
29
29
  requirement: !ruby/object:Gem::Requirement