asciidoctor-iso 0.7.9 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 355ac496fa1884cb8267d3c92d91131898ef9d1c
4
- data.tar.gz: 6a6ddf721d8ac3166b7c99ed4d65271615a95f3f
2
+ SHA256:
3
+ metadata.gz: 6fb0392613b100f479a723613c0b25ed4980b398a5f34a1a751a2a80eea285ee
4
+ data.tar.gz: 5f4dbd854ae36b9669081ed1a5dbcd4bb64f7fc269bdf4e263d5a3a8cecd2622
5
5
  SHA512:
6
- metadata.gz: 5798a56948f8731274adce9a0942b422958fbd6b776a45d6243e0c1c4be48f83f1f570692dd03a7b3131f3869310ecc78d153aaea4e135ad0c42c16341e54fb2
7
- data.tar.gz: 471c24e1688fd6ca6aec9f1f3b55d113f0838ac54f6c1891cf28a2775c0370d7a7d1f0722d4c786d3ac43aba423fa18dca7d184e9b70a413bbbd7a2c03713865
6
+ metadata.gz: ca833b27a34c5781824ed6b4ac849fd90330224f1d469889708c38f676e8567f7dab9fa3ee078ef08317f9f120141b8a0290e450b1c32dd09742d320e9696160
7
+ data.tar.gz: 14d7e8590882582d857b3db1a6335850170bb42dee5d2c16b91929b32f258e7d3a41cda87c6c89e71204a99c6183cb1448d07faf7cb0491eb84767afcfabe2f9
@@ -1,9 +1,8 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- asciidoctor-iso (0.7.8)
4
+ asciidoctor-iso (0.8.0)
5
5
  asciidoctor (~> 1.5.7)
6
- html2doc
7
6
  isobib (~> 0.1.4)
8
7
  isodoc (~> 0.6.2)
9
8
  ruby-jing
@@ -23,7 +22,7 @@ GEM
23
22
  docile (1.3.1)
24
23
  equivalent-xml (0.6.0)
25
24
  nokogiri (>= 1.4.3)
26
- ffi (1.9.23)
25
+ ffi (1.9.24)
27
26
  formatador (0.2.5)
28
27
  guard (2.14.2)
29
28
  formatador (>= 0.2.4)
@@ -39,7 +38,7 @@ GEM
39
38
  guard (~> 2.1)
40
39
  guard-compat (~> 1.1)
41
40
  rspec (>= 2.99.0, < 4.0)
42
- html2doc (0.7.1)
41
+ html2doc (0.8.0)
43
42
  asciimath
44
43
  htmlentities (~> 4.3.4)
45
44
  image_size
@@ -516,6 +516,18 @@ any item label prefixed with `ISO` on the ISO web site. The full bibliographic d
516
516
  of the item are screenscraped from the ISO site and inserted into the XML file
517
517
  (although only the title of the reference is used in rendering).
518
518
 
519
+ [[cache]]
520
+ The results of all `isobib` searches done to date, across all documents,
521
+ are cached in the global cache file `~/.relaton-bib.json`,
522
+ so they do not need to be re-fetched each time a document is processed.
523
+ (The web query takes a few seconds per reference.)
524
+
525
+ The results of all `isobib` searches done to date for the current document
526
+ (`filename.adoc`) are stored in the same directory as the current document,
527
+ in the file `filename`.relaton.json. The local cache overrides entries in
528
+ the global cache, and can be manually edited. The local cache is only used
529
+ if the `:local-cache:` document attribute is set.
530
+
519
531
  == Document Attributes
520
532
 
521
533
  The gem relies on Asciidoctor document attributes to provide necessary
@@ -527,6 +539,12 @@ Can be used as a command-line option (like all other document attributes):
527
539
 
528
540
  `:novalid:`:: Suppress validation.
529
541
 
542
+ `:flush-caches:`:: If set, delete and reinitialise the <<cache,cache>> of `isobib` searches
543
+ for ISO references from the ISO web site.
544
+
545
+ `:local-cache:`:: Use the local isobib search cache to override the global isobib search
546
+ cache.
547
+
530
548
  `:i18nyaml:`:: Name of YAML file of internationalisation text, to use instead
531
549
  of the built-in English, French or Chinese text used to label parts of the document
532
550
  (e.g. "Table", "Foreword", boilerplate text for Normative References, etc.)
@@ -29,7 +29,6 @@ Gem::Specification.new do |spec|
29
29
 
30
30
  spec.add_dependency "asciidoctor", "~> 1.5.7"
31
31
  spec.add_dependency "ruby-jing"
32
- spec.add_dependency "html2doc"
33
32
  spec.add_dependency "isodoc", "~> 0.6.2"
34
33
  spec.add_dependency "isobib", "~> 0.1.4"
35
34
 
@@ -82,7 +82,10 @@ module Asciidoctor
82
82
  @novalid = node.attr("novalid")
83
83
  @fontheader = default_fonts(node)
84
84
  @files_to_delete = []
85
- @bibliodb = open_cache_biblio(node)
85
+ @filename = node.attr("docfile").gsub(/\.adoc$/, "").gsub(%r{^.*/}, "")
86
+ @bibliodb = open_cache_biblio(node, true)
87
+ @local_bibliodb = node.attr("local-cache") ?
88
+ open_cache_biblio(node, false) : nil
86
89
  end
87
90
 
88
91
  def default_fonts(node)
@@ -100,12 +103,11 @@ module Asciidoctor
100
103
  init(node)
101
104
  ret = makexml(node).to_xml(indent: 2)
102
105
  unless node.attr("nodoc") || !node.attr("docfile")
103
- filename = node.attr("docfile").gsub(/\.adoc$/, "").gsub(%r{^.*/}, "")
104
- File.open(filename + ".xml", "w") { |f| f.write(ret) }
105
- html_converter_alt(node).convert(filename + ".xml")
106
- system "mv #{filename}.html #{filename}_alt.html"
107
- html_converter(node).convert(filename + ".xml")
108
- doc_converter(node).convert(filename + ".xml")
106
+ File.open(@filename + ".xml", "w") { |f| f.write(ret) }
107
+ html_converter_alt(node).convert(@filename + ".xml")
108
+ system "mv #{@filename}.html #{@filename}_alt.html"
109
+ html_converter(node).convert(@filename + ".xml")
110
+ doc_converter(node).convert(@filename + ".xml")
109
111
  end
110
112
  @files_to_delete.each { |f| system "rm #{f}" }
111
113
  ret
@@ -116,7 +118,8 @@ module Asciidoctor
116
118
  result << noko { |ixml| front node, ixml }
117
119
  result << noko { |ixml| middle node, ixml }
118
120
  result << "</iso-standard>"
119
- save_cache_biblio(@bibliodb)
121
+ save_cache_biblio(@bibliodb, true)
122
+ save_cache_biblio(@local_bibliodb, false)
120
123
  textcleanup(result.flatten * "\n")
121
124
  end
122
125
 
@@ -35,7 +35,7 @@ module Asciidoctor
35
35
  end
36
36
 
37
37
  def use_my_anchor(ref, id)
38
- ref.parent["id"] = id
38
+ ref.parent.children.last["id"] = id
39
39
  ref
40
40
  end
41
41
 
@@ -82,28 +82,46 @@ module Asciidoctor
82
82
  def fetch_year_check(hit, code, year, opts)
83
83
  ret =nil
84
84
  if year.nil? || year.to_i == hit.hit["year"]
85
- ret = hit.to_xml opts
86
- @bibliodb[code] = ret
87
- else
88
- warn "WARNING: cited year #{year} does not match year "\
85
+ ret = hit.to_xml opts
86
+ @bibliodb[code] = ret if @bibliodb
87
+ @local_bibliodb[code] = ret if @local_bibliodb
88
+ else
89
+ warn "WARNING: cited year #{year} does not match year "\
89
90
  "#{hit.hit['year']} found on the ISO website for #{code}"
90
- end
91
+ end
91
92
  ret
92
93
  end
93
94
 
95
+ def first_with_title(result)
96
+ result.first.each do |x|
97
+ next unless x.hit["title"]
98
+ return x
99
+ end
100
+ return nil
101
+ end
102
+
94
103
  def first_year_match_hit(result, code, year)
95
- return result&.first&.first if year.nil?
104
+ return first_with_title(result) if year.nil?
96
105
  return nil unless result.first && result.first.is_a?(Array)
97
106
  coderegex = %r{^(ISO|IEC)[^0-9]*\s[0-9-]+}
98
107
  result.first.each do |x|
99
- return x if x.hit["title"]&.match(coderegex)&.to_s == code &&
108
+ next unless x.hit["title"]
109
+ return x if x.hit["title"].match(coderegex).to_s == code &&
100
110
  year.to_i == x.hit["year"]
101
111
  end
102
- return result&.first&.first
112
+ return first_with_title(result)
103
113
  end
104
114
 
105
- def fetch_ref1(code, year, opts)
106
- return @bibliodb[code] if @bibliodb[code]
115
+ def fetch_ref_err(code)
116
+ warn "WARNING: no match found on the ISO website for #{code}."
117
+ if /\d-\d/.match? code
118
+ warn "The provided document part may not exist, or the document may no longer be published in parts."
119
+ else
120
+ warn "If you wanted to cite all document parts for the reference, use #{code}:All Parts"
121
+ end
122
+ end
123
+
124
+ def fetch_ref2(code, year, opts)
107
125
  result = Isobib::IsoBibliography.search(code)
108
126
  ret = nil
109
127
  hit = first_year_match_hit(result, code, year)
@@ -111,11 +129,20 @@ module Asciidoctor
111
129
  if hit && hit.hit["title"]&.match(coderegex)&.to_s == code
112
130
  ret = fetch_year_check(hit, code, year, opts)
113
131
  else
114
- warn "WARNING: no match found on the ISO website for #{code}"
132
+ fetch_ref_err(code)
115
133
  end
116
134
  ret
117
135
  end
118
136
 
137
+ def fetch_ref1(code, year, opts)
138
+ return nil if @bibliodb.nil? # signals we will not be using isobib
139
+ @bibliodb[code] = fetch_ref2(code, year, opts) unless @bibliodb[code]
140
+ @local_bibliodb[code] = @bibliodb[code] if !@local_bibliodb.nil? &&
141
+ !@local_bibliodb[code]
142
+ return @local_bibliodb[code] unless @local_bibliodb.nil?
143
+ @bibliodb[code]
144
+ end
145
+
119
146
  def fetch_ref(xml, code, year, **opts)
120
147
  warn "fetching #{code}..."
121
148
  hit = fetch_ref1(code, year, opts)
@@ -201,12 +228,15 @@ module Asciidoctor
201
228
  end.join("\n")
202
229
  end
203
230
 
204
- def bibliocache_name()
205
- "#{Dir.home}/.asciidoc-iso-biblio-cache.json"
231
+ def bibliocache_name(global)
232
+ global ? "#{Dir.home}/.relaton-bib.json" :
233
+ "#{@filename}.relaton.json"
206
234
  end
207
235
 
208
- def open_cache_biblio(node)
209
- filename = bibliocache_name()
236
+ # if returns nil, then biblio caching is disabled, and so is use of isobib
237
+ def open_cache_biblio(node, global)
238
+ return nil # disabling for now
239
+ filename = bibliocache_name(global)
210
240
  system("rm -f #{filename}") if node.attr("flush-caches") == "true"
211
241
  biblio = {}
212
242
  if Pathname.new(filename).file?
@@ -217,8 +247,9 @@ module Asciidoctor
217
247
  biblio
218
248
  end
219
249
 
220
- def save_cache_biblio(biblio)
221
- filename = bibliocache_name()
250
+ def save_cache_biblio(biblio, global)
251
+ return if biblio.nil?
252
+ filename = bibliocache_name(global)
222
253
  File.open(filename, "w") do |b|
223
254
  b << biblio.to_json
224
255
  end
@@ -1,5 +1,5 @@
1
1
  module Asciidoctor
2
2
  module ISO
3
- VERSION = "0.7.9".freeze
3
+ VERSION = "0.8.0".freeze
4
4
  end
5
5
  end
@@ -32,6 +32,7 @@
32
32
  :section-refsig: Clause
33
33
  :table-caption: Table
34
34
  :example-caption: Figure
35
+ :local-cache:
35
36
 
36
37
  [[foreword]]
37
38
  .Foreword
@@ -1854,7 +1854,7 @@ end</code></pre>
1854
1854
  </div>
1855
1855
  <div id="footer">
1856
1856
  <div id="footer-text">
1857
- Last updated 2018-06-01 23:15:41 AEST
1857
+ Last updated 2018-06-02 22:16:39 AEST
1858
1858
  </div>
1859
1859
  </div>
1860
1860
  <script type="text/x-mathjax-config">
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: asciidoctor-iso
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.9
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-06-02 00:00:00.000000000 Z
11
+ date: 2018-06-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: asciidoctor
@@ -38,20 +38,6 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
- - !ruby/object:Gem::Dependency
42
- name: html2doc
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - ">="
46
- - !ruby/object:Gem::Version
47
- version: '0'
48
- type: :runtime
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - ">="
53
- - !ruby/object:Gem::Version
54
- version: '0'
55
41
  - !ruby/object:Gem::Dependency
56
42
  name: isodoc
57
43
  requirement: !ruby/object:Gem::Requirement
@@ -330,7 +316,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
330
316
  version: '0'
331
317
  requirements: []
332
318
  rubyforge_project:
333
- rubygems_version: 2.6.14
319
+ rubygems_version: 2.7.7
334
320
  signing_key:
335
321
  specification_version: 4
336
322
  summary: asciidoctor-iso lets you write ISO standards in AsciiDoc.