2018-10-22 03:00:50 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-09-26 11:04:37 -04:00
|
|
|
module Gitlab
|
|
|
|
class Favicon
|
|
|
|
class << self
|
2017-09-28 07:57:08 -04:00
|
|
|
def main
|
2018-04-13 15:40:32 -04:00
|
|
|
image_name =
|
2019-06-11 08:07:24 -04:00
|
|
|
if appearance.favicon.exists?
|
|
|
|
appearance.favicon_path
|
2019-11-07 07:06:21 -05:00
|
|
|
elsif Gitlab.canary?
|
2018-04-13 15:40:32 -04:00
|
|
|
'favicon-yellow.png'
|
|
|
|
elsif Rails.env.development?
|
2019-03-05 10:02:32 -05:00
|
|
|
development_favicon
|
2018-04-13 15:40:32 -04:00
|
|
|
else
|
|
|
|
'favicon.png'
|
|
|
|
end
|
|
|
|
|
2018-06-20 10:00:13 -04:00
|
|
|
ActionController::Base.helpers.image_path(image_name, host: host)
|
2017-09-26 11:04:37 -04:00
|
|
|
end
|
2019-03-05 10:02:32 -05:00
|
|
|
|
|
|
|
def development_favicon
|
|
|
|
# This is a separate method so that EE can return a different favicon
|
|
|
|
# for development environments.
|
|
|
|
'favicon-blue.png'
|
|
|
|
end
|
2017-09-26 11:04:37 -04:00
|
|
|
|
2017-12-06 15:04:53 -05:00
|
|
|
def status_overlay(status_name)
|
|
|
|
path = File.join(
|
|
|
|
'ci_favicons',
|
|
|
|
"#{status_name}.png"
|
|
|
|
)
|
|
|
|
|
2018-06-20 10:00:13 -04:00
|
|
|
ActionController::Base.helpers.image_path(path, host: host)
|
2017-12-06 15:04:53 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def available_status_names
|
|
|
|
@available_status_names ||= begin
|
2017-12-07 07:15:49 -05:00
|
|
|
Dir.glob(Rails.root.join('app', 'assets', 'images', 'ci_favicons', '*.png'))
|
2017-12-06 15:04:53 -05:00
|
|
|
.map { |file| File.basename(file, '.png') }
|
|
|
|
.sort
|
2017-09-27 07:18:49 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-09-26 11:04:37 -04:00
|
|
|
private
|
|
|
|
|
2018-06-20 10:00:13 -04:00
|
|
|
# we only want to create full urls when there's a different asset_host
|
|
|
|
# configured.
|
|
|
|
def host
|
2018-06-29 05:21:51 -04:00
|
|
|
asset_host = ActionController::Base.asset_host
|
|
|
|
if asset_host.nil? || asset_host == Gitlab.config.gitlab.base_url
|
2018-06-20 10:00:13 -04:00
|
|
|
nil
|
|
|
|
else
|
|
|
|
Gitlab.config.gitlab.base_url
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-09-26 11:04:37 -04:00
|
|
|
def appearance
|
2018-09-20 18:40:15 -04:00
|
|
|
Gitlab::SafeRequestStore[:appearance] ||= (Appearance.current || Appearance.new)
|
2017-09-26 11:04:37 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2019-09-13 09:26:31 -04:00
|
|
|
|
2021-05-11 17:10:21 -04:00
|
|
|
Gitlab::Favicon.prepend_mod_with('Gitlab::Favicon')
|