Class: JsDuck::Tag::MemberTag

Inherits:
Tag
  • Object
show all
Defined in:
lib/jsduck/tag/member_tag.rb

Overview

Base class for all builtin members.

Direct Known Subclasses

Cfg, CssMixin, CssVar, Event, Method, Property

Constant Summary collapse

MEMBER_POS_CFG =
1
MEMBER_POS_PROPERTY =
2
MEMBER_POS_METHOD =
3
MEMBER_POS_EVENT =
4
MEMBER_POS_CSS_VAR =
5
MEMBER_POS_CSS_MIXIN =
6

Constants inherited from Tag

Tag::POS_ASIDE, Tag::POS_DEFAULT, Tag::POS_DEPRECATED, Tag::POS_DOC, Tag::POS_ENUM, Tag::POS_FIRES, Tag::POS_LOCALDOC, Tag::POS_OVERRIDES, Tag::POS_PARAM, Tag::POS_PREVENTABLE, Tag::POS_PRIVATE, Tag::POS_RETURN, Tag::POS_SINCE, Tag::POS_SUBPROPERTIES, Tag::POS_TEMPLATE, Tag::POS_THROWS

Instance Attribute Summary collapse

Attributes inherited from Tag

#css, #ext_define_default, #ext_define_pattern, #html_position, #pattern, #repeatable, #signature, #tagname

Instance Method Summary collapse

Methods inherited from Tag

descendants, #format, #parse_doc, #parse_ext_define, #process_doc

Instance Attribute Details

#member_typeObject (readonly)

Defines a class member type and specifies various settings. For example:

{
  :title => "Events",
  :position => MEMBER_POS_EVENT,
  # The following are optional
  :toolbar_title => "Events",
  :icon => File.dirname(__FILE__) + "/icons/event.png",
  :subsections => [
    {:title => "Static events",
     :filter => {:static => false},
     :default => true},
    {:title => "Instance events",
     :filter => {:static => true}},
  ]
}

Position defines the ordering of member section in final HTML output.

Title is shown at the top of each such section and also as a label on Docs app toolbar button unless :toolbar_title is specified.

Icon defines a file to be used as member icon in various places of the docs app.

Subsections allows splitting the list of members to several subgroups. For example methods get split into static and instance methods.

  • The :filter field defines how to filter out the members for this subcategory. :static=>true filters out all members that have a :static field with a truthy value. Conversely, :static=>false filters out members not having a :static field or having it with a falsy value.

  • Setting :default=>true will hide the subsection title when all the members end up in that subsection. For example when there are only instance methods, the docs will only contain the section title “Methods”, as by default one should assume all methods are instance methods if not stated otherwise.



51
52
53
# File 'lib/jsduck/tag/member_tag.rb', line 51

def member_type
  @member_type
end

Instance Method Details

Creates HTML link to the given member. A helper method for use in #to_html.



114
115
116
# File 'lib/jsduck/tag/member_tag.rb', line 114

def member_link(member)
  JsDuck::Render::SignatureUtil::link(member[:owner], member[:id], member[:name])
end

#member_params(params) ⇒ Object

Creates HTML listing of parameters. When called with nil, creates empty params list. A helper method for use in #to_html.



121
122
123
124
125
126
127
# File 'lib/jsduck/tag/member_tag.rb', line 121

def member_params(params)
  ps = Array(params).map do |p|
    p[:optional] ? "[#{p[:name]}]" : p[:name]
  end.join(", ")

  "( <span class='pre'>#{ps}</span> )"
end

#merge(hash, docs, code) ⇒ Object

Merges documentation and code hashes into the result hash.



98
99
# File 'lib/jsduck/tag/member_tag.rb', line 98

def merge(hash, docs, code)
end

#process_code(code) ⇒ Object

Extracts the fields auto-detected from code that are relevant to the member type and returns a hash with them.

The implementation here extracts fields applicable to all member types. When additional member-specific fields are to be extracted, override this method, but be sure to call the superclass method too.

For example inside Method tag we might additionally want to extract :type and :default:

def process_code(code)
  h = super(code)
  h[:type] = code[:type]
  h[:default] = code[:default]
  h
end


81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/jsduck/tag/member_tag.rb', line 81

def process_code(code)
  return {
    :tagname => code[:tagname],
    # An auto-detected name might be "MyClass.prototype.myMethod" -
    # for member name we only want the last "myMethod" part.
    :name => code[:name] ? code[:name].split(/\./).last : nil,

    :autodetected => code[:autodetected],
    :inheritdoc => code[:inheritdoc],
    :static => code[:static],
    :private => code[:private],
    :inheritable => code[:inheritable],
    :linenr => code[:linenr],
  }
end

#to_html(context, cls) ⇒ Object

This method defines the signature-line of the member. For example it might return something like this:

"apply(source, target) : Object"

Use #member_link method to render the member name as link in a standard way. Similarly there’s helper method #member_params for rendering the parameter list.



109
110
# File 'lib/jsduck/tag/member_tag.rb', line 109

def to_html(context, cls)
end