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}` [#{MethodPresentationHelper.attribute_access(item)}]" }
end

#render_collection(section_title, items, group_order, &label) {|item| ... } ⇒ 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.

  • label (Proc)

    Item-label renderer.

Yield Parameters:

  • item (YARD::CodeObjects::Base)

    Object whose label should be rendered.

Returns:

  • (String)

    Markdown for the collection section.



43
44
45
46
47
48
49
50
51
52
53
# File 'lib/yard/markdown/collection_rendering_helper.rb', line 43

def render_collection(section_title, items, group_order, &label)
  groups = SectionAssemblyHelper.grouped_items(items, group_order)
  grouped = groups.any? { |name, _items| name }
  body = groups.map do |name, group_items|
    item_heading = grouped ? "####" : "###"
    item_markdown = group_items.map { |item| render_collection_item(item_heading, item, &label) }.join("\n\n")
    [("### #{name || "General"}" if grouped), item_markdown].compact
  end

  ["## #{section_title}", body].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(&: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| "`#{MethodPresentationHelper.formatted_method_heading(item)}`" }
end