debian-mirror-gitlab/lib/gitlab/favicon.rb

63 lines
1.6 KiB
Ruby
Raw Normal View History

2018-12-13 13:39:08 +05:30
# frozen_string_literal: true
2018-11-08 19:23:39 +05:30
module Gitlab
class Favicon
class << self
def main
image_name =
2019-09-30 21:07:59 +05:30
if appearance.favicon.exists?
appearance.favicon_path
2018-11-08 19:23:39 +05:30
elsif Gitlab::Utils.to_boolean(ENV['CANARY'])
'favicon-yellow.png'
elsif Rails.env.development?
2019-07-07 11:18:12 +05:30
development_favicon
2018-11-08 19:23:39 +05:30
else
'favicon.png'
end
ActionController::Base.helpers.image_path(image_name, host: host)
end
2019-07-07 11:18:12 +05:30
def development_favicon
# This is a separate method so that EE can return a different favicon
# for development environments.
'favicon-blue.png'
end
2018-11-08 19:23:39 +05:30
def status_overlay(status_name)
path = File.join(
'ci_favicons',
"#{status_name}.png"
)
ActionController::Base.helpers.image_path(path, host: host)
end
def available_status_names
@available_status_names ||= begin
Dir.glob(Rails.root.join('app', 'assets', 'images', 'ci_favicons', '*.png'))
.map { |file| File.basename(file, '.png') }
.sort
end
end
private
# we only want to create full urls when there's a different asset_host
# configured.
def host
asset_host = ActionController::Base.asset_host
if asset_host.nil? || asset_host == Gitlab.config.gitlab.base_url
nil
else
Gitlab.config.gitlab.base_url
end
end
def appearance
2018-12-05 23:21:45 +05:30
Gitlab::SafeRequestStore[:appearance] ||= (Appearance.current || Appearance.new)
2018-11-08 19:23:39 +05:30
end
end
end
end