Module: YARD::Markdown::HeadingHelper
- Defined in:
- lib/yard/markdown/heading_helper.rb
Overview
Builds headings and legacy anchors for rendered object sections.
Class Method Summary collapse
-
.legacy_aref(object) ⇒ String?
Returns the legacy YARD anchor for an object when one exists.
Instance Method Summary collapse
-
#anchor_tag(id) ⇒ String
Builds an HTML anchor tag for a generated id.
-
#anchor_tags_for(object) ⇒ Array<String>
Returns all anchor tags that should be attached to a heading.
-
#heading_with_anchors(heading, object) ⇒ String
Appends the generated anchor tags to a Markdown heading.
Class Method Details
.legacy_aref(object) ⇒ String?
Returns the legacy YARD anchor for an object when one exists.
11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/yard/markdown/heading_helper.rb', line 11 def self.legacy_aref(object) name = object.name case object.type when :constant "#{name}-constant" when :classvariable "#{name}-classvariable" when :method "#{name}-#{(object.scope == :class) ? "class" : "instance"}_method" end end |
Instance Method Details
#anchor_tag(id) ⇒ String
Builds an HTML anchor tag for a generated id.
46 47 48 |
# File 'lib/yard/markdown/heading_helper.rb', line 46 def anchor_tag(id) %(<a id="#{id}"></a>) end |
#anchor_tags_for(object) ⇒ Array<String>
Returns all anchor tags that should be attached to a heading.
28 29 30 31 |
# File 'lib/yard/markdown/heading_helper.rb', line 28 def (object) anchors = [ArefHelper.aref(object), HeadingHelper.legacy_aref(object)].compact anchors.map { |id| anchor_tag(id) } end |
#heading_with_anchors(heading, object) ⇒ String
Appends the generated anchor tags to a Markdown heading.
38 39 40 |
# File 'lib/yard/markdown/heading_helper.rb', line 38 def heading_with_anchors(heading, object) "#{heading} #{(object).join(" ")}" end |