metanorma-utils 1.4.2 → 1.4.4

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: fd1e58ea4dadd1ad26ad1b254805c2c831914a1177b0e75ea166117a3c1a4e99
4
- data.tar.gz: 1479bd090933fc9e861f3b9aba780fa18fe863ddfa923ddcee7caa148956f754
3
+ metadata.gz: bdcbaef96c6a6ea0bbd2b04bb5266974aa6bec1567061c0e200c0e706b4388af
4
+ data.tar.gz: 361e87aa1151479e66c885d912f78a66749a697f2d93b4464d346e79f0fa193e
5
5
  SHA512:
6
- metadata.gz: c4578a2d2450368c92cec783b297ab5c5ba921e3644dc6078b6df66af58b0a74f56e6e800d2d01322f8af6b95ebf3c2834076528308845aaca612ed851108990
7
- data.tar.gz: 343f2b25137e40335e56ce82f00297294f6f33a956d7bec3ccb76ad012d31a8594d78a31143919060d05fe6edfa2a3a39f06183548e2b9a671cb3f97a310d6c8
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)
@@ -168,7 +163,11 @@ module Metanorma
168
163
  end
169
164
 
170
165
  def url?(url)
171
- %r{^([A-Z]:)?/}.match?(url)
166
+ %r{^[A-Z]{2,}://}i.match?(url)
167
+ end
168
+
169
+ def absolute_path?(uri)
170
+ %r{^/}.match?(uri) || %r{^[A-Z]:/}.match?(uri)
172
171
  end
173
172
 
174
173
  def decode_datauri(uri)
data/lib/utils/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module Metanorma
2
2
  module Utils
3
- VERSION = "1.4.2".freeze
3
+ VERSION = "1.4.4".freeze
4
4
  end
5
5
  end
data/spec/img_spec.rb CHANGED
@@ -2,6 +2,33 @@ require "spec_helper"
2
2
  require "fileutils"
3
3
 
4
4
  RSpec.describe Metanorma::Utils do
5
+ it "recognises data uris" do
6
+ expect(Metanorma::Utils.datauri?("data:img/gif,base64,ABBC"))
7
+ .to eq true
8
+ expect(Metanorma::Utils.datauri?("data1:img/gif,base64,ABBC"))
9
+ .to eq false
10
+ end
11
+
12
+ it "recognises uris" do
13
+ expect(Metanorma::Utils.url?("mailto://ABC"))
14
+ .to eq true
15
+ expect(Metanorma::Utils.url?("http://ABC"))
16
+ .to eq true
17
+ expect(Metanorma::Utils.url?("D:/ABC"))
18
+ .to eq false
19
+ expect(Metanorma::Utils.url?("/ABC"))
20
+ .to eq false
21
+ end
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
+
5
32
  it "rewrites SVGs" do
6
33
  FileUtils.cp("spec/fixtures/action_schemaexpg1.svg",
7
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.2
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-07 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