Module: YARD::Markdown::MetadataSectionHelper

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

Overview

Renders namespace metadata summaries.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.file_rows(object) ⇒ Array<Array>

Builds the source-file metadata rows.

Parameters:

  • object (YARD::CodeObjects::NamespaceObject)

    Namespace being rendered.

Returns:

  • (Array<Array>)

    Source-file rows.



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

def self.file_rows(object)
  files = object.files.map(&:first).uniq
  return [] if files.empty?

  [["Defined in", files.map { |file| (file) }.join(", ")]]
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.



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

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

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.



25
26
27
28
29
30
31
# File 'lib/yard/markdown/metadata_section_helper.rb', line 25

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

  "[#{label}](#{path})"
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
# File 'lib/yard/markdown/metadata_section_helper.rb', line 11

def (object)
  superclass = object.superclass if object.instance_of?(CodeObjects::ClassObject)
  rows = (superclass ? [["Inherits", (superclass)]] : []) +
    mixin_rows(object) + MetadataSectionHelper.file_rows(object)

  return "" if rows.empty?

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