Class: Madman::Commands::Nav
- Inherits:
-
MisterBin::Command
- Object
- MisterBin::Command
- Madman::Commands::Nav
- Includes:
- Colsole
- Defined in:
- lib/madman/commands/nav.rb
Instance Method Summary collapse
- #depth ⇒ Object
-
#dir ⇒ Object
CLI Arguments.
- #dry? ⇒ Boolean
- #force? ⇒ Boolean
- #marker ⇒ Object
- #recursive? ⇒ Boolean
- #run ⇒ Object
- #target ⇒ Object
- #update_file(file) ⇒ Object
- #verbose? ⇒ Boolean
Instance Method Details
#depth ⇒ Object
60 |
# File 'lib/madman/commands/nav.rb', line 60 def depth = args['--depth'].to_i |
#dir ⇒ Object
CLI Arguments
59 |
# File 'lib/madman/commands/nav.rb', line 59 def dir = args['DIR'] || '.' |
#dry? ⇒ Boolean
64 |
# File 'lib/madman/commands/nav.rb', line 64 def dry? = args.[]('--dry') |
#force? ⇒ Boolean
63 |
# File 'lib/madman/commands/nav.rb', line 63 def force? = args.[]('--force') |
#marker ⇒ Object
61 |
# File 'lib/madman/commands/nav.rb', line 61 def marker = args.[]('--marker') |
#recursive? ⇒ Boolean
66 |
# File 'lib/madman/commands/nav.rb', line 66 def recursive? = args.[]('--recursive') |
#run ⇒ Object
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 |
#target ⇒ Object
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
65 |
# File 'lib/madman/commands/nav.rb', line 65 def verbose? = args.[]('--verbose') |