Sha256: 37f79cf12a896bbd7ca4096da1dd3dac149e341d0b2244dd26c1a1eb84610cb5
Contents?: true
Size: 1.18 KB
Versions: 4
Compression:
Stored size: 1.18 KB
Contents
# frozen_string_literal: true module Ckeditor class PictureUploader < Shrine plugin :determine_mime_type plugin :validation_helpers plugin :processing plugin :versions Attacher.validate do validate_mime_type_inclusion %w[image/jpeg image/gif image/png] validate_max_size 2.megabytes end process(:store) do |io, _context| # return the hash of processed files {}.tap do |versions| io.download do |original| pipeline = SHRINE_PICTURE_PROCESSOR.source(original) versions[:content] = pipeline.resize_to_limit!(800, 800) versions[:thumb] = pipeline.resize_to_limit!(118, 100) end end end end class Picture < Ckeditor::Asset include PictureUploader.attachment(:data) validates :data, presence: true def url_content data_url(:content) end def url_thumb data_url(:thumb) end def path data[:thumb].storage.path(data[:thumb].id) end def datasource @datasource ||= HashWithIndifferentAccess .new(data) .fetch(:thumb, OpenStruct.new(metadata: {})) .metadata end end end
Version data entries
4 entries across 4 versions & 1 rubygems