Class: Mdtoc::DirNode

Inherits:
Node
  • Object
show all
Defined in:
lib/mdtoc/node.rb

Instance Method Summary collapse

Methods inherited from Node

for_path, #initialize, #label

Constructor Details

This class inherits a constructor from Mdtoc::Node

Instance Method Details

#headersObject



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/mdtoc/node.rb', line 40

def headers
  readme_path = T.let(nil, T.nilable(String))
  child_headers = Dir
    .each_child(@path)
    .map { |path| File.join(@path, path) }
    .reject { |path| readme_path = path if File.basename(path).downcase == 'readme.md' }
    .sort!
    .map { |path| Node.for_path(path, @depth + 1).headers }
    .flatten(1)
  return child_headers unless readme_path

  # Include the headers from the README at the beginning.
  readme_headers = FileNode.new(readme_path, @depth).headers
  readme_headers.push(*child_headers)
end