1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
class FaviconUploader < AttachmentUploader
include CarrierWave::MiniMagick
STATUS_ICON_NAMES = [
:status_not_found,
:status_canceled,
:status_success,
:status_skipped,
:status_created,
:status_failed,
:status_warning,
:status_pending,
:status_manual,
:status_running
].freeze
version :default do
process resize_to_fill: [32, 32]
process convert: 'ico'
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")
overlay = MiniMagick::Image.open(overlay_path)
img.composite(overlay) do |c|
c.compose 'over'
end
end
end
def filename_for_different_format(filename, format)
filename.chomp(File.extname(filename)) + ".#{format}"
end
end
|