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



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

def depth = args['--depth'].to_i

#dirObject

CLI Arguments



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

def dir = args['DIR'] || '.'

#dry?Boolean

Returns:

  • (Boolean)


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

def dry? = args.[]('--dry')

#force?Boolean

Returns:

  • (Boolean)


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

def force? = args.[]('--force')

#markerObject



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

def marker = args.[]('--marker')

#recursive?Boolean

Returns:

  • (Boolean)


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

def recursive? = args.[]('--recursive')

#runObject



32
33
34
35
36
37
38
39
40
# File 'lib/madman/commands/nav.rb', line 32

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



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

def target = args.[]('--target')

#update_file(file) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/madman/commands/nav.rb', line 42

def update_file(file)
  say "Updating g`#{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 "  b`#{doc.text}`"
    say ''
  end

  doc.save unless dry?
end

#verbose?Boolean

Returns:

  • (Boolean)


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

def verbose? = args.[]('--verbose')