Module: YARD::Markdown::ArefHelper
- Included in:
- HeadingHelper
- Defined in:
- lib/yard/markdown/aref_helper.rb
Overview
Computes anchor ids that match the generated Markdown headings.
Instance Method Summary collapse
-
#anchor_component(value) ⇒ String
Encodes a value so it can be embedded safely in an HTML anchor id.
-
#aref(object) ⇒ String
Returns the primary anchor id for a documented object.
Instance Method Details
#anchor_component(value) ⇒ String
Encodes a value so it can be embedded safely in an HTML anchor id.
13 14 15 16 17 |
# File 'lib/yard/markdown/aref_helper.rb', line 13 def anchor_component(value) value.to_s.each_char.map do |char| char.match?(/[A-Za-z0-9_-]/) ? char : format("-%X", char.ord) end.join end |
#aref(object) ⇒ String
Returns the primary anchor id for a documented object.
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/yard/markdown/aref_helper.rb', line 23 def aref(object) type = object.type return "class-#{object.path.gsub("::", "-")}" if type == :class return "module-#{object.path.gsub("::", "-")}" if type == :module return "constant-#{object.name}" if type == :constant return "classvariable-#{anchor_component(object.name)}" if type == :classvariable scope = (object.scope == :class) ? "c" : "i" if !object.attr_info.nil? "attribute-#{scope}-#{object.name}" else "method-#{scope}-#{anchor_component(object.name)}" end end |