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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 38d5284e3547876d1ad2385d81d10dc9defa3e3669412c30b311fa2dd89857c4
4
- data.tar.gz: e4bf71c720f096a107f2f22e075bb7391d2bdd844e020eb304ac4dc3c0323f29
3
+ metadata.gz: bdcbaef96c6a6ea0bbd2b04bb5266974aa6bec1567061c0e200c0e706b4388af
4
+ data.tar.gz: 361e87aa1151479e66c885d912f78a66749a697f2d93b4464d346e79f0fa193e
5
5
  SHA512:
6
- metadata.gz: 0a992b7f1f3980ee4e57b74cd272b743acd197061e382089edd8fd948e629f5e182f0d66b38848a1efe7c2195c2da5d0dcd790ada393fc3a1bca31dc11fb2a61
7
- data.tar.gz: d085748cc3ac46d3a85861c2533e9d361ece9b4cd4c7f2f18b860e9d19e09abb5c353e612bfadd7a897a59ac1690a77eb8fb611d286194f471b372df7952a53a
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
- # Return the data URI if it already is a data URI
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 = [local_path, relative_path].detect do |p|
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
@@ -1,5 +1,5 @@
1
1
  module Metanorma
2
2
  module Utils
3
- VERSION = "1.4.3".freeze
3
+ VERSION = "1.4.4".freeze
4
4
  end
5
5
  end
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.3
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-13 00:00:00.000000000 Z
11
+ date: 2022-09-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: asciidoctor