shrine-imgix 0.4.0 → 0.5.0
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 +5 -5
- data/README.md +62 -42
- data/lib/shrine/plugins/imgix.rb +61 -0
- data/lib/shrine/storage/imgix.rb +2 -5
- data/shrine-imgix.gemspec +7 -7
- metadata +29 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 2d6c5bb7609745c53c01ff6760fa02521df2dc5a37ea722d8167c5aa0420ae45
|
4
|
+
data.tar.gz: 0c14918abaefd1a08b0e020b10acdd6ee27d2c85100089f24d6a8cac3c97f648
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3420f84cd832bf15c71b25131fb176a327a39f60dd4d3b31b203933d1587779787ed6943aef6ff2b3262b52d26ed5b120502e52ab77027d87e59d078fae82fd9
|
7
|
+
data.tar.gz: 3ea6cead9ea7283ddb6c041c1edd38e0c8c601cb9d8214afe414008ff2dcb331caed9531be91df565a21ff99775ad9bcd23b8319fffaedeb3a584283315f5a67
|
data/README.md
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
Provides [Imgix] integration for [Shrine].
|
4
4
|
|
5
5
|
Imgix is a service for processing images on the fly, and works with files
|
6
|
-
stored on
|
6
|
+
stored on external services such as AWS S3 or Google Cloud Storage.
|
7
7
|
|
8
8
|
## Installation
|
9
9
|
|
@@ -11,63 +11,81 @@ stored on Amazon S3.
|
|
11
11
|
gem "shrine-imgix"
|
12
12
|
```
|
13
13
|
|
14
|
-
##
|
14
|
+
## Configuring
|
15
15
|
|
16
|
-
|
17
|
-
various sources (S3, Web Folder or Web Proxy), so you first need to set that up
|
18
|
-
(see the [Imgix documentation]). After this is set up, the Imgix Shrine
|
19
|
-
"storage" is used as a wrapper around the main storage of the source:
|
16
|
+
Load the `imgix` plugin with Imgix client settings:
|
20
17
|
|
21
18
|
```rb
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
19
|
+
Shrine.plugin :imgix, client: {
|
20
|
+
host: "your-subdomain.imgix.net",
|
21
|
+
secure_url_token: "abc123",
|
22
|
+
}
|
23
|
+
```
|
24
|
+
|
25
|
+
You can also pass in an `Imgix::Client` object directly:
|
26
|
+
|
27
|
+
```rb
|
28
|
+
require "imgix"
|
29
|
+
|
30
|
+
imgix_client = Imgix::Client.new(
|
31
|
+
host: "your-subdomain.imgix.net",
|
32
|
+
secure_url_token: "abc123",
|
31
33
|
)
|
32
34
|
|
33
|
-
Shrine.
|
35
|
+
Shrine.plugin :imgix, client: imgix_client
|
34
36
|
```
|
35
37
|
|
36
|
-
|
37
|
-
instantiating an `Imgix::Client`, see the [imgix] gem for information about all
|
38
|
-
possible options. The `:include_prefix` option decides whether the `#prefix`
|
39
|
-
of the underlying storage will be included in the generated Imgix URLs.
|
38
|
+
### Path prefix
|
40
39
|
|
41
|
-
|
42
|
-
|
43
|
-
|
40
|
+
If you've configured a "Path Prefix" on your Imgix source, and you also have
|
41
|
+
`:prefix` set on your Shrine storage, you'll need tell the `imgix` plugin to
|
42
|
+
exclude the storage prefix from generated URLs:
|
44
43
|
|
45
44
|
```rb
|
46
|
-
|
45
|
+
Shrine.plugin :imgix, client: ..., prefix: false
|
46
|
+
```
|
47
|
+
|
48
|
+
## Usage
|
49
|
+
|
50
|
+
You can generate an Imgix URL for a `Shrine::UploadedFile` object by calling
|
51
|
+
`#imgix_url`:
|
52
|
+
|
53
|
+
```rb
|
54
|
+
photo.image.imgix_url(w: 150, h: 200, fit: "crop")
|
47
55
|
#=> "http://my-subdomain.imgix.net/943kdfs0gkfg.jpg?w=150&h=200&fit=crop"
|
48
56
|
```
|
49
57
|
|
50
|
-
See the [Imgix docs]
|
51
|
-
URL options.
|
58
|
+
See the [Imgix docs][url reference] for all available URL options.
|
52
59
|
|
53
|
-
|
60
|
+
### Rails
|
54
61
|
|
55
|
-
|
56
|
-
|
62
|
+
If you're using [imgix-rails] and want to use the `ix_*` helpers, you can use
|
63
|
+
`#imgix_id` to retrieve the Imgix path:
|
57
64
|
|
58
|
-
```
|
59
|
-
|
60
|
-
IMGIX_API_KEY="..."
|
61
|
-
IMGIX_HOST="..."
|
62
|
-
IMGIX_SECURE_URL_TOKEN="..." # optional
|
63
|
-
S3_ACCESS_KEY_ID="..."
|
64
|
-
S3_SECRET_ACCESS_KEY="..."
|
65
|
-
S3_REGION="..."
|
66
|
-
S3_BUCKET="..."
|
67
|
-
S3_PREFIX="..."
|
65
|
+
```erb
|
66
|
+
<%= ix_image_tag photo.image.imgix_id, url_params: { w: 300, h: 500, fit: "crop" } %>
|
68
67
|
```
|
69
68
|
|
70
|
-
|
69
|
+
### Purging
|
70
|
+
|
71
|
+
If you want images to be automatically [purged][purging] from Imgix on
|
72
|
+
deletion, you can set `:purge` to `true`:
|
73
|
+
|
74
|
+
```rb
|
75
|
+
Shrine.plugin :imgix, client: ..., purge: true
|
76
|
+
```
|
77
|
+
|
78
|
+
You can also purge manually with `Shrine::UploadedFile#imgix_purge`:
|
79
|
+
|
80
|
+
```rb
|
81
|
+
photo.image.imgix_purge
|
82
|
+
```
|
83
|
+
|
84
|
+
Note that purging requires passing the `:api_key` option to your Imgix client.
|
85
|
+
|
86
|
+
## Development
|
87
|
+
|
88
|
+
You can run the test suite with:
|
71
89
|
|
72
90
|
```sh
|
73
91
|
$ bundle exec rake test
|
@@ -78,6 +96,8 @@ $ bundle exec rake test
|
|
78
96
|
[MIT](http://opensource.org/licenses/MIT)
|
79
97
|
|
80
98
|
[Imgix]: https://www.imgix.com/
|
81
|
-
[Shrine]: https://github.com/janko
|
99
|
+
[Shrine]: https://github.com/janko/shrine
|
82
100
|
[imgix]: https://github.com/imgix/imgix-rb
|
83
|
-
[
|
101
|
+
[url reference]: https://docs.imgix.com/apis/url
|
102
|
+
[imgix-rails]: https://github.com/imgix/imgix-rails
|
103
|
+
[purging]: https://docs.imgix.com/setup/purging-images
|
@@ -0,0 +1,61 @@
|
|
1
|
+
require "imgix"
|
2
|
+
|
3
|
+
class Shrine
|
4
|
+
module Plugins
|
5
|
+
module Imgix
|
6
|
+
def self.configure(uploader, **opts)
|
7
|
+
opts[:client] = ::Imgix::Client.new(opts[:client]) if opts[:client].is_a?(Hash)
|
8
|
+
|
9
|
+
uploader.opts[:imgix] ||= { prefix: true, purge: false }
|
10
|
+
uploader.opts[:imgix].merge!(**opts)
|
11
|
+
|
12
|
+
fail Error, ":client is required for imgix plugin" unless uploader.imgix_client
|
13
|
+
end
|
14
|
+
|
15
|
+
module ClassMethods
|
16
|
+
def imgix_client
|
17
|
+
opts[:imgix][:client]
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
module FileMethods
|
22
|
+
def imgix_url(**options)
|
23
|
+
imgix_client.path(imgix_id).to_url(**options)
|
24
|
+
end
|
25
|
+
|
26
|
+
def delete
|
27
|
+
super
|
28
|
+
imgix_purge if imgix_purge?
|
29
|
+
end
|
30
|
+
|
31
|
+
def imgix_purge
|
32
|
+
imgix_client.purge(imgix_id)
|
33
|
+
end
|
34
|
+
|
35
|
+
def imgix_id
|
36
|
+
if imgix_prefix? && storage.respond_to?(:prefix)
|
37
|
+
[*storage.prefix, id].join("/")
|
38
|
+
else
|
39
|
+
id
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
private
|
44
|
+
|
45
|
+
def imgix_client
|
46
|
+
shrine_class.imgix_client
|
47
|
+
end
|
48
|
+
|
49
|
+
def imgix_prefix?
|
50
|
+
shrine_class.opts[:imgix][:prefix]
|
51
|
+
end
|
52
|
+
|
53
|
+
def imgix_purge?
|
54
|
+
shrine_class.opts[:imgix][:purge]
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
register_plugin(:imgix, Imgix)
|
60
|
+
end
|
61
|
+
end
|
data/lib/shrine/storage/imgix.rb
CHANGED
@@ -2,6 +2,8 @@ require "imgix"
|
|
2
2
|
require "net/http"
|
3
3
|
require "uri"
|
4
4
|
|
5
|
+
warn "Shrine::Storage::Imgix is deprecated and will be removed in next major version. Use the new :imgix plugin instead."
|
6
|
+
|
5
7
|
class Shrine
|
6
8
|
module Storage
|
7
9
|
class Imgix
|
@@ -37,11 +39,6 @@ class Shrine
|
|
37
39
|
@storage.presign(*args)
|
38
40
|
end if @storage.respond_to?(:presign)
|
39
41
|
|
40
|
-
def multi_delete(ids)
|
41
|
-
@storage.multi_delete(ids)
|
42
|
-
ids.each { |id| purge(id) }
|
43
|
-
end if @storage.respond_to?(:multi_delete)
|
44
|
-
|
45
42
|
def clear!(*args)
|
46
43
|
@storage.clear!(*args)
|
47
44
|
end if @storage.respond_to?(:clear!)
|
data/shrine-imgix.gemspec
CHANGED
@@ -1,23 +1,23 @@
|
|
1
1
|
Gem::Specification.new do |gem|
|
2
2
|
gem.name = "shrine-imgix"
|
3
|
-
gem.version = "0.
|
3
|
+
gem.version = "0.5.0"
|
4
4
|
|
5
5
|
gem.required_ruby_version = ">= 2.1"
|
6
6
|
|
7
7
|
gem.summary = "Provides Imgix integration for Shrine."
|
8
|
-
gem.homepage = "https://github.com/janko
|
8
|
+
gem.homepage = "https://github.com/janko/shrine-imgix"
|
9
9
|
gem.authors = ["Janko Marohnić"]
|
10
10
|
gem.email = ["janko.marohnic@gmail.com"]
|
11
11
|
gem.license = "MIT"
|
12
12
|
|
13
|
-
gem.files = Dir["README.md", "LICENSE.txt", "lib/**/*.rb", "
|
13
|
+
gem.files = Dir["README.md", "LICENSE.txt", "lib/**/*.rb", "*.gemspec"]
|
14
14
|
gem.require_path = "lib"
|
15
15
|
|
16
|
-
gem.add_dependency "shrine", "
|
17
|
-
gem.add_dependency "imgix", "
|
16
|
+
gem.add_dependency "shrine", ">= 2.0", "< 4"
|
17
|
+
gem.add_dependency "imgix", ">= 1.2", "< 4"
|
18
18
|
|
19
19
|
gem.add_development_dependency "rake"
|
20
20
|
gem.add_development_dependency "minitest"
|
21
|
-
gem.add_development_dependency "
|
22
|
-
gem.add_development_dependency "
|
21
|
+
gem.add_development_dependency "mocha"
|
22
|
+
gem.add_development_dependency "shrine-memory"
|
23
23
|
end
|
metadata
CHANGED
@@ -1,43 +1,55 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: shrine-imgix
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Janko Marohnić
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-08-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: shrine
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '2.0'
|
20
|
+
- - "<"
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '4'
|
20
23
|
type: :runtime
|
21
24
|
prerelease: false
|
22
25
|
version_requirements: !ruby/object:Gem::Requirement
|
23
26
|
requirements:
|
24
|
-
- - "
|
27
|
+
- - ">="
|
25
28
|
- !ruby/object:Gem::Version
|
26
29
|
version: '2.0'
|
30
|
+
- - "<"
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '4'
|
27
33
|
- !ruby/object:Gem::Dependency
|
28
34
|
name: imgix
|
29
35
|
requirement: !ruby/object:Gem::Requirement
|
30
36
|
requirements:
|
31
|
-
- - "
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '1.2'
|
40
|
+
- - "<"
|
32
41
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
42
|
+
version: '4'
|
34
43
|
type: :runtime
|
35
44
|
prerelease: false
|
36
45
|
version_requirements: !ruby/object:Gem::Requirement
|
37
46
|
requirements:
|
38
|
-
- - "
|
47
|
+
- - ">="
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: '1.2'
|
50
|
+
- - "<"
|
39
51
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
52
|
+
version: '4'
|
41
53
|
- !ruby/object:Gem::Dependency
|
42
54
|
name: rake
|
43
55
|
requirement: !ruby/object:Gem::Requirement
|
@@ -67,7 +79,7 @@ dependencies:
|
|
67
79
|
- !ruby/object:Gem::Version
|
68
80
|
version: '0'
|
69
81
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
82
|
+
name: mocha
|
71
83
|
requirement: !ruby/object:Gem::Requirement
|
72
84
|
requirements:
|
73
85
|
- - ">="
|
@@ -81,19 +93,19 @@ dependencies:
|
|
81
93
|
- !ruby/object:Gem::Version
|
82
94
|
version: '0'
|
83
95
|
- !ruby/object:Gem::Dependency
|
84
|
-
name:
|
96
|
+
name: shrine-memory
|
85
97
|
requirement: !ruby/object:Gem::Requirement
|
86
98
|
requirements:
|
87
|
-
- - "
|
99
|
+
- - ">="
|
88
100
|
- !ruby/object:Gem::Version
|
89
|
-
version: '
|
101
|
+
version: '0'
|
90
102
|
type: :development
|
91
103
|
prerelease: false
|
92
104
|
version_requirements: !ruby/object:Gem::Requirement
|
93
105
|
requirements:
|
94
|
-
- - "
|
106
|
+
- - ">="
|
95
107
|
- !ruby/object:Gem::Version
|
96
|
-
version: '
|
108
|
+
version: '0'
|
97
109
|
description:
|
98
110
|
email:
|
99
111
|
- janko.marohnic@gmail.com
|
@@ -103,9 +115,10 @@ extra_rdoc_files: []
|
|
103
115
|
files:
|
104
116
|
- LICENSE.txt
|
105
117
|
- README.md
|
118
|
+
- lib/shrine/plugins/imgix.rb
|
106
119
|
- lib/shrine/storage/imgix.rb
|
107
120
|
- shrine-imgix.gemspec
|
108
|
-
homepage: https://github.com/janko
|
121
|
+
homepage: https://github.com/janko/shrine-imgix
|
109
122
|
licenses:
|
110
123
|
- MIT
|
111
124
|
metadata: {}
|
@@ -124,8 +137,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
124
137
|
- !ruby/object:Gem::Version
|
125
138
|
version: '0'
|
126
139
|
requirements: []
|
127
|
-
|
128
|
-
rubygems_version: 2.5.1
|
140
|
+
rubygems_version: 3.0.3
|
129
141
|
signing_key:
|
130
142
|
specification_version: 4
|
131
143
|
summary: Provides Imgix integration for Shrine.
|