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

Move @enum detection fully to Enum Tag class.

The Tag#parse method can now return also an array of hashes instead
of just one.  And the @enum uses this to generate both :class and :enum.
parent 0ef7c8f6
Loading
Loading
Loading
Loading
+0 −13
Original line number Diff line number Diff line
@@ -42,7 +42,6 @@ module JsDuck
        :tagname => :class,
        :name => detect_name(:class, doc_map),
        :doc => detect_doc(docs),
        :enum => detect_enum(doc_map),
      }, doc_map)
    end

@@ -173,18 +172,6 @@ module JsDuck
      }
    end

    def detect_enum(doc_map)
      return nil unless extract(doc_map, :class, :enum)

      default = extract(doc_map, :class, :default)

      return {
        :type => extract(doc_map, :class, :type),
        :default => default,
        :doc_only => !!default,
      }
    end

    # Combines :doc-s of most tags
    # Ignores tags that have doc comment themselves and subproperty tags
    def detect_doc(docs)
+6 −2
Original line number Diff line number Diff line
@@ -84,8 +84,12 @@ module JsDuck
      elsif tag = TagRegistry.get_by_pattern(name)
        match(/\w+/)

        t = tag.parse(self)
        add_tag(t) if t.is_a?(Hash)
        tags = tag.parse(self)
        if tags.is_a?(Hash)
          add_tag(tags)
        elsif tags.is_a?(Array)
          tags.each {|t| add_tag(t) }
        end

        skip_white
      else
+16 −4
Original line number Diff line number Diff line
@@ -4,14 +4,26 @@ module JsDuck::Tag
  class Enum < Tag
    def initialize
      @pattern = "enum"
      @key = :enum
    end

    # @enum {Type} [name=default] ...
    def parse(p)
      # @enum is a special case of class
      tag = p.standard_tag({:tagname => :class, :type => true, :name => true})
      tag[:enum] = true
      tag
      enum = p.standard_tag({:tagname => :enum, :type => true, :name => true})

      # @enum is a special case of class, so we also generate a class
      # tag with the same name as given for @enum.
      cls = {:tagname => :class, :name => enum[:name]}

      return [cls, enum]
    end

    def process_doc(tags)
      return {
        :type => tags[0][:type],
        :default => tags[0][:default],
        :doc_only => !!tags[0][:default],
      }
    end

  end