imglab 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +5 -5
- data/lib/imglab/utils.rb +14 -2
- data/lib/imglab/version.rb +1 -1
- data/lib/imglab.rb +17 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 87c1e0449e9f2b7e000fda519d3413e205cdfab3d9c87c85bfd2edcc2f5e9467
|
4
|
+
data.tar.gz: 173c5436f148213ac172bf83e3a65a013d6d169264d9252419c3f6e5bb4c0216
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 39276c9dc2443af3d62b81f20b6313ff0c043300021c21ef9773244543df9967b2fb8afd625404f46528509026d4d18fe17113fc9042e9d06df7eec1a4aa750b
|
7
|
+
data.tar.gz: ecc2f549086dbd82f72820d59787192699abfb0c1c7d35c356a58ec1c01452d87e9a9541cc46cf6efa955b42d7417b0de206f164231f5c0f2d8c2ea775be5053
|
data/README.md
CHANGED
@@ -7,7 +7,7 @@
|
|
7
7
|
Add this line to your application's Gemfile:
|
8
8
|
|
9
9
|
```ruby
|
10
|
-
gem "imglab", "~> 0.1
|
10
|
+
gem "imglab", "~> 0.1"
|
11
11
|
```
|
12
12
|
|
13
13
|
And then execute:
|
@@ -49,10 +49,10 @@ Imglab.url(Imglab::Source.new("assets"), "image.jpeg", width: 500, height: 600)
|
|
49
49
|
|
50
50
|
### Using secure image sources
|
51
51
|
|
52
|
-
For sources that require signed URLs you can specify `secure_key` and `secure_salt` attributes
|
52
|
+
For sources that require signed URLs you can specify `secure_key` and `secure_salt` attributes:
|
53
53
|
|
54
54
|
```ruby
|
55
|
-
source = Imglab::Source.new(secure_key: "assets-secure-key", secure_salt: "assets-secure-salt")
|
55
|
+
source = Imglab::Source.new("assets", secure_key: "assets-secure-key", secure_salt: "assets-secure-salt")
|
56
56
|
|
57
57
|
Imglab.url(source, "image.jpeg", width: 500, height: 600)
|
58
58
|
"https://cdn.imglab.io/assets/image.jpeg?width=500&height=600&signature=generated-signature"
|
@@ -167,11 +167,11 @@ include Imglab::Position
|
|
167
167
|
Imglab.url("assets", "image.jpeg", width: 500, height: 500, mode: "crop", crop: position("left", "top"))
|
168
168
|
"https://cdn.imglab.io/assets/image.jpeg?width=500&height=500&mode=crop&crop=left%2Ctop"
|
169
169
|
|
170
|
-
# Using position
|
170
|
+
# Using position helper for a vertical and horizontal position
|
171
171
|
Imglab.url("assets", "image.jpeg", width: 500, height: 500, mode: "crop", crop: position("top", "left"))
|
172
172
|
"https://cdn.imglab.io/assets/image.jpeg?width=500&height=500&mode=crop&crop=top%2Cleft"
|
173
173
|
|
174
|
-
# Using position
|
174
|
+
# Using position helper for a position
|
175
175
|
Imglab.url("assets", "image.jpeg", width: 500, height: 500, mode: "crop", crop: position("left"))
|
176
176
|
"https://cdn.imglab.io/assets/image.jpeg?width=500&height=500&mode=crop&crop=left"
|
177
177
|
```
|
data/lib/imglab/utils.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
class Imglab::Utils
|
2
|
-
NORMALIZE_PATH_PREFIX_REGEXP = Regexp.compile(
|
3
|
-
NORMALIZE_PATH_SUFFIX_REGEXP = Regexp.compile(
|
2
|
+
NORMALIZE_PATH_PREFIX_REGEXP = Regexp.compile(/\A\/*/)
|
3
|
+
NORMALIZE_PATH_SUFFIX_REGEXP = Regexp.compile(/\/*$/)
|
4
|
+
|
5
|
+
WEB_URI_SCHEMES = %w[https http]
|
4
6
|
|
5
7
|
# Returns a normalized path where suffix and prefix slashes are removed.
|
6
8
|
#
|
@@ -21,6 +23,16 @@ class Imglab::Utils
|
|
21
23
|
end
|
22
24
|
end
|
23
25
|
|
26
|
+
# Returns a boolean value indicating whether a string is a valid HTTP/HTTPS URI or not.
|
27
|
+
#
|
28
|
+
# @param uri [String]
|
29
|
+
# @return [Boolean]
|
30
|
+
def self.web_uri?(uri)
|
31
|
+
WEB_URI_SCHEMES.include?(URI.parse(uri).scheme)
|
32
|
+
rescue URI::Error
|
33
|
+
false
|
34
|
+
end
|
35
|
+
|
24
36
|
private
|
25
37
|
|
26
38
|
def self.dasherize(value)
|
data/lib/imglab/version.rb
CHANGED
data/lib/imglab.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require "erb"
|
2
|
+
|
1
3
|
require "imglab/version"
|
2
4
|
require "imglab/source"
|
3
5
|
require "imglab/signature"
|
@@ -41,13 +43,27 @@ module Imglab
|
|
41
43
|
source.host,
|
42
44
|
source.port,
|
43
45
|
nil,
|
44
|
-
File.join("/", source.path(normalized_path)),
|
46
|
+
File.join("/", source.path(encode_path(normalized_path))),
|
45
47
|
nil,
|
46
48
|
encode_params(source, normalized_path, normalized_params),
|
47
49
|
nil
|
48
50
|
).to_s
|
49
51
|
end
|
50
52
|
|
53
|
+
def self.encode_path(path)
|
54
|
+
if Utils.web_uri?(path)
|
55
|
+
encode_path_component(path)
|
56
|
+
else
|
57
|
+
path.split("/").map do |path_component|
|
58
|
+
encode_path_component(path_component)
|
59
|
+
end.join("/")
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def self.encode_path_component(path_component)
|
64
|
+
ERB::Util.url_encode(path_component)
|
65
|
+
end
|
66
|
+
|
51
67
|
def self.encode_params(source, path, params)
|
52
68
|
return encode_empty_params(source, path) if params.empty?
|
53
69
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: imglab
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- imglab
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-03-15 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Official Ruby library to integrate with imglab services.
|
14
14
|
email:
|
@@ -54,7 +54,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
54
54
|
- !ruby/object:Gem::Version
|
55
55
|
version: '0'
|
56
56
|
requirements: []
|
57
|
-
rubygems_version: 3.
|
57
|
+
rubygems_version: 3.1.6
|
58
58
|
signing_key:
|
59
59
|
specification_version: 4
|
60
60
|
summary: Official imglab Ruby library.
|