asciidoctor-iso 0.7.9 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/Gemfile.lock +3 -4
- data/README.adoc +18 -0
- data/asciidoctor-iso.gemspec +0 -1
- data/lib/asciidoctor/iso/base.rb +11 -8
- data/lib/asciidoctor/iso/ref.rb +49 -18
- data/lib/asciidoctor/iso/version.rb +1 -1
- data/spec/examples/rice.adoc +1 -0
- data/spec/examples/rice.preview.html +1 -1
- metadata +3 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 6fb0392613b100f479a723613c0b25ed4980b398a5f34a1a751a2a80eea285ee
|
4
|
+
data.tar.gz: 5f4dbd854ae36b9669081ed1a5dbcd4bb64f7fc269bdf4e263d5a3a8cecd2622
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ca833b27a34c5781824ed6b4ac849fd90330224f1d469889708c38f676e8567f7dab9fa3ee078ef08317f9f120141b8a0290e450b1c32dd09742d320e9696160
|
7
|
+
data.tar.gz: 14d7e8590882582d857b3db1a6335850170bb42dee5d2c16b91929b32f258e7d3a41cda87c6c89e71204a99c6183cb1448d07faf7cb0491eb84767afcfabe2f9
|
data/Gemfile.lock
CHANGED
@@ -1,9 +1,8 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
asciidoctor-iso (0.
|
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.
|
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.
|
41
|
+
html2doc (0.8.0)
|
43
42
|
asciimath
|
44
43
|
htmlentities (~> 4.3.4)
|
45
44
|
image_size
|
data/README.adoc
CHANGED
@@ -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.)
|
data/asciidoctor-iso.gemspec
CHANGED
data/lib/asciidoctor/iso/base.rb
CHANGED
@@ -82,7 +82,10 @@ module Asciidoctor
|
|
82
82
|
@novalid = node.attr("novalid")
|
83
83
|
@fontheader = default_fonts(node)
|
84
84
|
@files_to_delete = []
|
85
|
-
@
|
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
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
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
|
|
data/lib/asciidoctor/iso/ref.rb
CHANGED
@@ -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
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
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
|
-
|
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
|
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
|
-
|
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
|
112
|
+
return first_with_title(result)
|
103
113
|
end
|
104
114
|
|
105
|
-
def
|
106
|
-
|
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
|
-
|
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}/.
|
231
|
+
def bibliocache_name(global)
|
232
|
+
global ? "#{Dir.home}/.relaton-bib.json" :
|
233
|
+
"#{@filename}.relaton.json"
|
206
234
|
end
|
207
235
|
|
208
|
-
|
209
|
-
|
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
|
-
|
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
|
data/spec/examples/rice.adoc
CHANGED
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.
|
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-
|
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.
|
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.
|