Module: YARD::Markdown::TagFormattingHelper
- Defined in:
- lib/yard/markdown/tag_formatting_helper.rb
Overview
Formats YARD tags into Markdown list items and fenced examples.
Class Method Summary collapse
-
.format_tag(tag) ⇒ String
Formats a non-example YARD tag as a Markdown list item body.
-
.render_tags(object) ⇒ String
Renders all tags for an object as Markdown.
Class Method Details
.format_tag(tag) ⇒ String
Formats a non-example YARD tag as a Markdown list item body.
26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/yard/markdown/tag_formatting_helper.rb', line 26 def self.format_tag(tag) name = tag.name.to_s text = tag.text.to_s types = Array(tag.types).map { |type| type.to_s.strip }.reject(&:empty?) [ "**@#{tag.tag_name}**", ("`#{name}`" unless name.lstrip.empty?), ("[#{types.join(", ")}]" unless types.empty?), (text.strip unless text.lstrip.empty?) ].compact.join(" ") end |
.render_tags(object) ⇒ String
Renders all tags for an object as Markdown.
11 12 13 14 15 16 17 18 19 20 |
# File 'lib/yard/markdown/tag_formatting_helper.rb', line 11 def self.(object) , = object..partition { |tag| tag.tag_name == "example" } regular = .map { |tag| "- #{format_tag(tag)}" }.join("\n") examples = .map do |tag| name = tag.name.to_s.rstrip title = name.empty? ? "**@example**" : "**@example #{name}**" [title, "```ruby", tag.text.to_s.rstrip, "```"].join("\n") end [regular, examples].reject(&:empty?).join("\n\n") end |