class Mdtoc::Node

Public Class Methods

for_path(path, depth = 0) click to toggle source
# File lib/mdtoc/node.rb, line 19
def for_path(path, depth = 0)
  # Ensure that `path` is a relative path, so that all links are relative and therefore portable.
  path = Pathname.new(path)
  path = path.relative_path_from(Dir.pwd) if path.absolute?
  path = path.to_s
  File.directory?(path) ? DirNode.new(path, depth) : FileNode.new(path, depth)
end
new(path, depth) click to toggle source
# File lib/mdtoc/node.rb, line 36
def initialize(path, depth)
  @path = path
  @depth = depth
end
render(paths) click to toggle source
# File lib/mdtoc/node.rb, line 28
def render(paths)
  paths
    .flat_map { |path| for_path(path).headers }
    .join("\n")
end

Public Instance Methods

headers() click to toggle source
# File lib/mdtoc/node.rb, line 42
def headers; end
label() click to toggle source
# File lib/mdtoc/node.rb, line 45
def label
  File.basename(@path, File.extname(@path)).gsub(/_+/, ' ').gsub(/\s+/, ' ').capitalize
end