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