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.



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

def render_attributes(attrs, group_order)
  lines = ['## Attributes']
  grouped_attrs = grouped_items(attrs, group_order)
  uses_groups = grouped_attrs.any? { |name, _items| !name.nil? }

  grouped_attrs.each do |group_name, items|
    if uses_groups
      lines << "### #{group_name || 'General'}"
      item_heading = '####'
    else
      item_heading = '###'
    end

    lines << items.map { |item|
      item_lines = [heading_with_anchors("#{item_heading} `#{item.name}` [#{attribute_access(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
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/yard/markdown/collection_rendering_helper.rb', line 12

def render_constants(constants, group_order)
  lines = ['## Constants']
  grouped_constants = grouped_items(constants.sort_by { |item| item.name }, group_order)
  uses_groups = grouped_constants.any? { |name, _items| !name.nil? }

  grouped_constants.each do |group_name, items|
    if uses_groups
      lines << "### #{group_name || 'General'}"
      item_heading = '####'
    else
      item_heading = '###'
    end

    lines << items.map { |item|
      item_lines = [heading_with_anchors("#{item_heading} `#{item.name}`", 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_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.



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/yard/markdown/collection_rendering_helper.rb', line 71

def render_methods(section_title, methods, group_order)
  lines = ["## #{section_title}"]
  grouped_methods = grouped_items(methods, group_order)
  uses_groups = grouped_methods.any? { |name, _items| !name.nil? }

  grouped_methods.each do |group_name, items|
    if uses_groups
      lines << "### #{group_name || 'General'}"
      item_heading = '####'
    else
      item_heading = '###'
    end

    lines << items.map { |item|
      item_lines = [heading_with_anchors("#{item_heading} `#{formatted_method_heading(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