favicon uploader generating ci status favicons

This commit is contained in:
Alexis Reigel 2017-09-26 09:51:24 +02:00
parent 9921830267
commit c8a4d202c9
No known key found for this signature in database
GPG Key ID: C728AF10972E97C0
14 changed files with 85 additions and 0 deletions

View File

@ -104,6 +104,7 @@ gem 'hamlit', '~> 2.6.1'
# Files attachments
gem 'carrierwave', '~> 1.2'
gem 'mini_magick'
# Drag and Drop UI
gem 'dropzonejs-rails', '~> 0.7.1'

View File

@ -494,6 +494,7 @@ GEM
mime-types-data (~> 3.2015)
mime-types-data (3.2016.0521)
mimemagic (0.3.0)
mini_magick (4.8.0)
mini_mime (1.0.0)
mini_portile2 (2.3.0)
minitest (5.7.0)
@ -1078,6 +1079,7 @@ DEPENDENCIES
loofah (~> 2.2)
mail_room (~> 0.9.1)
method_source (~> 0.8)
mini_magick
minitest (~> 5.7.0)
mousetrap-rails (~> 1.4.6)
mysql2 (~> 0.4.10)

Binary file not shown.

After

Width:  |  Height:  |  Size: 864 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 889 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1015 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 945 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 919 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 923 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 830 B

View File

@ -0,0 +1,44 @@
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_without_format_conversion 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
STATUS_ICON_NAMES.each do |status_name|
version status_name, from_version: :default do
process status_favicon: status_name
end
end
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
end

View File

@ -0,0 +1,38 @@
require 'spec_helper'
RSpec.describe FaviconUploader do
include CarrierWave::Test::Matchers
let(:uploader) { described_class.new(build_stubbed(:user)) }
after do
uploader.remove!
end
def upload_fixture(filename)
fixture_file_upload(Rails.root.join('spec', 'fixtures', filename))
end
context 'versions' do
before do
uploader.store!(upload_fixture('dk.png'))
end
it 'has the correct format' do
expect(uploader.default).to be_format('ico')
end
it 'has the correct dimensions' do
expect(uploader.default).to have_dimensions(32, 32)
end
it 'generates all the status icons' do
# make sure that the following each statement actually loops
expect(FaviconUploader::STATUS_ICON_NAMES.count).to eq 10
FaviconUploader::STATUS_ICON_NAMES.each do |status_name|
expect(File.exist?(uploader.status_not_found.file.file)).to be true
end
end
end
end