Module: BinMan
Constant Summary
- VERSION =
"1.0.0"
Instance Method Summary (collapse)
-
- (Object) conv(source = nil)
Converts given markdown(7) source into roff(7).
-
- (Object) dump(source = nil)
Extracts leading comment header content from given source and returns the roff(7) conversion thereof.
-
- (Object) help(source = nil, argv = ARGV)
Shows leading comment header from given source as UNIX man page and exits.
-
- (Object) load(source = nil)
Extracts content of leading comment header (which can be one of the following two choices) from given source (IO, file name, or string).
-
- (Object) show(source = nil)
Shows leading comment header from given source as UNIX man page if possible, else falls back to showing leading comment header as-is.
Instance Method Details
- (Object) conv(source = nil)
Converts given markdown(7) source into roff(7).
33 34 35 36 37 38 39 |
# File 'lib/binman.rb', line 33 def conv source=nil header = read(source) require 'redcarpet-manpage' RedcarpetManpage::RENDERER.render(header) rescue LoadError raise 'Run `gem install binman --development` to use BinMan::conv().' end |
- (Object) dump(source = nil)
Extracts leading comment header content from given source and returns the roff(7) conversion thereof.
43 44 45 |
# File 'lib/binman.rb', line 43 def dump source=nil conv load(source) end |
- (Object) help(source = nil, argv = ARGV)
Shows leading comment header from given source as UNIX man page and exits.
67 68 69 70 71 72 |
# File 'lib/binman.rb', line 67 def help source=nil, argv=ARGV unless argv.grep(/^(-h|--help)$/).empty? show source exit end end |
- (Object) load(source = nil)
Extracts content of leading comment header (which can be one of the following two choices) from given source (IO, file name, or string).
(1) A contiguous sequence of single-line comments starting at the
beginning of the file (after shebang and encoding comments plus
optional blank lines) and ending at the first single blank line.
(2) First embedded document delimited by `=begin` and `=end` lines.
Comment markers and shebang/encoding comments are omitted from result.
17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/binman.rb', line 17 def load source=nil header = read(source) # strip shebang and encoding comments [/\A#!.+$/, /\A#.*coding:.+$/].each do |comment| header = $'.lstrip if header =~ comment end if header =~ /\A#/ header.split(/^\s*$/, 2).first.gsub(/^# ?/, '') else header[/^=begin\b.*?$(.*?)^=end\b.*?$/m, 1] end.strip end |
- (Object) show(source = nil)
Shows leading comment header from given source as UNIX man page if possible, else falls back to showing leading comment header as-is.
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/binman.rb', line 49 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.('../../man', file) and system 'man', '-M', man_path, '-a', File.basename(file) header = load(source) begin roff = conv(header) IO.popen('man -l -', 'w') {|man| man.puts roff } rescue => error warn "binman: #{error}" puts header end end |