Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
tvdeyen committed Jun 22, 2020
0 parents commit 02ad3d2
Show file tree
Hide file tree
Showing 11 changed files with 162 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.bundle/
log/*.log
pkg/
Gemfile.lock
17 changes: 17 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
source 'https://rubygems.org'
git_source(:github) { |repo| "https://github.com/#{repo}.git" }

# Declare your gem's dependencies in alchemy_s3.gemspec.
# Bundler will treat runtime dependencies like base dependencies, and
# development dependencies will be added by default to the :development group.
gemspec

gem 'alchemy_cms', github: 'AlchemyCMS/alchemy_cms'

# Declare any dependencies that are still in development here instead of in
# your gemspec. These might include edge Rails or gems from your path or
# Git. Remember to move these dependencies to your gemspec before releasing
# your gem to rubygems.org.

# To use a debugger
# gem 'byebug', group: [:development, :test]
20 changes: 20 additions & 0 deletions MIT-LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Copyright 2020 Thomas von Deyen

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# AlchemyCMS AWS S3

## Installation

Add this line to your application's Gemfile:

```ruby
gem 'alchemy-dragonfly-s3', github: 'AlchemyCMS/alchemy-dragonfly-s3'
```

And then execute:

```
$ bundle
```

## License
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
19 changes: 19 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
begin
require 'bundler/setup'
rescue LoadError
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
end

require 'rdoc/task'

RDoc::Task.new(:rdoc) do |rdoc|
rdoc.rdoc_dir = 'rdoc'
rdoc.title = 'AlchemyS3'
rdoc.options << '--line-numbers'
rdoc.rdoc_files.include('README.md')
rdoc.rdoc_files.include('lib/**/*.rb')
end

load 'rails/tasks/statistics.rake'

require 'bundler/gem_tasks'
22 changes: 22 additions & 0 deletions alchemy-dragonfly-s3.gemspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# frozen_string_literal: true

$:.push File.expand_path("lib", __dir__)

require "alchemy/dragonfly/s3/version"

# Describe your gem and declare its dependencies:
Gem::Specification.new do |s|
s.name = "alchemy-dragonfly-s3"
s.version = Alchemy::Dragonfly::S3::VERSION
s.authors = ["Thomas von Deyen"]
s.email = ["[email protected]"]
s.homepage = "https://alchemy-cms.com"
s.summary = "AlchemyCMS Dragonfly S3."
s.description = "AlchemyCMS Integration for the Dragonfly S3 datastore."
s.license = "MIT"

s.files = Dir["lib/**/*", "MIT-LICENSE", "README.md"]

s.add_dependency "alchemy_cms", [">= 3.5", "< 5"]
s.add_dependency "dragonfly-s3_data_store", "~> 1.3"
end
13 changes: 13 additions & 0 deletions app/models/alchemy/picture/s3_url.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# frozen_string_literal: true

module Alchemy
class Picture < BaseRecord
class S3Url < Url
def call(*)
return variant.image.remote_url unless processible_image?

::Dragonfly.app(:alchemy_pictures).remote_url_for(uid)
end
end
end
end
5 changes: 5 additions & 0 deletions lib/alchemy-dragonfly-s3.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# frozen_string_literal: true

require "alchemy_cms"
require "alchemy/dragonfly/s3/create_picture_thumb"
require "alchemy/dragonfly/s3/engine"
19 changes: 19 additions & 0 deletions lib/alchemy/dragonfly/s3/create_picture_thumb.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# frozen_string_literal: true

module Alchemy
module Dragonfly
module S3
class CreatePictureThumb
def self.call(variant, signature, uid)
image = variant.image
image.store(path: uid)
Alchemy::PictureThumb.create!(
picture: variant.picture,
signature: signature,
uid: uid,
)
end
end
end
end
end
16 changes: 16 additions & 0 deletions lib/alchemy/dragonfly/s3/engine.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# frozen_string_literal: true

module Alchemy
module Dragonfly
module S3
class Engine < ::Rails::Engine
engine_name "alchemy_dragonfly_s3"

config.after_initialize do
Alchemy::Picture.url_class = Alchemy::Picture::S3Url
Alchemy::PictureThumb.generator_class = Alchemy::Dragonfly::S3::CreatePictureThumb
end
end
end
end
end
9 changes: 9 additions & 0 deletions lib/alchemy/dragonfly/s3/version.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# frozen_string_literal: true

module Alchemy
module Dragonfly
module S3
VERSION = "0.1.0"
end
end
end

0 comments on commit 02ad3d2

Please sign in to comment.