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

Move additional :doc processing to Tag classes.

@cfg, @property and @constructor can be followed by docs that are
part of the top-level documentation.  Instead of having the logic
for that hard-coded to Doc::Processor class, the latter only extracts
the general :doc, and the Tag classes themselves append top-level docs
to this when needed.
parent 78196d59
Loading
Loading
Loading
Loading
+4 −19
Original line number Diff line number Diff line
@@ -25,7 +25,7 @@ module JsDuck
      def process(tagname, doc_map)
        hash = {
          :tagname => tagname,
          :doc => detect_doc(tagname, doc_map),
          :doc => extract_doc(doc_map),
        }

        position = {:filename => @filename, :linenr => @linenr}
@@ -41,24 +41,9 @@ module JsDuck

      private

      # Returns documentation for class or member.
      def detect_doc(tagname, doc_map)
        doc = extract(doc_map, :doc, :doc) || ""
        if tagname == :cfg || tagname == :property
          doc += extract(doc_map, tagname, :doc) || ""
        elsif tagname == :method && doc_map[:constructor]
          doc += extract(doc_map, :constructor, :doc)
        end
        doc
      end

      def extract(doc_map, tagname, propname = nil)
        tag = doc_map[tagname] ? doc_map[tagname].first : nil
        if tag && propname
          tag[propname]
        else
          tag
        end
      def extract_doc(doc_map)
        tag = doc_map[:doc] ? doc_map[:doc].first : {}
        return tag[:doc] || ""
      end

    end
+2 −0
Original line number Diff line number Diff line
@@ -28,6 +28,8 @@ module JsDuck::Tag
      h[:default] = p[:default]
      h[:properties] = JsDuck::Doc::Subproperties.nest(tags, pos)[0][:properties]
      h[:required] = true if p[:optional] == false
      # Documentation after the first @cfg is part of the top-level docs.
      h[:doc] += p[:doc]
    end
  end
end
+3 −0
Original line number Diff line number Diff line
@@ -16,6 +16,9 @@ module JsDuck::Tag
    # @method tag already supplied the name.
    def process_doc(h, tags, pos)
      h[:name] = "constructor" unless h[:name]
      # Documentation after @constructor is part of the constructor
      # method top-level docs.
      h[:doc] += tags[0][:doc]
    end
  end
end
+2 −0
Original line number Diff line number Diff line
@@ -23,6 +23,8 @@ module JsDuck::Tag
      h[:type] = p[:type] if p[:type]
      h[:default] = p[:default]
      h[:properties] = JsDuck::Doc::Subproperties.nest(tags, pos)[0][:properties]
      # Documentation after the first @property is part of the top-level docs.
      h[:doc] += p[:doc]
    end
  end
end