Commit 4b6419a8 authored by Rene Saarsoo's avatar Rene Saarsoo
Browse files

Move merging of :type field to Cfg/Property/CssVar classes.

A bit of a duplicated code in Cfg and Property, but we get rid of
the explicit check for :cfg/:property/:css_var in Type class.
parent 8ab1385f
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@ 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
      # :name, :static and :tagname fields.
@@ -48,6 +49,11 @@ module JsDuck
      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)
    end

    # Applies default merge algorithm to the rest of the data.
    def general_merge(h, docs, code)
      # Add all items in docs not already in result.
+7 −0
Original line number Diff line number Diff line
@@ -61,6 +61,13 @@ module JsDuck::Tag
      h
    end

    # Do the merging of :type field
    def merge(h, docs, code)
      if h[:type] == nil
        h[:type] = code[:tagname] == :method ? "Function" : "Object"
      end
    end

    def to_html(cfg, cls)
      JsDuck::Render::PropertySignature.render(cfg)
    end
+5 −0
Original line number Diff line number Diff line
@@ -39,6 +39,11 @@ module JsDuck::Tag
      h
    end

    # Set default value for :type field
    def merge(h, docs, code)
      h[:type] = "Object" unless h[:type]
    end

    def to_html(var, cls)
      JsDuck::Render::PropertySignature.render(var)
    end
+7 −0
Original line number Diff line number Diff line
@@ -53,6 +53,13 @@ module JsDuck::Tag
      h
    end

    # Do the merging of :type field
    def merge(h, docs, code)
      if h[:type] == nil
        h[:type] = code[:tagname] == :method ? "Function" : "Object"
      end
    end

    def to_html(property, cls)
      JsDuck::Render::PropertySignature.render(property)
    end
+0 −8
Original line number Diff line number Diff line
@@ -5,7 +5,6 @@ module JsDuck::Tag
    def initialize
      @pattern = "type"
      @tagname = :type
      @merge_context = :member

      # We don't really care about the position as we don't output any
      # HTML. We just need to set this up to do the formatting.
@@ -31,13 +30,6 @@ module JsDuck::Tag
      h[:type] = tags[0][:type] unless h[:type]
    end

    # Do the merging of :type field
    def merge(h, docs, code)
      if h[:type] == nil && ([:property, :cfg, :css_var].include?(h[:tagname]))
        h[:type] = code[:tagname] == :method ? "Function" : "Object"
      end
    end

    def format(m, formatter)
      m[:html_type] = formatter.format_type(m[:type])
    end