class JsDuck::Tag::MemberTag

Base class for all builtin members.

Constants

MEMBER_POS_CFG
MEMBER_POS_CSS_MIXIN
MEMBER_POS_CSS_VAR
MEMBER_POS_EVENT
MEMBER_POS_LISTENER
MEMBER_POS_METHOD
MEMBER_POS_PROPERTY

Attributes

member_type[R]

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.

Public Instance Methods

member_params(params) click to toggle source

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

# File lib/jsduck/tag/member_tag.rb, line 122
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) click to toggle source

Merges documentation and code hashes into the result hash.

# File lib/jsduck/tag/member_tag.rb, line 99
def merge(hash, docs, code)
end
process_code(code) click to toggle source

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
# File lib/jsduck/tag/member_tag.rb, line 82
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) click to toggle source

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.

# File lib/jsduck/tag/member_tag.rb, line 110
def to_html(context, cls)
end