metanorma-utils 1.4.3 → 1.4.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/utils/image.rb +11 -12
- data/lib/utils/version.rb +1 -1
- data/spec/img_spec.rb +9 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bdcbaef96c6a6ea0bbd2b04bb5266974aa6bec1567061c0e200c0e706b4388af
|
4
|
+
data.tar.gz: 361e87aa1151479e66c885d912f78a66749a697f2d93b4464d346e79f0fa193e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4ac44af9556e50ca2f7e7a1b197e3f9da3f80d27bf19545adc97e4ab77b7a082b033b06dc1d275bfcf06ea53dcacdc0d6422f36b732d48b46267f6ee0bc6a4f6
|
7
|
+
data.tar.gz: 8eeae386f6fbaba0ab910f389fa1122b7559bce68c01215fa7485f392044b9f8fb4c2d6ec11da09245b65a257744737b98a231f551c5b64ddd5f1a46e120fcae
|
data/lib/utils/image.rb
CHANGED
@@ -21,7 +21,7 @@ module Metanorma
|
|
21
21
|
end
|
22
22
|
|
23
23
|
def save_dataimage(uri)
|
24
|
-
%r{^data:(image|application)/(?<imgtype>[^;]+);(charset=[^;]+;)?base64,(?<imgdata>.+)$} =~ uri
|
24
|
+
%r{^data:(?:image|application)/(?<imgtype>[^;]+);(?:charset=[^;]+;)?base64,(?<imgdata>.+)$} =~ uri
|
25
25
|
imgtype.sub!(/\+[a-z0-9]+$/, "") # svg+xml
|
26
26
|
imgtype = "png" unless /^[a-z0-9]+$/.match? imgtype
|
27
27
|
Tempfile.open(["image", ".#{imgtype}"]) do |f|
|
@@ -125,25 +125,20 @@ module Metanorma
|
|
125
125
|
# sources/plantuml/plantuml20200524-90467-1iqek5i.png
|
126
126
|
# already includes localdir
|
127
127
|
def datauri(uri, local_dir = ".")
|
128
|
-
|
129
|
-
return uri if datauri?(uri)
|
130
|
-
|
131
|
-
# Return the URL if it is a URL
|
132
|
-
return uri if url?(uri)
|
133
|
-
|
134
|
-
local_path = uri
|
135
|
-
relative_path = File.join(local_dir, uri)
|
128
|
+
return uri if datauri?(uri) || url?(uri) || absolute_path?(uri)
|
136
129
|
|
137
130
|
# Check whether just the local path or the other specified relative path
|
138
131
|
# works.
|
139
|
-
path = [
|
132
|
+
path = [uri, File.join(local_dir, uri)].detect do |p|
|
140
133
|
File.exist?(p) ? p : nil
|
141
134
|
end
|
135
|
+
datauri1(path)
|
136
|
+
end
|
142
137
|
|
138
|
+
def datauri1(path)
|
143
139
|
unless path && File.exist?(path)
|
144
140
|
warn "Image specified at `#{uri}` does not exist."
|
145
|
-
# Return original provided location
|
146
|
-
return uri
|
141
|
+
return uri # Return original provided location
|
147
142
|
end
|
148
143
|
|
149
144
|
encode_datauri(path)
|
@@ -171,6 +166,10 @@ module Metanorma
|
|
171
166
|
%r{^[A-Z]{2,}://}i.match?(url)
|
172
167
|
end
|
173
168
|
|
169
|
+
def absolute_path?(uri)
|
170
|
+
%r{^/}.match?(uri) || %r{^[A-Z]:/}.match?(uri)
|
171
|
+
end
|
172
|
+
|
174
173
|
def decode_datauri(uri)
|
175
174
|
%r{^data:(?<mimetype>[^;]+);base64,(?<mimedata>.+)$} =~ uri
|
176
175
|
return nil unless mimetype && mimedata
|
data/lib/utils/version.rb
CHANGED
data/spec/img_spec.rb
CHANGED
@@ -20,6 +20,15 @@ RSpec.describe Metanorma::Utils do
|
|
20
20
|
.to eq false
|
21
21
|
end
|
22
22
|
|
23
|
+
it "recognises absolute file locations" do
|
24
|
+
expect(Metanorma::Utils.absolute_path?("D:/a.html"))
|
25
|
+
.to eq true
|
26
|
+
expect(Metanorma::Utils.absolute_path?("/a.html"))
|
27
|
+
.to eq true
|
28
|
+
expect(Metanorma::Utils.absolute_path?("a.html"))
|
29
|
+
.to eq false
|
30
|
+
end
|
31
|
+
|
23
32
|
it "rewrites SVGs" do
|
24
33
|
FileUtils.cp("spec/fixtures/action_schemaexpg1.svg",
|
25
34
|
"action_schemaexpg1.svg")
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: metanorma-utils
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.4.
|
4
|
+
version: 1.4.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ribose Inc.
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-09-
|
11
|
+
date: 2022-09-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: asciidoctor
|