Class: ReadmeYard::ExampleTag

Inherits:
Object
  • Object
show all
Defined in:
lib/readme_yard/example_tag.rb

Overview

The Example Tag leverages YARD's standard @example tag syntax, allowing you to include example code in your README directly from source files. This saves time and ensures your README stays in sync with your YARD documentation

Class Method Summary collapse

Class Method Details

.format_ruby(text) ⇒ Object



31
32
33
# File 'lib/readme_yard/example_tag.rb', line 31

def format_ruby(text)
  "```ruby\n#{text}\n```\n"
end

.format_tag(yard_object, tag) ⇒ Object



26
27
28
29
# File 'lib/readme_yard/example_tag.rb', line 26

def format_tag(yard_object, tag)
  text = tag.text.empty? ? yard_object.source : tag.text
  format_ruby(text)
end

.format_tags(yard_object, yard_tags) ⇒ Object



22
23
24
# File 'lib/readme_yard/example_tag.rb', line 22

def format_tags(yard_object, yard_tags)
  yard_tags.map { |tag| format_tag(yard_object, tag) }.join("\n")
end

.hello_worldObject

Examples:

ReadmeYard::ExampleTag.hello_world #=> "Hello 🌎 🌍 🌏"


18
19
20
# File 'lib/readme_yard/example_tag.rb', line 18

def hello_world
  "Hello 🌎 🌍 🌏"
end