Module: YARD::Markdown::ArefHelper

Includes:
AnchorComponentHelper
Included in:
HeadingHelper
Defined in:
lib/yard/markdown/aref_helper.rb

Overview

Computes anchor ids that match the generated Markdown headings.

Instance Method Summary collapse

Methods included from AnchorComponentHelper

#anchor_component

Instance Method Details

#aref(object) ⇒ String

Returns the primary anchor id for a documented object.

Parameters:

  • object (YARD::CodeObjects::Base)

    Object being rendered.

Returns:

  • (String)

    Anchor id for the object’s heading.



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/yard/markdown/aref_helper.rb', line 13

def aref(object)
  type = object.type

  return "class-#{object.path.gsub('::', '-')}" if type == :class
  return "module-#{object.path.gsub('::', '-')}" if type == :module
  return "constant-#{object.name}" if type == :constant
  return "classvariable-#{anchor_component(object.name)}" if type == :classvariable

  scope = object.scope == :class ? 'c' : 'i'

  if !object.attr_info.nil?
    "attribute-#{scope}-#{object.name}"
  else
    "method-#{scope}-#{anchor_component(object.name)}"
  end
end