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_component(component) ⇒ Object
- #link_to_heading_practices ⇒ Object
- #link_to_octicons ⇒ Object
- #link_to_system_arguments_docs ⇒ Object
- #link_to_typography_docs ⇒ Object
- #one_of(enumerable, lower: false, sort: true) ⇒ Object
- #pretty_value(val) ⇒ Object
Instance Method Details
#link_to_accessibility ⇒ Object
31 32 33 |
# File 'lib/yard/docs_helper.rb', line 31 def link_to_accessibility "[Accessibility](#system-arguments)" end |
#link_to_component(component) ⇒ Object
43 44 45 46 |
# File 'lib/yard/docs_helper.rb', line 43 def link_to_component(component) short_name = component.name.gsub(/Primer|::|Component/, "") "[#{short_name}](/components/#{short_name.downcase})" end |
#link_to_heading_practices ⇒ Object
52 53 54 |
# File 'lib/yard/docs_helper.rb', line 52 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_octicons ⇒ Object
48 49 50 |
# File 'lib/yard/docs_helper.rb', line 48 def link_to_octicons "[Octicon](https://primer.style/octicons/)" end |
#link_to_system_arguments_docs ⇒ Object
35 36 37 |
# File 'lib/yard/docs_helper.rb', line 35 def link_to_system_arguments_docs "[System arguments](/system-arguments)" end |
#link_to_typography_docs ⇒ Object
39 40 41 |
# File 'lib/yard/docs_helper.rb', line 39 def link_to_typography_docs "[Typography](/system-arguments#typography)" end |
#one_of(enumerable, lower: false, sort: true) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/yard/docs_helper.rb', line 6 def one_of(enumerable, lower: false, sort: true) # Sort the array if requested if sort compare = ->(a, b) { a.class == b.class ? a <=> b : a.class.to_s <=> b.class.to_s } enumerable = enumerable.sort { |a, b| compare.call(a, b) } 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
56 57 58 59 60 61 62 63 64 65 |
# File 'lib/yard/docs_helper.rb', line 56 def pretty_value(val) case val when nil "`nil`" when Symbol "`:#{val}`" else "`#{val}`" end end |