Sha256: cb87cc5db2f27ae859e2e117ac43268ae92ce32240946a500a77cc32bf708b3e

Contents?: true

Size: 1.44 KB

Versions: 14

Compression:

Stored size: 1.44 KB

Contents

require 'jsduck/tag_registry'

module JsDuck

  # Detects the type of documentation object: class, method, cfg, etc
  class BaseType
    # Given parsed documentation and code, returns the tagname for
    # documentation item.
    #
    # @param doc_map Result from DocParser turned into hash of tags.
    # @param code Result from Ast#detect or CssParser#parse
    # @returns :class or any of the member type symbols (:method, :event, ...).
    #
    def self.detect(doc_map, code)
      if doc_map[:class] || doc_map[:override]
        :class
      elsif type = detect_member(doc_map)
        type
      elsif doc_map[:type]
        # @type also results in property
        :property
      elsif code[:tagname] == :class
        :class
      elsif code[:tagname] == :css_mixin
        :css_mixin
      elsif doc_map[:cfg]
        :cfg
      elsif doc_map[:constructor]
        :method
      elsif doc_map[:params] || doc_map[:return]
        :method
      else
        code[:tagname]
      end
    end

    # Detects any of the members defined using a Tag class.
    # Returns the detected member type on success.
    # Otherwise nil.
    def self.detect_member(doc_map)
      type = TagRegistry.member_type_names.find {|type| doc_map[type] }

      if type == :cfg
        # Only detect a single @cfg as a :cfg.
        # Multiple ones can be part of a class.
        return (doc_map[:cfg].length == 1) ? :cfg : nil
      else
        type
      end
    end
  end

end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
jsduck-5.3.4 lib/jsduck/base_type.rb
jsduck-5.3.3 lib/jsduck/base_type.rb
jsduck-5.3.2 lib/jsduck/base_type.rb
jsduck-5.3.1 lib/jsduck/base_type.rb
jsduck-5.3.0 lib/jsduck/base_type.rb
jsduck-5.2.0 lib/jsduck/base_type.rb
jsduck-5.1.0 lib/jsduck/base_type.rb
jsduck-5.0.1 lib/jsduck/base_type.rb
jsduck-5.0.0 lib/jsduck/base_type.rb
jsduck-5.0.0.beta5 lib/jsduck/base_type.rb
jsduck-5.0.0.beta4 lib/jsduck/base_type.rb
jsduck-5.0.0.beta3 lib/jsduck/base_type.rb
jsduck-5.0.0.beta2 lib/jsduck/base_type.rb
jsduck-5.0.0.beta01 lib/jsduck/base_type.rb