Welcome to mirror list, hosted at ThFree Co, Russian Federation.

favicon.rb « gitlab « lib - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: d0178d0fdf9a5d1a44b04bd0f42244553f1e480b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
module Gitlab
  class Favicon
    class << self
      def main
        return custom_favicon_url(appearance_favicon.favicon_main.url) if appearance_favicon.exists?
        return ActionController::Base.helpers.image_path('favicon-yellow.png') if Gitlab::Utils.to_boolean(ENV['CANARY'])
        return ActionController::Base.helpers.image_path('favicon-blue.png') if Rails.env.development?

        ActionController::Base.helpers.image_path('favicon.png')
      end

      def status_overlay(status_name)
        path = File.join(
          'ci_favicons',
          "#{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', '*.png'))
            .map { |file| File.basename(file, '.png') }
            .sort
        end
      end

      private

      def appearance
        RequestStore.store[:appearance] ||= (Appearance.current || Appearance.new)
      end

      def appearance_favicon
        appearance.favicon
      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
    end
  end
end