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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 57ecf7558228131c734f18189db5fe9579683f11c9f8269f5edf430412054cb2
4
- data.tar.gz: 4762e8db65f0a9e03e6a0c958d3e40968b5194824f1018e5aea0f8aca1096a90
3
+ metadata.gz: 9e7d4b6d86dedc30058632c7ee8e4ac52f7da75d40ec9f8537410bb2d907ad84
4
+ data.tar.gz: e0f0cc16ad9d45ef019beb1bbdffa37c65d01dc5e4a7447b9a0ce919eda0a193
5
5
  SHA512:
6
- metadata.gz: 644939cf2ef17f876d42224505ee084f57d1551ae44573f2792003c52392cd53fb3ae56cc872cba7f32680ca954738fefb1dda4c21d53395e74414c2140326ed
7
- data.tar.gz: 1f159cdbd7c383816693d5e1b4303829f498ba7e47b6af583388c246f736bd80533d26d53e2e1a381f027c7a5340cbf320dc7300eb0ecd766b52482aa7dbfc52
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) || absolute_path?(uri)
130
+ return uri if datauri?(uri) || url?(uri)
131
131
 
132
- path = [uri, File.join(local_dir, uri)].detect do |p|
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
- unless path && File.exist?(path)
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
@@ -1,5 +1,5 @@
1
1
  module Metanorma
2
2
  module Utils
3
- VERSION = "1.4.4.1".freeze
3
+ VERSION = "1.4.4.2".freeze
4
4
  end
5
5
  end
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: metanorma-utils
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.4.1
4
+ version: 1.4.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.