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

55 lines
1.4 KiB
Ruby
Raw Normal View History

2017-09-26 15:04:37 +00:00
module Gitlab
class Favicon
class << self
def main
return custom_favicon_url(appearance_favicon.favicon_main.url) if appearance_favicon.exists?
2017-09-26 15:04:37 +00:00
return 'favicon-yellow.ico' if Gitlab::Utils.to_boolean(ENV['CANARY'])
return 'favicon-blue.ico' if Rails.env.development?
'favicon.ico'
end
def status_overlay(status_name)
path = File.join(
'ci_favicons',
'overlays',
"#{status_name}.png"
)
ActionController::Base.helpers.image_path(path)
end
def available_status_overlays
available_status_names.map do |status_name|
status_overlay(status_name)
end
end
def available_status_names
@available_status_names ||= begin
Dir.glob(Rails.root.join('app', 'assets', 'images', 'ci_favicons', 'overlays', "*.png"))
.map { |file| File.basename(file, '.png') }
.sort
end
end
2017-09-26 15:04:37 +00:00
private
def appearance
2017-09-28 08:45:50 +00:00
RequestStore.store[:appearance] ||= (Appearance.current || Appearance.new)
2017-09-26 15:04:37 +00:00
end
def appearance_favicon
appearance.favicon
2017-09-26 15:04:37 +00:00
end
# Without the '?' at the end of the favicon url the custom favicon (i.e.
# the favicons that are served through `UploadController`) are not shown
# in the browser.
def custom_favicon_url(url)
"#{url}?"
end
2017-09-26 15:04:37 +00:00
end
end
end