Class: Madman::Commands::Nav

Inherits:
MisterBin::Command
  • Object
show all
Includes:
Colsole
Defined in:
lib/madman/commands/nav.rb

Instance Method Summary collapse

Instance Method Details

#depthObject



57
# File 'lib/madman/commands/nav.rb', line 57

def depth;      args['--depth'].to_i; end

#dirObject

CLI Arguments



56
# File 'lib/madman/commands/nav.rb', line 56

def dir;        args['DIR'] || '.'; end

#dry?Boolean

Returns:

  • (Boolean)


61
# File 'lib/madman/commands/nav.rb', line 61

def dry?;       args['--dry']; end

#force?Boolean

Returns:

  • (Boolean)


60
# File 'lib/madman/commands/nav.rb', line 60

def force?;     args['--force']; end

#markerObject



58
# File 'lib/madman/commands/nav.rb', line 58

def marker;     args['--marker']; end

#recursive?Boolean

Returns:

  • (Boolean)


63
# File 'lib/madman/commands/nav.rb', line 63

def recursive?; args['--recursive']; end

#runObject



29
30
31
32
33
34
35
36
37
# 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

#targetObject



59
# File 'lib/madman/commands/nav.rb', line 59

def target;     args['--target']; end

#update_file(file) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
52
# 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?Boolean

Returns:

  • (Boolean)


62
# File 'lib/madman/commands/nav.rb', line 62

def verbose?;   args['--verbose']; end