metanorma-utils 1.4.4.1 → 1.4.4.2
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 +4 -4
- data/lib/utils/image.rb +5 -3
- data/lib/utils/version.rb +1 -1
- data/spec/img_spec.rb +33 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9e7d4b6d86dedc30058632c7ee8e4ac52f7da75d40ec9f8537410bb2d907ad84
|
4
|
+
data.tar.gz: e0f0cc16ad9d45ef019beb1bbdffa37c65d01dc5e4a7447b9a0ce919eda0a193
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 98028f963be5cc7261afe75ce8ebbecc08df32b16c7783e8a94263453941b3139549367f6baa0576a187aafa2007b400fc76d7e6905a249216866aa9c075466b
|
7
|
+
data.tar.gz: f8e5cb9be34dc02eb56e24c6cd7c3b8e477f89eebdb356d130ad903ce5c12f63fdfcae934ebb859570d01f5ae8b3dda156c96b3e88b290a83540135ef6c1477d
|
data/lib/utils/image.rb
CHANGED
@@ -127,12 +127,14 @@ module Metanorma
|
|
127
127
|
# Check whether just the local path or the other specified relative path
|
128
128
|
# works.
|
129
129
|
def datauri(uri, local_dir = ".")
|
130
|
-
return uri if datauri?(uri) || url?(uri)
|
130
|
+
return uri if datauri?(uri) || url?(uri)
|
131
131
|
|
132
|
-
|
132
|
+
options = absolute_path?(uri) ? [uri] : [uri, File.join(local_dir, uri)]
|
133
|
+
path = options.detect do |p|
|
133
134
|
File.exist?(p) ? p : nil
|
134
135
|
end
|
135
|
-
|
136
|
+
|
137
|
+
unless path
|
136
138
|
warn "Image specified at `#{uri}` does not exist."
|
137
139
|
return uri # Return original provided location
|
138
140
|
end
|
data/lib/utils/version.rb
CHANGED
data/spec/img_spec.rb
CHANGED
@@ -2,6 +2,39 @@ require "spec_helper"
|
|
2
2
|
require "fileutils"
|
3
3
|
|
4
4
|
RSpec.describe Metanorma::Utils do
|
5
|
+
|
6
|
+
context "recognises data uris" do
|
7
|
+
it "where the content is an existing file at a relative path" do
|
8
|
+
expect(Metanorma::Utils.datauri("spec/fixtures/rice_image1.png"))
|
9
|
+
.to eq Metanorma::Utils.encode_datauri('spec/fixtures/rice_image1.png')
|
10
|
+
end
|
11
|
+
|
12
|
+
it "where the content is an existing file at an absolute path" do
|
13
|
+
expect(Metanorma::Utils.datauri(File.expand_path("spec/fixtures/rice_image1.png")))
|
14
|
+
.to eq Metanorma::Utils.encode_datauri('spec/fixtures/rice_image1.png')
|
15
|
+
end
|
16
|
+
|
17
|
+
it "where the content is a relative file path pointing to a bogus file" do
|
18
|
+
expect(Metanorma::Utils.datauri("spec/fixtures/bogus.png"))
|
19
|
+
.to eq "spec/fixtures/bogus.png"
|
20
|
+
end
|
21
|
+
|
22
|
+
it "where the content is an absolute file path pointing to a bogus file" do
|
23
|
+
expect(Metanorma::Utils.datauri("D:/spec/fixtures/bogus.png"))
|
24
|
+
.to eq "D:/spec/fixtures/bogus.png"
|
25
|
+
end
|
26
|
+
|
27
|
+
it "where the content is a data/image URI" do
|
28
|
+
expect(Metanorma::Utils.datauri("data1:img/gif,base64,ABBC"))
|
29
|
+
.to eq "data1:img/gif,base64,ABBC"
|
30
|
+
end
|
31
|
+
|
32
|
+
it "where the content is an URL" do
|
33
|
+
expect(Metanorma::Utils.datauri("https://example.com/image.png"))
|
34
|
+
.to eq "https://example.com/image.png"
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
5
38
|
it "recognises data uris" do
|
6
39
|
expect(Metanorma::Utils.datauri?("data:img/gif,base64,ABBC"))
|
7
40
|
.to eq true
|