Module: Yattho::YARD::DocsHelper

Included in:
Backend, Registry, RegistryEntry
Defined in:
lib/yattho/yard/docs_helper.rb

Overview

Helper methods to use for yard documentation

Instance Method Summary collapse

Instance Method Details



35
36
37
# File 'lib/yattho/yard/docs_helper.rb', line 35

def link_to_accessibility
  "[Accessibility](#accessibility)"
end


47
48
49
50
51
52
# File 'lib/yattho/yard/docs_helper.rb', line 47

def link_to_component(component)
  status_module, short_name, class_name = status_module_and_short_name(component)
  status_path = status_module.nil? ? "" : "#{status_module}/"

  "[#{class_name}](/components/#{status_path}#{short_name.downcase})"
end


58
59
60
# File 'lib/yattho/yard/docs_helper.rb', line 58

def link_to_heading_practices
  "[Learn more about best heading practices (WAI Headings)](https://www.w3.org/WAI/tutorials/page-structure/headings/)"
end


54
55
56
# File 'lib/yattho/yard/docs_helper.rb', line 54

def link_to_octicons
  "[Octicon](https://yattho.com/octicons/)"
end


39
40
41
# File 'lib/yattho/yard/docs_helper.rb', line 39

def link_to_system_arguments_docs
  "[System arguments](/system-arguments)"
end


43
44
45
# File 'lib/yattho/yard/docs_helper.rb', line 43

def link_to_typography_docs
  "[Typography](/system-arguments#typography)"
end

#one_of(enumerable, lower: false, sort: true) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/yattho/yard/docs_helper.rb', line 9

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(two_words_connector: ' or ', last_word_connector: ', or ')}."
end

#pretty_value(val) ⇒ Object



69
70
71
72
73
74
75
76
77
78
# File 'lib/yattho/yard/docs_helper.rb', line 69

def pretty_value(val)
  case val
  when nil
    "`nil`"
  when Symbol
    "`:#{val}`"
  else
    "`#{val}`"
  end
end

#status_module_and_short_name(component) ⇒ Object



62
63
64
65
66
67
# File 'lib/yattho/yard/docs_helper.rb', line 62

def status_module_and_short_name(component)
  name_with_status = component.name.gsub(/Yattho::|Component/, "")

  m = name_with_status.match(/(?<status>Beta|Alpha|Deprecated)?(?<_colons>::)?(?<name>.*)/)
  [m[:status]&.downcase, m[:name].gsub("::", ""), m[:name]]
end