diff options
author | Alexis Reigel <mail@koffeinfrei.org> | 2017-09-26 09:51:24 +0200 |
---|---|---|
committer | Alexis Reigel <mail@koffeinfrei.org> | 2018-06-05 16:20:06 +0200 |
commit | c8a4d202c99c772822a2b9b09fa6da2c90b2ae81 (patch) | |
tree | 0680404038d5923bd659e8557dd578341d4688d2 | |
parent | 9921830267ccef2321e9a57383b28daafd34fa78 (diff) | |
download | gitlab-ce-c8a4d202c99c772822a2b9b09fa6da2c90b2ae81.tar.gz |
favicon uploader generating ci status favicons
14 files changed, 85 insertions, 0 deletions
@@ -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' diff --git a/Gemfile.lock b/Gemfile.lock index 2daaa3b516e..7437b6e7898 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -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) diff --git a/app/assets/images/ci_favicons/overlays/favicon_status_canceled.png b/app/assets/images/ci_favicons/overlays/favicon_status_canceled.png Binary files differnew file mode 100644 index 00000000000..8adaa9c600b --- /dev/null +++ b/app/assets/images/ci_favicons/overlays/favicon_status_canceled.png diff --git a/app/assets/images/ci_favicons/overlays/favicon_status_created.png b/app/assets/images/ci_favicons/overlays/favicon_status_created.png Binary files differnew file mode 100644 index 00000000000..ca788dd0034 --- /dev/null +++ b/app/assets/images/ci_favicons/overlays/favicon_status_created.png diff --git a/app/assets/images/ci_favicons/overlays/favicon_status_failed.png b/app/assets/images/ci_favicons/overlays/favicon_status_failed.png Binary files differnew file mode 100644 index 00000000000..93f1e2772fd --- /dev/null +++ b/app/assets/images/ci_favicons/overlays/favicon_status_failed.png diff --git a/app/assets/images/ci_favicons/overlays/favicon_status_manual.png b/app/assets/images/ci_favicons/overlays/favicon_status_manual.png Binary files differnew file mode 100644 index 00000000000..c926062c806 --- /dev/null +++ b/app/assets/images/ci_favicons/overlays/favicon_status_manual.png diff --git a/app/assets/images/ci_favicons/overlays/favicon_status_not_found.png b/app/assets/images/ci_favicons/overlays/favicon_status_not_found.png Binary files differnew file mode 100644 index 00000000000..df3049315a9 --- /dev/null +++ b/app/assets/images/ci_favicons/overlays/favicon_status_not_found.png diff --git a/app/assets/images/ci_favicons/overlays/favicon_status_pending.png b/app/assets/images/ci_favicons/overlays/favicon_status_pending.png Binary files differnew file mode 100644 index 00000000000..f7d67d4a230 --- /dev/null +++ b/app/assets/images/ci_favicons/overlays/favicon_status_pending.png diff --git a/app/assets/images/ci_favicons/overlays/favicon_status_running.png b/app/assets/images/ci_favicons/overlays/favicon_status_running.png Binary files differnew file mode 100644 index 00000000000..ff4167c4b20 --- /dev/null +++ b/app/assets/images/ci_favicons/overlays/favicon_status_running.png diff --git a/app/assets/images/ci_favicons/overlays/favicon_status_skipped.png b/app/assets/images/ci_favicons/overlays/favicon_status_skipped.png Binary files differnew file mode 100644 index 00000000000..a9c36464b69 --- /dev/null +++ b/app/assets/images/ci_favicons/overlays/favicon_status_skipped.png diff --git a/app/assets/images/ci_favicons/overlays/favicon_status_success.png b/app/assets/images/ci_favicons/overlays/favicon_status_success.png Binary files differnew file mode 100644 index 00000000000..bcc30c73f5f --- /dev/null +++ b/app/assets/images/ci_favicons/overlays/favicon_status_success.png diff --git a/app/assets/images/ci_favicons/overlays/favicon_status_warning.png b/app/assets/images/ci_favicons/overlays/favicon_status_warning.png Binary files differnew file mode 100644 index 00000000000..6db3b0280f5 --- /dev/null +++ b/app/assets/images/ci_favicons/overlays/favicon_status_warning.png diff --git a/app/uploaders/favicon_uploader.rb b/app/uploaders/favicon_uploader.rb new file mode 100644 index 00000000000..dc30e838337 --- /dev/null +++ b/app/uploaders/favicon_uploader.rb @@ -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 diff --git a/spec/uploaders/favicon_uploader_spec.rb b/spec/uploaders/favicon_uploader_spec.rb new file mode 100644 index 00000000000..5989d294112 --- /dev/null +++ b/spec/uploaders/favicon_uploader_spec.rb @@ -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 |