alchemy_cloudinary 1.0.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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: f6013eec238f7a1c44af91041e61a1f4c3f1ee8491f8a5aff6b70f67a3f9af8f
4
+ data.tar.gz: bb3387d30961d38a25be56fbce96d22c842c660821f853cd58a2e67d71f5e1de
5
+ SHA512:
6
+ metadata.gz: 886357acc1f48531e783aa4db24ec103a32ab0328f696fe7c25b4a4fd75d78042b18fce61fce0e7a05f89789eadaf1808ea65bdb26f64840004e279f9e403869
7
+ data.tar.gz: 3f3cd82adf0f391be4f0c88477de99fdf72d7d587c47767a03bcd9d58162c66eabc5e9411874a6a63d7242a22a8f151e5d9f7239ade753694425c96701485373
@@ -0,0 +1,20 @@
1
+ Copyright 2018 Thomas von Deyen
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,94 @@
1
+ # AlchemyCMS Cloudinary Integration
2
+
3
+ Cloudinary is a cloud service that offers a solution to a web application's entire image management pipeline.
4
+
5
+ * Easily upload images to the cloud.
6
+ * Automatically perform smart image resizing, cropping and conversion without installing any complex software.
7
+ * Images are seamlessly delivered through a fast CDN, and much much more.
8
+
9
+ ## Usage
10
+
11
+ ## Installation
12
+
13
+ Add this line to your application's Gemfile:
14
+
15
+ ```ruby
16
+ gem 'alchemy_cloudinary', github: 'AlchemyCMS/alchemy_cloudinary'
17
+ ```
18
+
19
+ And then execute:
20
+
21
+ ```
22
+ $ bundle
23
+ ```
24
+
25
+ Or install it yourself as:
26
+
27
+ ```
28
+ $ gem install alchemy_cloudinary
29
+ ```
30
+
31
+ ## Configuration
32
+
33
+ To use the Cloudinary Ruby on Rails library, you have to configure at least:
34
+
35
+ * `cloud_name`
36
+ * `api_key`
37
+ * `api_secret`
38
+
39
+ Setting the configuration parameters can be done by:
40
+
41
+ * programmatically in each call to a Cloudinary method
42
+ * globally using config/cloudinary.yml configuration file
43
+
44
+ > **Warning**: In this case you must **exclude it** from version control system (git, etc). In `.gitignore` you can add `config/cloudinary.yml`
45
+
46
+ * use a Rails initializer file.
47
+
48
+ You can place a file named `cloudinary.rb` in the `config/initializers` folder of your Rails project.
49
+
50
+ Here's some sample initializer code:
51
+
52
+ ```ruby
53
+ # config/initializer/cloudinary.rb
54
+ Cloudinary.config do |config|
55
+ config.cloud_name = 'sample'
56
+ config.api_key = '874837483274837'
57
+ config.api_secret = 'a676b67565c6767a6767d6767f676fe1'
58
+ config.secure = true
59
+ config.cdn_subdomain = true
60
+ end
61
+ ```
62
+
63
+ * dynamically configure the `cloud_name`, `api_key`, and `api_secret` by defining the `CLOUDINARY_URL` environment variable.
64
+
65
+ The **configuration URL** is available in the Management Console's dashboard of your account.
66
+ When using Cloudinary through a PaaS add-on (e.g., **Heroku**), this environment variable is
67
+ **automatically** defined in your deployment environment.
68
+
69
+ Here's a sample value:
70
+
71
+ `CLOUDINARY_URL=cloudinary://874837483274837:a676b67565c6767a6767d6767f676fe1@sample`
72
+
73
+ > **Note**: If you use more than one configuration option, the order of precedence is:
74
+ `CLOUDINARY_URL` -> `cloud_name` -> `cloudinary.yml`
75
+
76
+ ## Resources
77
+
78
+ * https://cloudinary.com/documentation/rails_integration
79
+ * Sample projects - https://github.com/cloudinary/cloudinary_gem/tree/master/samples
80
+ * Basic Ruby sample.
81
+ Uploading local and remote images to Cloudinary and generating various transformation URLs.
82
+ * Basic Rails sample.
83
+ Uploading local and remote images in a Rails project while embedding various transformed images in a Rails web view.
84
+ * Rails Photo Album.
85
+ A fully working web application.
86
+ It uses CarrierWave to manage images of an album model (database).
87
+ Performs image uploading both from the server side and directly from the browser using a jQuery plugin.
88
+ * https://rubygems.org/gems/cloudinary
89
+ * https://github.com/cloudinary/cloudinary_gem
90
+ * https://cloudinary.com/documentation/rails_image_and_video_upload
91
+ * https://cloudinary.com/documentation/rails_image_manipulation
92
+
93
+ ## License
94
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,47 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Alchemy
4
+ module Picture::CloudinaryUrl
5
+ def url(options = {})
6
+ @options = options
7
+ image_file.remote_url(transformation: transformations, secure: !!options[:secure])
8
+ end
9
+
10
+ private
11
+
12
+ def transformations
13
+ [crop_transformation, resize_transformation].compact
14
+ end
15
+
16
+ def crop_transformation
17
+ if @options[:crop] && @options[:crop_from].present?
18
+ {
19
+ crop: 'crop',
20
+ gravity: 'xy_center',
21
+ x: crop_coordinates[:x],
22
+ y: crop_coordinates[:y],
23
+ size: @options[:crop_size]
24
+ }
25
+ end
26
+ end
27
+
28
+ def resize_transformation
29
+ crop_mode = @options[:crop] ? 'fill' : @options[:upsample] ? 'fit' : 'limit'
30
+ if @options[:size]
31
+ {
32
+ crop: crop_mode,
33
+ size: @options[:size]
34
+ }
35
+ end
36
+ end
37
+
38
+ def crop_coordinates
39
+ x, y = @options[:crop_from].to_s.split('x')
40
+ size_x, size_y = @options[:crop_size].to_s.split('x')
41
+ {
42
+ x: (x.to_i + size_x.to_f / 2).round,
43
+ y: (y.to_i + size_y.to_f / 2).round
44
+ }
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'alchemy_cloudinary/engine'
@@ -0,0 +1,49 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'cloudinary'
4
+
5
+ module AlchemyCloudinary
6
+ class DragonflyDataStore
7
+ def write(content, opts = {})
8
+ result = Cloudinary::Uploader.upload(content.file, {
9
+ public_id: name(content.name)
10
+ }.merge(opts))
11
+ "#{result['public_id']}.#{result['format']}"
12
+ end
13
+
14
+ def read(uid)
15
+ url = Cloudinary::Utils.cloudinary_url(public_id(uid), format: ext(uid) || 'jpg')
16
+ [Cloudinary::Downloader.download(url), {'name' => name(uid)}]
17
+ end
18
+
19
+ def destroy(uid)
20
+ Cloudinary::Uploader.destroy public_id(uid)
21
+ end
22
+
23
+ def url_for(uid, options = {})
24
+ options = {format: ext(uid)}.merge(options)
25
+ Cloudinary::Utils.cloudinary_url(public_id(uid), options)
26
+ end
27
+
28
+ private
29
+
30
+ def public_id(uid)
31
+ File.basename(uid, ext(uid, true))
32
+ end
33
+
34
+ def name(uid)
35
+ pid = public_id(uid)
36
+ if pid.include?('_')
37
+ public_id(uid).split('_')[0..-1].join
38
+ else
39
+ pid
40
+ end
41
+ end
42
+
43
+ def ext(uid, with_dot = false)
44
+ ext = File.extname(uid)
45
+ ext[0] = '' if ext && !with_dot
46
+ ext
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ module AlchemyCloudinary
4
+ class Engine < ::Rails::Engine
5
+ config.before_initialize do
6
+ require 'dragonfly'
7
+ require 'alchemy_cloudinary/dragonfly_data_store'
8
+
9
+ Dragonfly::App.register_datastore(:alchemy_cloudinary) do
10
+ AlchemyCloudinary::DragonflyDataStore
11
+ end
12
+ end
13
+
14
+ config.to_prepare do
15
+ file = 'alchemy/picture/cloudinary_url'
16
+ Rails.configuration.cache_classes ? require(file) : load(file)
17
+ Alchemy::Picture.prepend(Alchemy::Picture::CloudinaryUrl)
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module AlchemyCloudinary
4
+ VERSION = '1.0.0'
5
+ end
metadata ADDED
@@ -0,0 +1,84 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: alchemy_cloudinary
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Thomas von Deyen
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-03-14 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: alchemy_cms
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 4.1.0.beta
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '5'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: 4.1.0.beta
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '5'
33
+ - !ruby/object:Gem::Dependency
34
+ name: cloudinary
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '1.9'
40
+ type: :runtime
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '1.9'
47
+ description: AlchemyCMS Cloudinary Integration.
48
+ email:
49
+ - thomas@vondeyen.com
50
+ executables: []
51
+ extensions: []
52
+ extra_rdoc_files: []
53
+ files:
54
+ - MIT-LICENSE
55
+ - README.md
56
+ - lib/alchemy/picture/cloudinary_url.rb
57
+ - lib/alchemy_cloudinary.rb
58
+ - lib/alchemy_cloudinary/dragonfly_data_store.rb
59
+ - lib/alchemy_cloudinary/engine.rb
60
+ - lib/alchemy_cloudinary/version.rb
61
+ homepage: https://alchemy-cms.com
62
+ licenses:
63
+ - MIT
64
+ metadata: {}
65
+ post_install_message:
66
+ rdoc_options: []
67
+ require_paths:
68
+ - lib
69
+ required_ruby_version: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
74
+ required_rubygems_version: !ruby/object:Gem::Requirement
75
+ requirements:
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
79
+ requirements: []
80
+ rubygems_version: 3.0.3
81
+ signing_key:
82
+ specification_version: 4
83
+ summary: AlchemyCMS Cloudinary Integration.
84
+ test_files: []