alchemy-dragonfly-s3 5.0.4 → 5.1.5
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 +4 -4
- data/README.md +16 -8
- data/app/models/alchemy/attachment/s3_url.rb +11 -0
- data/app/models/alchemy/picture/s3_url.rb +13 -0
- data/lib/alchemy-dragonfly-s3.rb +1 -0
- data/lib/alchemy/dragonfly/s3/create_picture_thumb.rb +29 -0
- data/lib/alchemy/dragonfly/s3/engine.rb +4 -13
- data/lib/alchemy/dragonfly/s3/version.rb +1 -1
- metadata +11 -40
- data/lib/alchemy/attachment_monkey_patch.rb +0 -13
- data/lib/alchemy/essence_picture_monkey_patch.rb +0 -19
- data/lib/alchemy/picture_monkey_patch.rb +0 -43
- data/lib/tasks/alchemy_dragonfly_s3/generate.rake +0 -37
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ec1c13a542a1b63dd195077cd647d1e1bc0bdfaeae8a4eb51b702566d5202c12
|
4
|
+
data.tar.gz: 646fe1fa7a99c9ee7cb68eb8cc1bbddbd78640624cfafb168f5fb9371239bce0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c16231755be826fc40a78542cfb864753a0403eed16feb51186d9e526c2c76dc450810a228105644a0233844fa97171e7a83d35bd52ecedcbdaf7205d639961a
|
7
|
+
data.tar.gz: 946cf698073d4940257b251f8f53eb1ef189b53c4bf91ea081ff3142360cef5ef05cbf97631a5fad8c2c51cc58a98f1048b41e3c5e6093439ddc323786181f03
|
data/README.md
CHANGED
@@ -1,35 +1,43 @@
|
|
1
|
-
[](https://travis-ci.com/AlchemyCMS/alchemy-dragonfly-s3)
|
2
2
|
|
3
3
|
# AlchemyCMS AWS S3
|
4
4
|
|
5
|
-
|
5
|
+
Provides classes for storing Alchemy pictures and file attachments on Amazon AWS S3.
|
6
6
|
|
7
7
|
## Alchemy Version
|
8
8
|
|
9
|
-
This branch works with Alchemy 5.
|
9
|
+
This branch works with Alchemy 5.1 only.
|
10
10
|
|
11
|
-
- For a Alchemy 5.
|
11
|
+
- For a Alchemy 5.0 compatible version use the `alchemy-5` branch.
|
12
12
|
- For a Alchemy 4 compatible version use the `alchemy-4` branch.
|
13
|
-
- For a Alchemy 3
|
13
|
+
- For a Alchemy 3 compatible version use the `alchemy-3` branch.
|
14
14
|
|
15
15
|
## Installation
|
16
16
|
|
17
17
|
Add this line to your application's Gemfile:
|
18
18
|
|
19
19
|
```ruby
|
20
|
-
gem 'alchemy-dragonfly-s3', github: 'AlchemyCMS/alchemy-dragonfly-s3'
|
20
|
+
gem 'alchemy-dragonfly-s3', github: 'AlchemyCMS/alchemy-dragonfly-s3'
|
21
21
|
```
|
22
22
|
|
23
|
+
For now you also need the master branch of AlchemyCMS*
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
gem 'alchemy_cms', github: 'AlchemyCMS/alchemy_cms', branch: 'master'
|
27
|
+
```
|
28
|
+
|
29
|
+
*only necessary until Alchemy 5.1 has been released.
|
30
|
+
|
23
31
|
And then execute:
|
24
32
|
|
25
33
|
```
|
26
34
|
$ bundle install
|
27
35
|
```
|
28
36
|
|
29
|
-
Install the picture thumbs migration
|
37
|
+
Install the picture thumbs migration from Alchemy 5.1
|
30
38
|
|
31
39
|
```
|
32
|
-
$ bin/rake
|
40
|
+
$ bin/rake alchemy:install:migrations
|
33
41
|
$ bin/rake db:migrate
|
34
42
|
```
|
35
43
|
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Alchemy
|
4
|
+
class Picture < BaseRecord
|
5
|
+
class S3Url < Url
|
6
|
+
def call(*)
|
7
|
+
return variant.image.remote_url unless processible_image?
|
8
|
+
|
9
|
+
::Dragonfly.app(:alchemy_pictures).remote_url_for(uid)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
data/lib/alchemy-dragonfly-s3.rb
CHANGED
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Alchemy
|
4
|
+
module Dragonfly
|
5
|
+
module S3
|
6
|
+
class CreatePictureThumb
|
7
|
+
def self.call(variant, signature, uid)
|
8
|
+
# create the thumb before uploading
|
9
|
+
# to prevent db race conditions
|
10
|
+
thumb = variant.picture.thumbs.create!(
|
11
|
+
picture: variant.picture,
|
12
|
+
signature: signature,
|
13
|
+
uid: uid,
|
14
|
+
)
|
15
|
+
begin
|
16
|
+
# fetch and process the image
|
17
|
+
image = variant.image
|
18
|
+
# upload the processed image
|
19
|
+
image.store(path: uid)
|
20
|
+
rescue RuntimeError, Excon::Error => e
|
21
|
+
Rails.logger.warn(e)
|
22
|
+
# destroy the thumb if processing or upload fails
|
23
|
+
thumb.destroy
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -6,19 +6,10 @@ module Alchemy
|
|
6
6
|
class Engine < ::Rails::Engine
|
7
7
|
engine_name "alchemy_dragonfly_s3"
|
8
8
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
config.to_prepare do
|
14
|
-
files = [
|
15
|
-
"attachment_monkey_patch.rb",
|
16
|
-
"picture_monkey_patch.rb",
|
17
|
-
"essence_picture_monkey_patch.rb",
|
18
|
-
].each do |filename|
|
19
|
-
file = Alchemy::Dragonfly::S3::Engine.root.join("lib", "alchemy", filename)
|
20
|
-
Rails.application.config.cache_classes ? require(file) : load(file)
|
21
|
-
end
|
9
|
+
config.after_initialize do
|
10
|
+
Alchemy::Attachment.url_class = Alchemy::Attachment::S3Url
|
11
|
+
Alchemy::Picture.url_class = Alchemy::Picture::S3Url
|
12
|
+
Alchemy::PictureThumb.generator_class = Alchemy::Dragonfly::S3::CreatePictureThumb
|
22
13
|
end
|
23
14
|
end
|
24
15
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: alchemy-dragonfly-s3
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 5.
|
4
|
+
version: 5.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Thomas von Deyen
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-07-
|
11
|
+
date: 2020-07-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: alchemy_cms
|
@@ -16,20 +16,20 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 5.
|
19
|
+
version: 5.1.0.alpha
|
20
20
|
- - "<"
|
21
21
|
- !ruby/object:Gem::Version
|
22
|
-
version: '
|
22
|
+
version: '6'
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
25
|
version_requirements: !ruby/object:Gem::Requirement
|
26
26
|
requirements:
|
27
27
|
- - ">="
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
version: 5.
|
29
|
+
version: 5.1.0.alpha
|
30
30
|
- - "<"
|
31
31
|
- !ruby/object:Gem::Version
|
32
|
-
version: '
|
32
|
+
version: '6'
|
33
33
|
- !ruby/object:Gem::Dependency
|
34
34
|
name: dragonfly-s3_data_store
|
35
35
|
requirement: !ruby/object:Gem::Requirement
|
@@ -44,20 +44,6 @@ dependencies:
|
|
44
44
|
- - "~>"
|
45
45
|
- !ruby/object:Gem::Version
|
46
46
|
version: '1.3'
|
47
|
-
- !ruby/object:Gem::Dependency
|
48
|
-
name: capybara
|
49
|
-
requirement: !ruby/object:Gem::Requirement
|
50
|
-
requirements:
|
51
|
-
- - "~>"
|
52
|
-
- !ruby/object:Gem::Version
|
53
|
-
version: '3.0'
|
54
|
-
type: :development
|
55
|
-
prerelease: false
|
56
|
-
version_requirements: !ruby/object:Gem::Requirement
|
57
|
-
requirements:
|
58
|
-
- - "~>"
|
59
|
-
- !ruby/object:Gem::Version
|
60
|
-
version: '3.0'
|
61
47
|
- !ruby/object:Gem::Dependency
|
62
48
|
name: rspec-rails
|
63
49
|
requirement: !ruby/object:Gem::Requirement
|
@@ -78,14 +64,14 @@ dependencies:
|
|
78
64
|
requirements:
|
79
65
|
- - "~>"
|
80
66
|
- !ruby/object:Gem::Version
|
81
|
-
version: '
|
67
|
+
version: '6.0'
|
82
68
|
type: :development
|
83
69
|
prerelease: false
|
84
70
|
version_requirements: !ruby/object:Gem::Requirement
|
85
71
|
requirements:
|
86
72
|
- - "~>"
|
87
73
|
- !ruby/object:Gem::Version
|
88
|
-
version: '
|
74
|
+
version: '6.0'
|
89
75
|
- !ruby/object:Gem::Dependency
|
90
76
|
name: simplecov
|
91
77
|
requirement: !ruby/object:Gem::Requirement
|
@@ -100,20 +86,6 @@ dependencies:
|
|
100
86
|
- - "~>"
|
101
87
|
- !ruby/object:Gem::Version
|
102
88
|
version: '0.17'
|
103
|
-
- !ruby/object:Gem::Dependency
|
104
|
-
name: shoulda-matchers
|
105
|
-
requirement: !ruby/object:Gem::Requirement
|
106
|
-
requirements:
|
107
|
-
- - "~>"
|
108
|
-
- !ruby/object:Gem::Version
|
109
|
-
version: '4.0'
|
110
|
-
type: :development
|
111
|
-
prerelease: false
|
112
|
-
version_requirements: !ruby/object:Gem::Requirement
|
113
|
-
requirements:
|
114
|
-
- - "~>"
|
115
|
-
- !ruby/object:Gem::Version
|
116
|
-
version: '4.0'
|
117
89
|
description: AlchemyCMS Integration for the Dragonfly S3 datastore.
|
118
90
|
email:
|
119
91
|
- thomas@vondeyen.com
|
@@ -123,13 +95,12 @@ extra_rdoc_files: []
|
|
123
95
|
files:
|
124
96
|
- MIT-LICENSE
|
125
97
|
- README.md
|
98
|
+
- app/models/alchemy/attachment/s3_url.rb
|
99
|
+
- app/models/alchemy/picture/s3_url.rb
|
126
100
|
- lib/alchemy-dragonfly-s3.rb
|
127
|
-
- lib/alchemy/
|
101
|
+
- lib/alchemy/dragonfly/s3/create_picture_thumb.rb
|
128
102
|
- lib/alchemy/dragonfly/s3/engine.rb
|
129
103
|
- lib/alchemy/dragonfly/s3/version.rb
|
130
|
-
- lib/alchemy/essence_picture_monkey_patch.rb
|
131
|
-
- lib/alchemy/picture_monkey_patch.rb
|
132
|
-
- lib/tasks/alchemy_dragonfly_s3/generate.rake
|
133
104
|
homepage: https://alchemy-cms.com
|
134
105
|
licenses:
|
135
106
|
- MIT
|
@@ -1,19 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Alchemy
|
4
|
-
module EssencePictureMonkeyPatch
|
5
|
-
def picture_url(options = {})
|
6
|
-
super || "missing-image.png"
|
7
|
-
end
|
8
|
-
|
9
|
-
def thumbnail_url
|
10
|
-
super || "alchemy/missing-image.svg"
|
11
|
-
end
|
12
|
-
|
13
|
-
def allow_image_cropping?
|
14
|
-
super && !!picture.image_file
|
15
|
-
end
|
16
|
-
|
17
|
-
EssencePicture.prepend(self)
|
18
|
-
end
|
19
|
-
end
|
@@ -1,43 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Alchemy
|
4
|
-
module PictureMonkeyPatch
|
5
|
-
def self.prepended(klass)
|
6
|
-
klass.has_many :thumbs, class_name: "Alchemy::PictureThumb", dependent: :destroy
|
7
|
-
klass.after_create -> { PictureThumb.generate_thumbs!(self) }
|
8
|
-
end
|
9
|
-
|
10
|
-
# Returns an url (or relative path) to a processed image for use inside an image_tag helper.
|
11
|
-
#
|
12
|
-
# Any additional options are passed to the url method, so you can add params to your url.
|
13
|
-
#
|
14
|
-
# Example:
|
15
|
-
#
|
16
|
-
# <%= image_tag picture.url(size: '320x200', format: 'png') %>
|
17
|
-
#
|
18
|
-
# @see Alchemy::PictureVariant#call for transformation options
|
19
|
-
# @see Alchemy::Picture::Url#call for url options
|
20
|
-
# @return [String|Nil]
|
21
|
-
def url(options = {})
|
22
|
-
return unless image_file
|
23
|
-
|
24
|
-
variant = PictureVariant.new(self, options.slice(*Picture::TRANSFORMATION_OPTIONS))
|
25
|
-
Picture::S3Url.new(variant).call(options.except(*Picture::TRANSFORMATION_OPTIONS).merge(
|
26
|
-
basename: name,
|
27
|
-
ext: variant.render_format,
|
28
|
-
name: name,
|
29
|
-
))
|
30
|
-
rescue ::Dragonfly::Job::Fetch::NotFound => e
|
31
|
-
log_warning(e.message)
|
32
|
-
nil
|
33
|
-
end
|
34
|
-
|
35
|
-
Picture::THUMBNAIL_SIZES = {
|
36
|
-
small: "80x60",
|
37
|
-
medium: "160x120",
|
38
|
-
large: "240x180",
|
39
|
-
}.with_indifferent_access.freeze
|
40
|
-
|
41
|
-
Picture.prepend(self)
|
42
|
-
end
|
43
|
-
end
|
@@ -1,37 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
namespace :alchemy_dragonfly_s3 do
|
4
|
-
namespace :generate do
|
5
|
-
desc "Generates all thumbnails for Alchemy Pictures and EssencePictures."
|
6
|
-
task thumbnails: [
|
7
|
-
"alchemy_dragonfly_s3:generate:picture_thumbnails",
|
8
|
-
"alchemy_dragonfly_s3:generate:essence_picture_thumbnails"
|
9
|
-
]
|
10
|
-
|
11
|
-
desc "Generates thumbnails for Alchemy Pictures."
|
12
|
-
task picture_thumbnails: :environment do
|
13
|
-
puts "Regenerate #{Alchemy::Picture.count} picture thumbnails."
|
14
|
-
puts "Please wait..."
|
15
|
-
|
16
|
-
Alchemy::Picture.find_each do |picture|
|
17
|
-
puts Alchemy::PictureThumb.generate_thumbs!(picture)
|
18
|
-
end
|
19
|
-
|
20
|
-
puts "Done!"
|
21
|
-
end
|
22
|
-
|
23
|
-
desc "Generates thumbnails for Alchemy EssencePictures."
|
24
|
-
task essence_picture_thumbnails: :environment do
|
25
|
-
essence_pictures = Alchemy::EssencePicture.joins(:content, :ingredient_association)
|
26
|
-
puts "Regenerate #{essence_pictures.count} essence picture thumbnails."
|
27
|
-
puts "Please wait..."
|
28
|
-
|
29
|
-
essence_pictures.find_each do |essence_picture|
|
30
|
-
puts essence_picture.picture_url
|
31
|
-
puts essence_picture.thumbnail_url
|
32
|
-
end
|
33
|
-
|
34
|
-
puts "Done!"
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|