lib/binman.rb in binman-3.2.1 vs lib/binman.rb in binman-3.3.0
- old
+ new
@@ -29,14 +29,14 @@
end.strip
end
# Converts given markdown(7) source into roff(7).
def conv source=nil
- require 'md2man'
- Md2Man::ENGINE.render(read(source))
+ require 'md2man/roff/engine'
+ Md2Man::Roff::ENGINE.render(read(source))
rescue LoadError
- raise 'Run `gem install md2man -v "~>1"` to use BinMan::conv().'
+ raise 'Run `gem install md2man --version "~> 2.0"` to use BinMan::conv().'
end
# Extracts leading comment header content from given
# source and returns the roff(7) conversion thereof.
def dump source=nil
@@ -45,13 +45,26 @@
# Shows leading comment header from given source as UNIX man page if
# possible, else falls back to showing leading comment header as-is.
def show source=nil
# try showing existing man page files for given source
- return if file = find(source) and File.exist? file and
- File.exist? man_path = File.expand_path('../../man', file) and
- system 'man', '-M', man_path, '-a', File.basename(file)
+ if file = find(source) and File.exist? file
+ man_page = File.basename(file)
+ man_path = File.expand_path('../../man', file)
+ # try showing HTML manual page in a web browser in background
+ require 'opener'
+ Dir["#{man_path}/**/#{man_page}.*.html"].each do |man_html|
+ # close streams to avoid interference with man(1) reader below
+ Opener.spawn man_html, 0 => :close, 1 => :close, 2 => :close
+ end
+
+ # try showing roff manual page in man(1) reader in foreground;
+ # close STDERR to avoid interference with the fall back below
+ return if system 'man', '-M', man_path, '-a', man_page, 2 => :close
+ end
+
+ # fall back to showing leading comment header as-is
header = load(source)
begin
roff = conv(header)
require 'tempfile'