Module: YARD::Markdown::TagFormattingHelper
- Defined in:
- lib/yard/markdown/tag_formatting_helper.rb
Overview
Formats YARD tags into Markdown list items and fenced examples.
Instance Method Summary collapse
-
#format_tag(tag) ⇒ String
Formats a non-example YARD tag as a Markdown list item body.
-
#normalized_tag_types(types) ⇒ Array<String>
Normalizes tag type declarations into printable strings.
-
#render_tags(object) ⇒ String
Renders all tags for an object as Markdown.
Instance Method Details
#format_tag(tag) ⇒ String
Formats a non-example YARD tag as a Markdown list item body.
31 32 33 34 35 36 37 38 39 40 |
# File 'lib/yard/markdown/tag_formatting_helper.rb', line 31 def format_tag(tag) parts = ["**@#{tag.tag_name}**"] parts << "`#{tag.name}`" unless tag.name.to_s.lstrip.empty? cleaned_types = normalized_tag_types(tag.types) parts << "[#{cleaned_types.join(", ")}]" unless cleaned_types.empty? parts << tag.text.strip unless tag.text.to_s.lstrip.empty? parts.join(" ") end |
#normalized_tag_types(types) ⇒ Array<String>
Normalizes tag type declarations into printable strings.
46 47 48 |
# File 'lib/yard/markdown/tag_formatting_helper.rb', line 46 def normalized_tag_types(types) Array(types).map(&:to_s).map(&:strip).reject(&:empty?) end |
#render_tags(object) ⇒ String
Renders all tags for an object as Markdown.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/yard/markdown/tag_formatting_helper.rb', line 11 def (object) , = object..partition { |tag| tag.tag_name == "example" } lines = .map { |tag| "- #{format_tag(tag)}" } .each do |tag| lines << nil unless lines.empty? title = tag.name.to_s.rstrip.empty? ? "**@example**" : "**@example #{tag.name}**" lines << title lines << "```ruby" lines << tag.text.to_s.rstrip lines << "```" end lines.join("\n") end |