Module: YARD::DocsHelper
- Defined in:
- lib/yard/docs_helper.rb
Overview
Helper methods to use for yard documentation
Instance Method Summary collapse
- #link_to_accessibility ⇒ Object
- #link_to_attributes_docs ⇒ Object
- #link_to_classes_docs ⇒ Object
- #link_to_component(component) ⇒ Object
- #link_to_heading_practices ⇒ Object
- #link_to_heroicons ⇒ Object
- #link_to_typography_docs ⇒ Object
- #one_of(enumerable, lower: false, sort: true) ⇒ Object
- #pretty_value(val) ⇒ Object
- #status_module_and_short_name(component) ⇒ Object
Instance Method Details
#link_to_accessibility ⇒ Object
34 35 36 |
# File 'lib/yard/docs_helper.rb', line 34 def link_to_accessibility "[Accessibility](#accessibility)" end |
#link_to_attributes_docs ⇒ Object
42 43 44 |
# File 'lib/yard/docs_helper.rb', line 42 def link_to_attributes_docs "[Classes and attributes](/classes-attributes)" end |
#link_to_classes_docs ⇒ Object
38 39 40 |
# File 'lib/yard/docs_helper.rb', line 38 def link_to_classes_docs "[Classes and attributes](/classes-attributes)" end |
#link_to_component(component) ⇒ Object
50 51 52 53 54 55 |
# File 'lib/yard/docs_helper.rb', line 50 def link_to_component(component) (status_module, short_name) = status_module_and_short_name(component) status_path = status_module.nil? ? "" : "/" "[#{short_name}](/components/#{status_path}#{short_name.downcase})" end |
#link_to_heading_practices ⇒ Object
61 62 63 |
# File 'lib/yard/docs_helper.rb', line 61 def link_to_heading_practices "[Learn more about best heading practices (WAI Headings)](https://www.w3.org/WAI/tutorials/page-structure/headings/)" end |
#link_to_heroicons ⇒ Object
57 58 59 |
# File 'lib/yard/docs_helper.rb', line 57 def link_to_heroicons "[Heroicon](https://ariadne.style/heroicons/)" end |
#link_to_typography_docs ⇒ Object
46 47 48 |
# File 'lib/yard/docs_helper.rb', line 46 def link_to_typography_docs "[Typography](/system-arguments#typography)" end |
#one_of(enumerable, lower: false, sort: true) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/yard/docs_helper.rb', line 8 def one_of(enumerable, lower: false, sort: true) # Sort the array if requested if sort enumerable = enumerable.sort do |a, b| a.instance_of?(b.class) ? a <=> b : a.class.to_s <=> b.class.to_s end end values = case enumerable when Hash enumerable.map do |key, value| "#{pretty_value(key)} (#{pretty_value(value)})" end else enumerable.map do |key| pretty_value(key) end end prefix = "One of" prefix = prefix.downcase if lower "#{prefix} #{values.to_sentence(last_word_connector: ", or ")}." end |
#pretty_value(val) ⇒ Object
72 73 74 75 76 77 78 79 80 81 |
# File 'lib/yard/docs_helper.rb', line 72 def pretty_value(val) case val when nil "`nil`" when Symbol "`:#{val}`" else "`#{val}`" end end |
#status_module_and_short_name(component) ⇒ Object
65 66 67 68 69 70 |
# File 'lib/yard/docs_helper.rb', line 65 def status_module_and_short_name(component) name_with_status = component.name.gsub(/Ariadne::|Component/, "") m = name_with_status.match(/(?<status>Beta|Alpha|Deprecated)?(?<_colons>::)?(?<name>.*)/) [m[:status]&.downcase, m[:name].gsub("::", "")] end |