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

Refactor @deprecated into attributes hash.

All the attributes are now in this hash. That makes possible
further refactoring of the whole attributes listing creation
in method signatures.
parent 071cd258
Loading
Loading
Loading
Loading
+14 −6
Original line number Diff line number Diff line
@@ -57,8 +57,7 @@ module JsDuck
        :owner => cfg[:owner],
        :files => cfg[:files],
        :id => "method-" + name,
        :deprecated => cfg[:deprecated],
        :attributes => {},
        :attributes => clone_attributes(cfg),
        :meta => cfg[:meta],
      }
    end
@@ -81,8 +80,7 @@ module JsDuck
        :owner => cfg[:owner],
        :files => cfg[:files],
        :id => "method-" + name,
        :deprecated => cfg[:deprecated],
        :attributes => {},
        :attributes => clone_attributes(cfg),
        :meta => cfg[:meta]
      }
    end
@@ -119,8 +117,7 @@ module JsDuck
        :owner => cfg[:owner],
        :files => cfg[:files],
        :id => "event-" + name,
        :deprecated => cfg[:deprecated],
        :attributes => {},
        :attributes => clone_attributes(cfg),
        :meta => cfg[:meta]
      }
    end
@@ -128,6 +125,17 @@ module JsDuck
    def upcase_first(str)
      str[0,1].upcase + str[1..-1]
    end

    # Create copy of all attributes of config, except the :required
    # attribute which only applies to configs and must not be
    # propagated to methods or events.
    def clone_attributes(cfg)
      h = {}
      cfg[:attributes].each_pair do |key, value|
        h[:key] = value unless key == :required
      end
      h
    end
  end

end
+1 −1
Original line number Diff line number Diff line
@@ -45,7 +45,7 @@ module JsDuck

    def compact_member(m)
      m_copy = {}
      [:name, :tagname, :owner, :deprecated, :attributes, :id].each do |key|
      [:name, :tagname, :owner, :attributes, :id].each do |key|
        m_copy[key] = m[key]
      end
      m_copy
+3 −2
Original line number Diff line number Diff line
@@ -36,7 +36,8 @@ module JsDuck
    def format_member(m)
      @formatter.doc_context = m[:files][0]
      m[:doc] = @formatter.format(m[:doc]) if m[:doc]
      m[:deprecated][:text] = @formatter.format(m[:deprecated][:text]) if m[:deprecated]
      depr = m[:attributes][:deprecated]
      depr[:text] = @formatter.format(depr[:text]) if depr
      if expandable?(m) || @formatter.too_long?(m[:doc])
        m[:shortDoc] = @formatter.shorten(m[:doc])
      end
@@ -52,7 +53,7 @@ module JsDuck
    end

    def expandable?(m)
      m[:params] || (m[:properties] && m[:properties].length > 0) || m[:default] || m[:deprecated] || m[:attributes][:template]
      m[:params] || (m[:properties] && m[:properties].length > 0) || m[:default] || m[:attributes][:deprecated] || m[:attributes][:template]
    end

    def format_item(it, is_css_tag)
+3 −5
Original line number Diff line number Diff line
@@ -221,7 +221,6 @@ module JsDuck
      hash.merge!({
        :private => !!doc_map[:private],
        :inheritable => !!doc_map[:inheritable],
        :deprecated => detect_deprecated(doc_map),
        :inheritdoc => doc_map[:inheritdoc] ? doc_map[:inheritdoc].first : nil,
        :attributes => detect_attributes(doc_map),
        :meta => detect_meta(doc_map),
@@ -362,10 +361,6 @@ module JsDuck
      meta
    end

    def detect_deprecated(doc_map)
      doc_map[:deprecated] ? doc_map[:deprecated].first : nil
    end

    def detect_singleton(doc_map, code)
      !!(doc_map[:singleton] || code[:type] == :ext_define && code[:singleton])
    end
@@ -375,6 +370,9 @@ module JsDuck
      (doc_map[:attribute] || []).each do |tag|
        attributes[tag[:name]] = true
      end
      # @deprecated and (required) are detected in special ways from
      # doc-comment but merged into :attributes hash.
      attributes[:deprecated] = doc_map[:deprecated].first if doc_map[:deprecated]
      attributes[:required] = true if detect_required(doc_map)
      attributes
    end
+6 −5
Original line number Diff line number Diff line
@@ -227,7 +227,7 @@ module JsDuck
      if m[:attributes][:static]
        after += "<strong class='static signature'>static</strong>"
      end
      if m[:deprecated]
      if m[:attributes][:deprecated]
        after += "<strong class='deprecated signature'>deprecated</strong>"
      end
      if m[:attributes][:required]
@@ -265,17 +265,18 @@ module JsDuck
        doc << "<p>Defaults to: <code>" + CGI.escapeHTML(m[:default]) + "</code></p>"
      end

      if m[:deprecated]
        v = m[:deprecated][:version] ? "since " + m[:deprecated][:version] : ""
      if m[:attributes][:deprecated]
        depr = m[:attributes][:deprecated]
        v = depr[:version] ? "since " + depr[:version] : ""
        doc << [
          "<div class='signature-box deprecated'>",
          "<p>This #{m[:tagname]} has been <strong>deprecated</strong> #{v}</p>",
          m[:deprecated][:text],
          depr[:text],
          "</div>",
        ]
      end

      if m[:template]
      if m[:attributes][:template]
        doc << [
          "<div class='signature-box template'>",
          "<p>This is a template method. A hook into the functionality of this class.",
Loading