Commit 2285d897 authored by Rene Saarsoo's avatar Rene Saarsoo
Browse files

Move class-comment grouping to separate class.

parent 153ecd4e
Loading
Loading
Loading
Loading
+52 −0
Original line number Diff line number Diff line
module JsDuck

  # Handles old syntax where configs and constructor are part of class
  # doc-comment.
  class ClassDocGrouper

    # Gathers all tags until first @cfg or @constructor into the first
    # bare :class group.  We have a special case for @xtype which in
    # ExtJS comments often appears after @constructor - so we
    # explicitly place it into :class group.
    #
    # Then gathers each @cfg and tags following it into :cfg group, so
    # that it becomes array of arrays of tags.  This is to allow some
    # configs to be marked with @private or whatever else.
    #
    # Finally gathers tags after @constructor into its group.
    def self.group(docs)
      groups = {
        :class => [],
        :cfg => [],
        :constructor => [],
      }

      # By default everything goes to :class group
      group_name = :class

      docs.each do |tag|
        tagname = tag[:tagname]

        if tagname == :cfg || tagname == :constructor
          group_name = tagname
          if tagname == :cfg
            groups[:cfg] << []
          end
        end

        if tagname == :alias
          # For backwards compatibility allow @xtype after @constructor
          groups[:class] << tag
        elsif group_name == :cfg
          groups[:cfg].last << tag
        else
          groups[group_name] << tag
        end
      end

      groups
    end

  end

end
+2 −33
Original line number Diff line number Diff line
require 'jsduck/logger'
require 'jsduck/meta_tag_registry'
require 'jsduck/doc_type'
require 'jsduck/class_doc_grouper'

module JsDuck

@@ -41,7 +42,7 @@ module JsDuck
    end

    def create_class(docs, code)
      groups = group_class_docs(docs)
      groups = ClassDocGrouper.group(docs)
      result = create_bare_class(groups[:class], code)
      result[:members] = create_class_members(groups, result[:name])
      result[:statics] = Class.default_members_hash
@@ -53,38 +54,6 @@ module JsDuck
      result
    end

    # Gathers all tags until first @cfg or @constructor into the first
    # bare :class group.  We have a special case for @xtype which in
    # ExtJS comments often appears after @constructor - so we
    # explicitly place it into :class group.
    #
    # Then gathers each @cfg and tags following it into :cfg group, so
    # that it becomes array of arrays of tags.  This is to allow some
    # configs to be marked with @private or whatever else.
    #
    # Finally gathers tags after @constructor into its group.
    def group_class_docs(docs)
      groups = {:class => [], :cfg => [], :constructor => []}
      group_name = :class
      docs.each do |tag|
        if tag[:tagname] == :cfg || tag[:tagname] == :constructor
          group_name = tag[:tagname]
          if tag[:tagname] == :cfg
            groups[:cfg] << []
          end
        end

        if tag[:tagname] == :alias
          groups[:class] << tag
        elsif group_name == :cfg
          groups[:cfg].last << tag
        else
          groups[group_name] << tag
        end
      end
      groups
    end

    def create_bare_class(docs, code)
      doc_map = build_doc_map(docs)
      return add_shared({