class Madman::Commands::Nav

Public Instance Methods

depth() click to toggle source
# File lib/madman/commands/nav.rb, line 57
def depth;      args['--depth'].to_i; end
dir() click to toggle source

CLI Arguments

# File lib/madman/commands/nav.rb, line 56
def dir;        args['DIR'] || '.'; end
dry?() click to toggle source
# File lib/madman/commands/nav.rb, line 61
def dry?;       args['--dry']; end
force?() click to toggle source
# File lib/madman/commands/nav.rb, line 60
def force?;     args['--force']; end
marker() click to toggle source
# File lib/madman/commands/nav.rb, line 58
def marker;     args['--marker']; end
recursive?() click to toggle source
# File lib/madman/commands/nav.rb, line 63
def recursive?; args['--recursive']; end
run() click to toggle source
# File lib/madman/commands/nav.rb, line 29
def run
  if recursive?
    Dir["#{dir}/**/#{target}"].each { |file| update_file file }
  else
    update_file "#{dir}/#{target}"
  end

  say dry? ? "Done (dry mode, no changes were made)" : "Done"
end
target() click to toggle source
# File lib/madman/commands/nav.rb, line 59
def target;     args['--target']; end
update_file(file) click to toggle source
# File lib/madman/commands/nav.rb, line 39
def update_file(file)
  say "Updating !txtgrn!#{file}"
  file_dir = File.dirname file
  toc = Madman::Navigation.new file_dir, depth: depth
  doc = Madman::Document.from_file file
  doc.inject toc.markdown, marker: marker, force: force?

  if verbose?
    say word_wrap "  !txtblu!#{doc.text}"
    say ""
  end

  doc.save unless dry?
end
verbose?() click to toggle source
# File lib/madman/commands/nav.rb, line 62
def verbose?;   args['--verbose']; end