Module: YARD::Markdown::SectionAssemblyHelper

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

Overview

Assembles grouped content into ordered Markdown sections.

Instance Method Summary collapse

Instance Method Details

#append_lines(lines, content, separated: true) ⇒ void

This method returns an undefined value.

Appends non-empty content to a mutable list of lines.

Parameters:

  • lines (Array<String>)

    Destination line buffer.

  • content (String)

    Rendered Markdown block to split into lines.

  • separated (Boolean) (defaults to: true)

    Whether to insert a blank separator line first.



38
39
40
41
42
43
# File 'lib/yard/markdown/section_assembly_helper.rb', line 38

def append_lines(lines, content, separated: true)
  return if content.lstrip.empty?

  lines << "" if separated && !lines.empty? && !lines.last.empty?
  lines.concat(content.split("\n"))
end

#grouped_items(items, group_order) ⇒ Array<Array>

Groups items by their YARD group and orders them for rendering.

Parameters:

  • items (Array<#group>)

    Renderable objects that expose a YARD group name.

  • group_order (Array<String>, nil)

    Preferred ordering for named groups.

Returns:

  • (Array<Array>)

    Ordered pairs of group names and grouped items.



23
24
25
26
27
28
29
30
# File 'lib/yard/markdown/section_assembly_helper.rb', line 23

def grouped_items(items, group_order)
  groups = items.group_by(&:group)
  names = groups.keys
  order = Array(group_order)
  ordered_names = (order & names) + (names.compact - order).sort + ([nil] & names)

  ordered_names.map { |name| [name, groups.fetch(name)] }
end

#render_section_content(content) ⇒ String

Returns section content with the expected trailing spacing.

Parameters:

  • content (Object)

    Section content to render.

Returns:

  • (String)

    Section content followed by blank-line spacing.



11
12
13
14
15
16
# File 'lib/yard/markdown/section_assembly_helper.rb', line 11

def render_section_content(content)
  text = content.to_s.strip
  return "" if text.empty?

  "#{text}\n\n"
end