Commit 2c9e9389 authored by Rene Saarsoo's avatar Rene Saarsoo
Browse files

Move all class-level merging to Tag::Class.

With this we completely get rid of the @merge_context variable,
and all the merging happens in Tag::Class or MemberTag subclasses.
parent 1ac77680
Loading
Loading
Loading
Loading
+0 −9
Original line number Diff line number Diff line
@@ -24,7 +24,6 @@ module JsDuck
      }

      general_merge(h, docs, code)
      invoke_merge_in_tags(h, docs, code)
      invoke_merge_in_member_tag(h, docs, code)

      # Needs to be calculated last, as it relies on the existance of
@@ -41,14 +40,6 @@ module JsDuck
      TagRegistry.get_by_name(tagname).process_code(code)
    end

    # Invokes the #merge methods of tags registered for the given
    # merge context.
    def invoke_merge_in_tags(h, docs, code)
      TagRegistry.mergers(h[:tagname]).each do |tag|
        tag.merge(h, docs, code)
      end
    end

    # Invokes the #merge method in corresponding member or :class tag.
    def invoke_merge_in_member_tag(h, docs, code)
      TagRegistry.get_by_name(h[:tagname]).merge(h, docs, code)
+0 −20
Original line number Diff line number Diff line
@@ -9,7 +9,6 @@ module JsDuck::Tag
      @repeatable = true
      @ext_define_pattern = "alias"
      @ext_define_default = {:aliases => []}
      @merge_context = :class
    end

    # For backwards compatibility decide whether the @alias was used
@@ -39,24 +38,5 @@ module JsDuck::Tag
      cls[:aliases] += JsDuck::Js::Utils.make_string_list(ast)
    end

    def merge(h, docs, code)
      h[:aliases] = build_aliases_hash(h[:aliases] || [])
    end

    # Given array of full alias names like "foo.bar", "foo.baz"
    # build hash like {"foo" => ["bar", "baz"]}
    def build_aliases_hash(aliases)
      hash={}
      aliases.each do |a|
        if a =~ /^([^.]+)\.(.+)$/
          if hash[$1]
            hash[$1] << $2
          else
            hash[$1] = [$2]
          end
        end
      end
      hash
    end
  end
end
+0 −5
Original line number Diff line number Diff line
@@ -8,11 +8,6 @@ module JsDuck::Tag
      @repeatable = true
      @ext_define_pattern = "alternateClassName"
      @ext_define_default = {:alternateClassNames => []}
      @merge_context = :class
    end

    def merge(h, docs, code)
      h[@tagname] = [] unless h[@tagname]
    end
  end
end
+32 −2
Original line number Diff line number Diff line
@@ -5,7 +5,6 @@ module JsDuck::Tag
    def initialize
      @pattern = "class"
      @tagname = :class
      @merge_context = :class
    end

    # @class name
@@ -33,9 +32,40 @@ module JsDuck::Tag
      end
    end

    # Ensure the empty members array.
    def merge(h, docs, code)
      # Ensure the empty members array.
      h[:members] = []
      # Ignore extending of the Object class
      h[:extends] = nil if h[:extends] == "Object"
      # Default alternateClassNames list to empty array
      h[:alternateClassNames] = [] unless h[:alternateClassNames]
      # Turn :aliases field into hash
      h[:aliases] = build_aliases_hash(h[:aliases] || [])

      # Takes the :enum always from docs, but the :doc_only can come
      # from either code or docs.
      if docs[:enum]
        h[:enum] = docs[:enum]
        h[:enum][:doc_only] = docs[:enum][:doc_only] || (code[:enum] && code[:enum][:doc_only])
      end
    end

    private

    # Given array of full alias names like "foo.bar", "foo.baz"
    # build hash like {"foo" => ["bar", "baz"]}
    def build_aliases_hash(aliases)
      hash={}
      aliases.each do |a|
        if a =~ /^([^.]+)\.(.+)$/
          if hash[$1]
            hash[$1] << $2
          else
            hash[$1] = [$2]
          end
        end
      end
      hash
    end
  end
end
+0 −1
Original line number Diff line number Diff line
@@ -5,7 +5,6 @@ module JsDuck::Tag
    def initialize
      @pattern = "enum"
      @tagname = :enum
      @merge_context = :class
      @html_position = POS_ENUM
      # Green box
      @css = <<-EOCSS
Loading