fix carrierwave suffix for different format

when versions have a different file format from the original file
carrierwave constructs a wrong url (with the original file suffix).
This commit is contained in:
Alexis Reigel 2017-09-26 15:02:00 +02:00
parent ce6172e863
commit 18d4f121d3
No known key found for this signature in database
GPG key ID: C728AF10972E97C0

View file

@ -14,24 +14,27 @@ class FaviconUploader < AttachmentUploader
:status_running
].freeze
version :default_without_format_conversion do
version :default do
process resize_to_fill: [32, 32]
end
# this intermediate version generates an image in the ico format but with the
# original file suffix.
version :_default, from_version: :default_without_format_conversion do
process convert: 'ico'
end
version :default, from_version: :_default
def full_filename(filename)
filename_for_different_format(super(filename), 'ico')
end
end
STATUS_ICON_NAMES.each do |status_name|
version status_name, from_version: :default do
process status_favicon: status_name
def full_filename(filename)
filename_for_different_format(super(filename), 'ico')
end
end
end
private
def status_favicon(status_name)
manipulate! do |img|
overlay_path = Rails.root.join("app/assets/images/ci_favicons/overlays/favicon_#{status_name}.png")
@ -41,4 +44,8 @@ class FaviconUploader < AttachmentUploader
end
end
end
def filename_for_different_format(filename, format)
filename.chomp(File.extname(filename)) + ".#{format}"
end
end