imgix 4.0.1 → 4.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +3 -7
- data/.vscode/tasks.json +29 -0
- data/CHANGELOG.md +10 -0
- data/Gemfile +3 -0
- data/lib/imgix.rb +1 -0
- data/lib/imgix/path.rb +43 -11
- data/lib/imgix/version.rb +1 -1
- data/script/bench_path.rb +11 -0
- data/script/bench_to_url.rb +12 -0
- metadata +7 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b593ef71fdd4683f9af895b093f631c8ee57c0e5e1008dd82ece781d422d1b36
|
4
|
+
data.tar.gz: eb75567f9424d0b898e7773fac412d0500d24350e4a6d73775babb739f01d971
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '0389f0633ffba93ba0e5eb3e69dbf7017462ade823648ce3c490451ea0c5bd6c30a9a6c95b8e03f3111eb27cd6bdc4b766eb279b7c9c95f9feae77c6751c6b39'
|
7
|
+
data.tar.gz: c2033581fb3e629ff440c3aada007804872dc2d5a9f495006a47dded1ad532d043b9a83bc8e12ae3bc9ddb4874c3bc6802e5ac5f2677a8182cee4e6c43e6267e
|
data/.travis.yml
CHANGED
@@ -2,11 +2,8 @@ dist: trusty
|
|
2
2
|
language: ruby
|
3
3
|
bundler_args: --without development
|
4
4
|
rvm:
|
5
|
-
- 2.7
|
6
|
-
- 2.6
|
7
|
-
- 2.3.0
|
8
|
-
- 2.2.4
|
9
|
-
- 2.1.8
|
5
|
+
- 2.7
|
6
|
+
- 2.6
|
10
7
|
- jruby-9.2.11.0
|
11
8
|
|
12
9
|
jobs:
|
@@ -15,9 +12,8 @@ jobs:
|
|
15
12
|
|
16
13
|
include:
|
17
14
|
- name: Rubinius
|
18
|
-
rvm: rbx-3
|
15
|
+
rvm: rbx-3
|
19
16
|
dist: trusty
|
20
17
|
|
21
18
|
allow_failures:
|
22
19
|
- name: Rubinius
|
23
|
-
|
data/.vscode/tasks.json
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
{
|
2
|
+
"version": "2.0.0",
|
3
|
+
"tasks": [
|
4
|
+
{
|
5
|
+
"label": "rake: test",
|
6
|
+
"type": "shell",
|
7
|
+
"group":{
|
8
|
+
"kind": "test",
|
9
|
+
"isDefault": true
|
10
|
+
},
|
11
|
+
"problemMatcher": {
|
12
|
+
"owner": "ruby",
|
13
|
+
"fileLocation": ["relative", "${workspaceFolder}"],
|
14
|
+
"pattern": [
|
15
|
+
{
|
16
|
+
"regexp": "^([^:]+: .+)",
|
17
|
+
"message": 1
|
18
|
+
},
|
19
|
+
{
|
20
|
+
"regexp": "^ ([^:]+):(\\d+)",
|
21
|
+
"file": 1,
|
22
|
+
"line": 2
|
23
|
+
}
|
24
|
+
]
|
25
|
+
},
|
26
|
+
"command": "bundle exec rake test"
|
27
|
+
}
|
28
|
+
]
|
29
|
+
}
|
data/CHANGELOG.md
CHANGED
@@ -3,6 +3,16 @@
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
4
4
|
This project adheres to [Semantic Versioning](http://semver.org/).
|
5
5
|
|
6
|
+
## [4.0.2](https://github.com/imgix/imgix-rb/compare/4.0.1...4.0.2) - April 22, 2021
|
7
|
+
|
8
|
+
* fix(path): correctly encode reserved chars ([#108](https://github.com/imgix/imgix-rb/pull/108))
|
9
|
+
* test: add benchmark script for Imgix::Path#to_url ([4b00c4b](https://github.com/imgix/imgix-rb/commit/4b00c4b6d27b87787464438b36954b9c166096eb))
|
10
|
+
* perf: avoid calculating path_and_params twice ([#109](https://github.com/imgix/imgix-rb/pull/109))
|
11
|
+
* ci: use major version only for Rubinius 3 ([921e41a](https://github.com/imgix/imgix-rb/commit/921e41ac7789a55c78b42d60ac99cc0b641a69fd))
|
12
|
+
* ci: use optimistic versioning ([#107](https://github.com/imgix/imgix-rb/pull/107))
|
13
|
+
* ci: remove support for ruby version <2.5 ([#106](https://github.com/imgix/imgix-rb/pull/106))
|
14
|
+
* perf: precompute DEFAULT_TARGET_WIDTHS to avoid repeating on Path.new ([#105](https://github.com/imgix/imgix-rb/pull/105))
|
15
|
+
|
6
16
|
## [4.0.1](https://github.com/imgix/imgix-rb/compare/4.0.0...4.0.1) - March 24, 2021
|
7
17
|
|
8
18
|
* fix: dpr srcset when only h param ([#101](https://github.com/imgix/imgix-rb/pull/101))
|
data/Gemfile
CHANGED
data/lib/imgix.rb
CHANGED
@@ -39,6 +39,7 @@ module Imgix
|
|
39
39
|
resolutions.push(max_size)
|
40
40
|
return resolutions
|
41
41
|
}
|
42
|
+
DEFAULT_TARGET_WIDTHS = TARGET_WIDTHS.call(DEFAULT_WIDTH_TOLERANCE, MIN_WIDTH, MAX_WIDTH).freeze
|
42
43
|
|
43
44
|
# hash of default quality parameter values mapped by each dpr srcset entry
|
44
45
|
DPR_QUALITY = {
|
data/lib/imgix/path.rb
CHANGED
@@ -12,20 +12,18 @@ module Imgix
|
|
12
12
|
@secure_url_token = secure_url_token
|
13
13
|
@path = path
|
14
14
|
@options = {}
|
15
|
-
|
16
|
-
@path = CGI.escape(@path) if /^https?/ =~ @path
|
17
|
-
@path = "/#{@path}" if @path[0] != "/"
|
18
|
-
@target_widths = TARGET_WIDTHS.call(DEFAULT_WIDTH_TOLERANCE, MIN_WIDTH, MAX_WIDTH)
|
19
15
|
end
|
20
16
|
|
21
17
|
def to_url(opts = {})
|
18
|
+
sanitized_path = sanitize_path(@path)
|
22
19
|
prev_options = @options.dup
|
23
20
|
@options.merge!(opts)
|
24
21
|
|
25
|
-
|
22
|
+
current_path_and_params = path_and_params(sanitized_path)
|
23
|
+
url = @prefix + current_path_and_params
|
26
24
|
|
27
25
|
if @secure_url_token
|
28
|
-
url += (has_query? ? "&" : "?") + "s=#{signature}"
|
26
|
+
url += (has_query? ? "&" : "?") + "s=#{signature(current_path_and_params)}"
|
29
27
|
end
|
30
28
|
|
31
29
|
@options = prev_options
|
@@ -130,12 +128,46 @@ module Imgix
|
|
130
128
|
|
131
129
|
private
|
132
130
|
|
133
|
-
|
134
|
-
|
131
|
+
# Escape and encode any characters in path that are reserved and not utf8 encoded.
|
132
|
+
# This includes " +?:#" characters. If a path is being used as a proxy, utf8
|
133
|
+
# encode everything. If it is not being used as proxy, leave certain chars, like
|
134
|
+
# "/", alone. Method assumes path is not already encoded.
|
135
|
+
def sanitize_path(path)
|
136
|
+
# remove the leading "/", we'll add it back after encoding
|
137
|
+
path = path.slice(1, path.length) if Regexp.new('^/') =~ path
|
138
|
+
# if path is being used as a proxy, encode the entire thing
|
139
|
+
if /^https?/ =~ path
|
140
|
+
return encode_URI_Component(path)
|
141
|
+
else
|
142
|
+
# otherwise, encode only specific characters
|
143
|
+
return encode_URI(path)
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
# URL encode the entire path
|
148
|
+
def encode_URI_Component(path)
|
149
|
+
return "/" + CGI.escape(path)
|
150
|
+
end
|
151
|
+
|
152
|
+
# URL encode every character in the path, including
|
153
|
+
# " +?:#" characters.
|
154
|
+
def encode_URI(path)
|
155
|
+
# For each component in the path, URL encode it and add it
|
156
|
+
# to the array path component.
|
157
|
+
path_components = []
|
158
|
+
path.split("/").each do |str|
|
159
|
+
path_components << ERB::Util.url_encode(str)
|
160
|
+
end
|
161
|
+
# Prefix and join the encoded path components.
|
162
|
+
"/#{path_components.join('/')}"
|
163
|
+
end
|
164
|
+
|
165
|
+
def signature(rest)
|
166
|
+
Digest::MD5.hexdigest(@secure_url_token + rest)
|
135
167
|
end
|
136
168
|
|
137
|
-
def path_and_params
|
138
|
-
has_query? ? "#{
|
169
|
+
def path_and_params(path)
|
170
|
+
has_query? ? "#{path}?#{query}" : path
|
139
171
|
end
|
140
172
|
|
141
173
|
def query
|
@@ -170,7 +202,7 @@ module Imgix
|
|
170
202
|
validate_width_tolerance!(width_tolerance)
|
171
203
|
srcset_widths = TARGET_WIDTHS.call(width_tolerance, min_width, max_width)
|
172
204
|
else
|
173
|
-
srcset_widths =
|
205
|
+
srcset_widths = DEFAULT_TARGET_WIDTHS
|
174
206
|
end
|
175
207
|
|
176
208
|
srcset_widths.each do |width|
|
data/lib/imgix/version.rb
CHANGED
@@ -0,0 +1,12 @@
|
|
1
|
+
$LOAD_PATH << 'lib'
|
2
|
+
require 'imgix'
|
3
|
+
require 'benchmark/ips'
|
4
|
+
|
5
|
+
client = Imgix::Client.new(domain: 'domain.com', secure_url_token: 'token')
|
6
|
+
path = client.path("/img.jpg")
|
7
|
+
|
8
|
+
Benchmark.ips do |x|
|
9
|
+
x.report('Imgix::Path#to_url') do
|
10
|
+
path.to_url({ auto: 'compress,format', fit: 'crop', crop: 'top', w: 590, h: 332 })
|
11
|
+
end
|
12
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: imgix
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.0.
|
4
|
+
version: 4.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kelly Sutton
|
@@ -13,7 +13,7 @@ authors:
|
|
13
13
|
autorequire:
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
|
-
date: 2021-
|
16
|
+
date: 2021-04-26 00:00:00.000000000 Z
|
17
17
|
dependencies: []
|
18
18
|
description: Easily create and sign imgix URLs.
|
19
19
|
email:
|
@@ -30,6 +30,7 @@ files:
|
|
30
30
|
- ".gitignore"
|
31
31
|
- ".rubocop.yml"
|
32
32
|
- ".travis.yml"
|
33
|
+
- ".vscode/tasks.json"
|
33
34
|
- CHANGELOG.md
|
34
35
|
- Contributing.markdown
|
35
36
|
- Gemfile
|
@@ -41,14 +42,16 @@ files:
|
|
41
42
|
- lib/imgix/client.rb
|
42
43
|
- lib/imgix/path.rb
|
43
44
|
- lib/imgix/version.rb
|
45
|
+
- script/bench_path.rb
|
46
|
+
- script/bench_to_url.rb
|
44
47
|
homepage: https://github.com/imgix/imgix-rb
|
45
48
|
licenses:
|
46
49
|
- MIT
|
47
50
|
metadata:
|
48
51
|
bug_tracker_uri: https://github.com/imgix/imgix-rb/issues
|
49
52
|
changelog_uri: https://github.com/imgix/imgix-rb/blob/main/CHANGELOG.md
|
50
|
-
documentation_uri: https://www.rubydoc.info/gems/imgix/4.0.
|
51
|
-
source_code_uri: https://github.com/imgix/imgix-rb/tree/4.0.
|
53
|
+
documentation_uri: https://www.rubydoc.info/gems/imgix/4.0.2
|
54
|
+
source_code_uri: https://github.com/imgix/imgix-rb/tree/4.0.2
|
52
55
|
post_install_message:
|
53
56
|
rdoc_options: []
|
54
57
|
require_paths:
|