From 71c9c3709d5d42b43e3a8385085ef02b4b614bc9 Mon Sep 17 00:00:00 2001 From: Thomas von Deyen Date: Tue, 12 Apr 2022 17:56:52 +0200 Subject: [PATCH] Remove Dragonfly --- alchemy_cms.gemspec | 2 - app/models/alchemy/picture.rb | 4 +- config/alchemy/config.yml | 23 ++++++------ config/initializers/dragonfly.rb | 21 ----------- .../dragonfly/processors/auto_orient.rb | 18 --------- .../dragonfly/processors/crop_resize.rb | 35 ------------------ lib/alchemy/engine.rb | 11 ------ lib/alchemy_cms.rb | 1 - .../alchemy/install/install_generator.rb | 8 ---- .../alchemy/install/templates/dragonfly.rb.tt | 35 ------------------ spec/dummy/config/initializers/dragonfly.rb | 37 ------------------- .../dragonfly/processors/auto_orient_spec.rb | 17 --------- .../dragonfly/processors/crop_resize_spec.rb | 23 ------------ spec/support/dragonfly_test_app.rb | 8 ---- 14 files changed, 13 insertions(+), 230 deletions(-) delete mode 100644 config/initializers/dragonfly.rb delete mode 100644 lib/alchemy/dragonfly/processors/auto_orient.rb delete mode 100644 lib/alchemy/dragonfly/processors/crop_resize.rb delete mode 100644 lib/generators/alchemy/install/templates/dragonfly.rb.tt delete mode 100644 spec/dummy/config/initializers/dragonfly.rb delete mode 100644 spec/libraries/dragonfly/processors/auto_orient_spec.rb delete mode 100644 spec/libraries/dragonfly/processors/crop_resize_spec.rb delete mode 100644 spec/support/dragonfly_test_app.rb diff --git a/alchemy_cms.gemspec b/alchemy_cms.gemspec index b6ad353037..29582c1458 100644 --- a/alchemy_cms.gemspec +++ b/alchemy_cms.gemspec @@ -38,8 +38,6 @@ Gem::Specification.new do |gem| gem.add_runtime_dependency "awesome_nested_set", ["~> 3.1"] gem.add_runtime_dependency "cancancan", [">= 2.1", "< 4.0"] gem.add_runtime_dependency "coffee-rails", [">= 4.0", "< 6.0"] - gem.add_runtime_dependency "dragonfly", ["~> 1.4"] - gem.add_runtime_dependency "dragonfly_svg", ["~> 0.0.4"] gem.add_runtime_dependency "gutentag", ["~> 2.2", ">= 2.2.1"] gem.add_runtime_dependency "handlebars_assets", ["~> 0.23"] gem.add_runtime_dependency "image_processing", [">= 1.2"] diff --git a/app/models/alchemy/picture.rb b/app/models/alchemy/picture.rb index 1101cf7e40..a4f1dc5729 100644 --- a/app/models/alchemy/picture.rb +++ b/app/models/alchemy/picture.rb @@ -57,8 +57,8 @@ class Picture < BaseRecord # # === CAUTION # - # This HAS to be placed for Dragonfly's class methods, - # to ensure this runs before Dragonfly's before_destroy callback. + # This HAS to be placed for ActiveStorage class methods, + # to ensure this runs before ActiveStorage before_destroy callback. # before_destroy unless: :deletable? do raise PictureInUseError, Alchemy.t(:cannot_delete_picture_notice) % { name: name } diff --git a/config/alchemy/config.yml b/config/alchemy/config.yml index efd757f7e6..0462a5ddd0 100644 --- a/config/alchemy/config.yml +++ b/config/alchemy/config.yml @@ -62,7 +62,7 @@ items_per_page: 15 # === Picture rendering settings # -# Alchemy uses Dragonfly to render images. Settings for image rendering are specific to elements and are defined in elements.yml +# Alchemy uses ActiveStorage to render images. Settings for image rendering are specific to elements and are defined in elements.yml # # Example: # - name: some_element @@ -74,8 +74,6 @@ items_per_page: 15 # crop: true # turns on image cropping # size: '500x500' # image will be cropped to this size # -# See http://markevans.github.com/dragonfly for further info. -# # ==== Global Options: # # output_image_jpg_quality [Integer] # If image gets rendered as JPG this is the quality setting for it. (Default 85) @@ -92,7 +90,7 @@ sharpen_images: false # This is used by the seeder to create the default site. default_site: name: Default Site - host: '*' + host: "*" # This is the default language when seeding. default_language: @@ -134,7 +132,8 @@ mailer: mail_from: your.mail@your-domain.com mail_to: your.mail@your-domain.com subject: A new contact form message - fields: [salutation, firstname, lastname, address, zip, city, phone, email, message] + fields: + [salutation, firstname, lastname, address, zip, city, phone, email, message] validate_fields: [lastname, email] # === User roles @@ -167,14 +166,14 @@ uploader: file_size_limit: 100 allowed_filetypes: alchemy/attachments: - - '*' + - "*" alchemy/pictures: - - jpg - - jpeg - - gif - - png - - svg - - webp + - jpg + - jpeg + - gif + - png + - svg + - webp # === Link Target Options # diff --git a/config/initializers/dragonfly.rb b/config/initializers/dragonfly.rb deleted file mode 100644 index 017e8fecf6..0000000000 --- a/config/initializers/dragonfly.rb +++ /dev/null @@ -1,21 +0,0 @@ -# frozen_string_literal: true -require "dragonfly_svg" -require "alchemy/dragonfly/processors/crop_resize" -require "alchemy/dragonfly/processors/auto_orient" - -# Logger -Dragonfly.logger = Rails.logger - -# Add model functionality -if defined?(ActiveRecord::Base) - ActiveRecord::Base.extend Dragonfly::Model - ActiveRecord::Base.extend Dragonfly::Model::Validations -end - -# Dragonfly 1.4.0 only allows `quality` as argument to `encode` -Dragonfly::ImageMagick::Processors::Encode::WHITELISTED_ARGS << "flatten" - -Rails.application.config.after_initialize do - Dragonfly.app(:alchemy_pictures).add_processor(:crop_resize, Alchemy::Dragonfly::Processors::CropResize.new) - Dragonfly.app(:alchemy_pictures).add_processor(:auto_orient, Alchemy::Dragonfly::Processors::AutoOrient.new) -end diff --git a/lib/alchemy/dragonfly/processors/auto_orient.rb b/lib/alchemy/dragonfly/processors/auto_orient.rb deleted file mode 100644 index 732c4bc099..0000000000 --- a/lib/alchemy/dragonfly/processors/auto_orient.rb +++ /dev/null @@ -1,18 +0,0 @@ -# frozen_string_literal: true - -require "dragonfly/image_magick/commands" - -module Alchemy - module Dragonfly - module Processors - class AutoOrient - def call(content) - ::Dragonfly::ImageMagick::Commands.convert( - content, - "-auto-orient" - ) - end - end - end - end -end diff --git a/lib/alchemy/dragonfly/processors/crop_resize.rb b/lib/alchemy/dragonfly/processors/crop_resize.rb deleted file mode 100644 index be664ddf9d..0000000000 --- a/lib/alchemy/dragonfly/processors/crop_resize.rb +++ /dev/null @@ -1,35 +0,0 @@ -# frozen_string_literal: true - -require "dragonfly/image_magick/commands" - -module Alchemy - module Dragonfly - module Processors - class CropResize - include ::Dragonfly::ParamValidators - - IS_CROP_ARGUMENT = ->(args_string) { - args_string.match?(::Dragonfly::ImageMagick::Processors::Thumb::CROP_GEOMETRY) - } - - IS_RESIZE_ARGUMENT = ->(args_string) { - args_string.match?(::Dragonfly::ImageMagick::Processors::Thumb::RESIZE_GEOMETRY) - } - - def call(content, crop_argument, resize_argument) - validate!(crop_argument, &IS_CROP_ARGUMENT) - validate!(resize_argument, &IS_RESIZE_ARGUMENT) - ::Dragonfly::ImageMagick::Commands.convert( - content, - "-crop #{crop_argument} -resize #{resize_argument}" - ) - end - - def update_url(attrs, _args = "", opts = {}) - format = opts["format"] - attrs.ext = format if format - end - end - end - end -end diff --git a/lib/alchemy/engine.rb b/lib/alchemy/engine.rb index 47a03647ae..707b282e56 100644 --- a/lib/alchemy/engine.rb +++ b/lib/alchemy/engine.rb @@ -45,16 +45,5 @@ class Engine < Rails::Engine end end end - - initializer "alchemy.webp-mime_type" do - # Rails does not know anything about webp even in 2022 - unless Mime::Type.lookup_by_extension(:webp) - Mime::Type.register("image/webp", :webp) - end - # Dragonfly uses Rack to read the mime type and guess what - unless Rack::Mime::MIME_TYPES[".webp"] - Rack::Mime::MIME_TYPES[".webp"] = "image/webp" - end - end end end diff --git a/lib/alchemy_cms.rb b/lib/alchemy_cms.rb index 3ccfe96623..3e54672124 100644 --- a/lib/alchemy_cms.rb +++ b/lib/alchemy_cms.rb @@ -9,7 +9,6 @@ require "active_model_serializers" require "awesome_nested_set" require "cancan" -require "dragonfly" require "gutentag" require "handlebars_assets" require "jquery-rails" diff --git a/lib/generators/alchemy/install/install_generator.rb b/lib/generators/alchemy/install/install_generator.rb index d817964808..201116badc 100644 --- a/lib/generators/alchemy/install/install_generator.rb +++ b/lib/generators/alchemy/install/install_generator.rb @@ -71,14 +71,6 @@ def copy_demo_views copy_file "alchemy.en.yml", app_config_path.join("locales", "alchemy.en.yml") end - def copy_dragonfly_config - template( - "#{__dir__}/templates/dragonfly.rb.tt", - app_config_path.join("initializers", "dragonfly.rb"), - skip: options[:auto_accept] - ) - end - def install_gutentag_migrations rake "gutentag:install:migrations" end diff --git a/lib/generators/alchemy/install/templates/dragonfly.rb.tt b/lib/generators/alchemy/install/templates/dragonfly.rb.tt deleted file mode 100644 index ee1757af09..0000000000 --- a/lib/generators/alchemy/install/templates/dragonfly.rb.tt +++ /dev/null @@ -1,35 +0,0 @@ -# AlchemyCMS Dragonfly configuration. -# -# Consider using some kind of caching solution for image processing. -# For small projects, we have good experience with Rack::Cache. -# -# Larger installations should consider using a CDN, start reading -# http://markevans.github.io/dragonfly/cache/ -# -# A complete reference can be found at -# http://markevans.github.io/dragonfly/configuration -# -# Pictures -# -Dragonfly.app(:alchemy_pictures).configure do - dragonfly_url nil - plugin :imagemagick - plugin :svg - secret "<%= SecureRandom.hex(32) %>" - url_format "/pictures/:job/:basename.:ext" - - datastore :file, - root_path: Rails.root.join("uploads/pictures").to_s, - server_root: Rails.root.join("public"), - store_meta: false -end - -# Mount as middleware -Rails.application.middleware.use Dragonfly::Middleware, :alchemy_pictures - -# Attachments -Dragonfly.app(:alchemy_attachments).configure do - datastore :file, - root_path: Rails.root.join("uploads/attachments").to_s, - store_meta: false -end diff --git a/spec/dummy/config/initializers/dragonfly.rb b/spec/dummy/config/initializers/dragonfly.rb deleted file mode 100644 index ea3b9b9854..0000000000 --- a/spec/dummy/config/initializers/dragonfly.rb +++ /dev/null @@ -1,37 +0,0 @@ -# frozen_string_literal: true - -# AlchemyCMS Dragonfly configuration. -# -# Consider using some kind of caching solution for image processing. -# For small projects, we have good experience with Rack::Cache. -# -# Larger installations should consider using a CDN, start reading -# http://markevans.github.io/dragonfly/cache/ -# -# A complete reference can be found at -# http://markevans.github.io/dragonfly/configuration/ -# -# Pictures -# -Dragonfly.app(:alchemy_pictures).configure do - dragonfly_url nil - plugin :imagemagick - plugin :svg - secret "976ee38cf5e6d65dbf58f1d355825ba33239ab7a76a432818cd592526e9c78b5" - url_format "/pictures/:job/:basename.:ext" - - datastore :file, - root_path: Rails.root.join("uploads/pictures").to_s, - server_root: Rails.root.join("public"), - store_meta: false -end - -# Mount as middleware -Rails.application.middleware.use Dragonfly::Middleware, :alchemy_pictures - -# Attachments -Dragonfly.app(:alchemy_attachments).configure do - datastore :file, - root_path: Rails.root.join("uploads/attachments").to_s, - store_meta: false -end diff --git a/spec/libraries/dragonfly/processors/auto_orient_spec.rb b/spec/libraries/dragonfly/processors/auto_orient_spec.rb deleted file mode 100644 index f4441c78ce..0000000000 --- a/spec/libraries/dragonfly/processors/auto_orient_spec.rb +++ /dev/null @@ -1,17 +0,0 @@ -# frozen_string_literal: true - -require "rails_helper" -require_relative "../../../support/dragonfly_test_app" - -RSpec.describe Alchemy::Dragonfly::Processors::AutoOrient do - let(:app) { dragonfly_test_app } - let(:file) { Pathname.new(File.expand_path("../../../fixtures/80x60.png", __dir__)) } - let(:image) { Dragonfly::Content.new(app, file) } - let(:processor) { described_class.new } - - it "works" do - expect { - processor.call(image) - }.to_not raise_error - end -end diff --git a/spec/libraries/dragonfly/processors/crop_resize_spec.rb b/spec/libraries/dragonfly/processors/crop_resize_spec.rb deleted file mode 100644 index ff61fd9a5e..0000000000 --- a/spec/libraries/dragonfly/processors/crop_resize_spec.rb +++ /dev/null @@ -1,23 +0,0 @@ -# frozen_string_literal: true - -require "rails_helper" -require_relative "../../../support/dragonfly_test_app" - -RSpec.describe Alchemy::Dragonfly::Processors::CropResize do - let(:app) { dragonfly_test_app } - let(:file) { Pathname.new(File.expand_path("../../../fixtures/80x60.png", __dir__)) } - let(:image) { Dragonfly::Content.new(app, file) } - let(:processor) { described_class.new } - - it "validates bad crop and resize arguments" do - expect { - processor.call(image, "h4ck", "m3") - }.to raise_error(Dragonfly::ParamValidators::InvalidParameter) - end - - it "works with correct crop and resize arguments" do - expect { - processor.call(image, "4x4+0+0", "20x20>") - }.to_not raise_error - end -end diff --git a/spec/support/dragonfly_test_app.rb b/spec/support/dragonfly_test_app.rb deleted file mode 100644 index ddf38f2048..0000000000 --- a/spec/support/dragonfly_test_app.rb +++ /dev/null @@ -1,8 +0,0 @@ -# frozen_string_literal: true - -def dragonfly_test_app(name = nil) - app = Dragonfly::App.instance(name) - app.datastore = Dragonfly::MemoryDataStore.new - app.secret = "test secret" - app -end