Module: YARD::Markdown::CollectionRenderingHelper

Defined in:
lib/yard/markdown/collection_rendering_helper.rb

Overview

Renders grouped Markdown sections for constants, attributes, and methods.

Instance Method Summary collapse

Instance Method Details

#render_attributes(attrs, group_order) ⇒ String

Renders the attributes section for an object page.

Parameters:

  • attrs (Array<YARD::CodeObjects::MethodObject>)

    Attributes to render.

  • group_order (Array<String>, nil)

    Preferred ordering for group headings.

Returns:

  • (String)

    Markdown for the attributes section.



21
22
23
# File 'lib/yard/markdown/collection_rendering_helper.rb', line 21

def render_attributes(attrs, group_order)
  render_collection("Attributes", attrs, group_order) { |item| "`#{item.name}` [#{attribute_access(item)}]" }
end

#render_collection(section_title, items, group_order) ⇒ String

Renders a grouped collection with a caller-provided item label.

Parameters:

  • section_title (String)

    Section title to render.

  • items (Array<YARD::CodeObjects::Base>)

    Objects to group and render.

  • group_order (Array<String>, nil)

    Preferred ordering for group headings.

Returns:

  • (String)

    Markdown for the collection section.



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/yard/markdown/collection_rendering_helper.rb', line 41

def render_collection(section_title, items, group_order)
  lines = ["## #{section_title}"]
  groups = grouped_items(items, group_order)
  uses_groups = groups.any? { |name, _items| !name.nil? }
  item_heading = uses_groups ? "####" : "###"

  groups.each do |group_name, group_items|
    lines << "### #{group_name || "General"}" if uses_groups

    lines << group_items.map { |item|
      item_lines = [heading_with_anchors("#{item_heading} #{yield(item)}", item)]
      append_lines(item_lines, documented_text(item), separated: false)
      append_lines(item_lines, render_tags(item), separated: false)
      item_lines.join("\n")
    }.join("\n\n")
  end

  lines.join("\n")
end

#render_constants(constants, group_order) ⇒ String

Renders the constants section for an object page.

Parameters:

  • constants (Array<YARD::CodeObjects::Base>)

    Constant objects collected for the current page.

  • group_order (Array<String>, nil)

    Preferred ordering for group headings.

Returns:

  • (String)

    Markdown for the constants section.



12
13
14
# File 'lib/yard/markdown/collection_rendering_helper.rb', line 12

def render_constants(constants, group_order)
  render_collection("Constants", constants.sort_by { |item| item.name }, group_order) { |item| "`#{item.name}`" }
end

#render_methods(section_title, methods, group_order) ⇒ String

Renders a method section for an object page.

Parameters:

  • section_title (String)

    Section title to render.

  • methods (Array<YARD::CodeObjects::MethodObject>)

    Method objects collected for the current section.

  • group_order (Array<String>, nil)

    Preferred ordering for group headings.

Returns:

  • (String)

    Markdown for the method section.



31
32
33
# File 'lib/yard/markdown/collection_rendering_helper.rb', line 31

def render_methods(section_title, methods, group_order)
  render_collection(section_title, methods, group_order) { |item| "`#{formatted_method_heading(item)}`" }
end