Module: YARD::Markdown::MetadataSectionHelper

Defined in:
lib/yard/markdown/metadata_section_helper.rb

Overview

Renders namespace metadata summaries.

Instance Method Summary collapse

Instance Method Details

#metadata_reference(target) ⇒ String

Returns a table-safe namespace reference, linked when YARD will render it.

Parameters:

  • target (YARD::CodeObjects::NamespaceObject, YARD::CodeObjects::Proxy)

    Referenced namespace.

Returns:

  • (String)

    Markdown link or plain table-cell text.



37
38
39
40
41
42
# File 'lib/yard/markdown/metadata_section_helper.rb', line 37

def (target)
  label = (target.path)
  return label unless target.is_a?(CodeObjects::Base) && run_verifier([target]).any?

  "[#{label}](#{target.path})"
end

#metadata_table_cell(value) ⇒ String

Escapes text for a Markdown table cell.

Parameters:

  • value (String)

    Metadata text.

Returns:

  • (String)

    GFM table-safe Markdown text.



48
49
50
51
# File 'lib/yard/markdown/metadata_section_helper.rb', line 48

def (value)
  value.gsub(/[[:blank:]]*\R[[:blank:]]*/, " ")
    .gsub(/[\\|]/) { |character| "\\#{character}" }
end

#object_metadata(object) ⇒ String

Returns inheritance, mixins, and source files for an object.

Parameters:

  • object (YARD::CodeObjects::NamespaceObject)

    Object being rendered.

Returns:

  • (String)

    Markdown table containing the object's metadata.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/yard/markdown/metadata_section_helper.rb', line 11

def (object)
  rows = []

  if object.instance_of?(CodeObjects::ClassObject)
    rows << ["Inherits", (object.superclass)]
  end

  [[:class, "Extended by"], [:instance, "Includes"]].each do |scope, label|
    mixins = run_verifier(object.mixins(scope)).sort_by { |item| item.path }
    next if mixins.empty?

    rows << [label, mixins.map { |mixin| (mixin) }.join(", ")]
  end

  files = object.files.map(&:first).uniq
  rows << ["Defined in", files.map { |file| (file) }.join(", ")] unless files.empty?

  return "" if rows.empty?

  (["|  |  |", "| --- | --- |"] + rows.map { |label, value| "| **#{label}** | #{value} |" }).join("\n")
end