gitlab-org--gitlab-foss/lib/gitlab/favicon.rb

59 lines
1.4 KiB
Ruby
Raw Normal View History

2017-09-26 11:04:37 -04:00
module Gitlab
class Favicon
class << self
def main
2018-04-13 15:40:32 -04:00
image_name =
if appearance_favicon.exists?
appearance_favicon.url
elsif Gitlab::Utils.to_boolean(ENV['CANARY'])
2018-04-13 15:40:32 -04:00
'favicon-yellow.png'
elsif Rails.env.development?
'favicon-blue.png'
else
'favicon.png'
end
ActionController::Base.helpers.image_path(image_name, host: host)
2017-09-26 11:04:37 -04:00
end
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
2017-09-26 11:04:37 -04:00
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
2017-09-26 11:04:37 -04:00
def appearance
2017-09-28 04:45:50 -04:00
RequestStore.store[:appearance] ||= (Appearance.current || Appearance.new)
2017-09-26 11:04:37 -04:00
end
def appearance_favicon
appearance.favicon
2017-09-26 11:04:37 -04:00
end
end
end
end