Module: YARD::Markdown::MetadataSectionHelper
- Defined in:
- lib/yard/markdown/metadata_section_helper.rb
Overview
Renders namespace metadata summaries.
Class Method Summary collapse
-
.file_rows(object) ⇒ Array<Array>
Builds the source-file metadata rows.
-
.metadata_table_cell(value) ⇒ String
Escapes text for a Markdown table cell.
Instance Method Summary collapse
-
#metadata_reference(target) ⇒ String
Returns a table-safe namespace reference, linked when YARD will render it.
-
#object_metadata(object) ⇒ String
Returns inheritance, mixins, and source files for an object.
Class Method Details
.file_rows(object) ⇒ Array<Array>
Builds the source-file metadata 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.
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.
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.
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 |