Class: JsDuck::BaseType

Inherits:
Object
  • Object
show all
Defined in:
lib/jsduck/base_type.rb

Overview

Detects the type of documentation object: class, method, cfg, etc

Class Method Summary collapse

Class Method Details

.detect(doc_map, code) ⇒ Object

Given parsed documentation and code, returns the tagname for documentation item.

Parameters:

  • doc_map

    Result from DocParser turned into hash of tags.

  • code

    Result from Ast#detect or CssParser#parse



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/jsduck/base_type.rb', line 14

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

.detect_member(doc_map) ⇒ Object

Detects any of the members defined using a Tag class. Returns the detected member type on success. Otherwise nil.



40
41
42
43
44
45
46
47
48
49
50
# File 'lib/jsduck/base_type.rb', line 40

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