Commit 63927567 authored by Rene Saarsoo's avatar Rene Saarsoo
Browse files

Add priority field to class icons.

To determine which icon to used when multiple possibilities.

For now primarily using this to choose the Singleton icon over
Component.
parent 11fcb1f9
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -9,6 +9,7 @@ module JsDuck::Tag
        :small => File.dirname(__FILE__) + "/icons/class.png",
        :large => File.dirname(__FILE__) + "/icons/class-large.png",
        :redirect => File.dirname(__FILE__) + "/icons/class-redirect.png",
        :priority => PRIORITY_CLASS,
      }
    end

+1 −0
Original line number Diff line number Diff line
@@ -11,6 +11,7 @@ module JsDuck::Tag
        :small => File.dirname(__FILE__) + "/icons/component.png",
        :large => File.dirname(__FILE__) + "/icons/component-large.png",
        :redirect => File.dirname(__FILE__) + "/icons/component-redirect.png",
        :priority => PRIORITY_COMPONENT,
      }
      super
    end
+1 −0
Original line number Diff line number Diff line
@@ -9,6 +9,7 @@ module JsDuck::Tag
        :small => File.dirname(__FILE__) + "/icons/singleton.png",
        :large => File.dirname(__FILE__) + "/icons/singleton-large.png",
        :redirect => File.dirname(__FILE__) + "/icons/singleton-redirect.png",
        :priority => PRIORITY_SINGLETON,
      }
      @signature = {:long => "singleton", :short => "single"}
      @css = <<-EOCSS
+12 −2
Original line number Diff line number Diff line
@@ -135,13 +135,23 @@ module JsDuck::Tag

    # Defines custom class icon files.
    #
    # It must be a hash with keys :small, :large, :redirect -
    # each referencing an icon file.
    # It must be a hash with the following keys:
    #
    # - :large - the large icon used in class header
    # - :small - small icon used in class tree and search
    # - :redirect - redirect icon for alternateClassNames in search.
    # - :priority - a number to determine which icon gets used when
    #      a class has several tags that set a custom icon.  An icon
    #      with a larger priority wins.
    #
    # Used by @class tag to define the default icon.
    # Used by @singleton and @component tags for a different icon.
    attr_reader :class_icon

    PRIORITY_SINGLETON = 2
    PRIORITY_COMPONENT = 1
    PRIORITY_CLASS = 0

    # Returns all descendants of JsDuck::Tag::Tag class.
    def self.descendants
      result = []
+3 −1
Original line number Diff line number Diff line
@@ -57,7 +57,9 @@ module JsDuck
      end

      def self.class_icon_providers
        TagRegistry.class_icon_providers
        @providers ||= TagRegistry.class_icon_providers.sort do |a, b|
          a.class_icon[:priority] <=> b.class_icon[:priority]
        end.reverse
      end
    end