binman 0.1.2 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/HISTORY.markdown CHANGED
@@ -1,3 +1,31 @@
1
+ ------------------------------------------------------------------------------
2
+ Version 1.0.0 (2011-10-13)
3
+ ------------------------------------------------------------------------------
4
+
5
+ Incompatible changes:
6
+
7
+ * The `BinMan::dump()` method and corresponding `binman dump` command now
8
+ extract the leading comment header from their input before returning the
9
+ markdown to roff conversion thereof.
10
+
11
+ * The `BinMan::read()` method and corresponding `binman read` command have
12
+ been renamed to `BinMan::load()` and `binman load` respectively.
13
+
14
+ New features:
15
+
16
+ * Added `BinMan::conv()` method and corresponding `binman conv` command to
17
+ encapsulate the markdown to roff conversion process.
18
+
19
+ Bug fixes:
20
+
21
+ * Pre-built man pages included alongside a `bin/` script were not displayed.
22
+ Instead, binman was (incorrectly) always trying to convert the leading
23
+ comment header from the `bin/` script into a UNIX man page for display.
24
+
25
+ Housekeeping:
26
+
27
+ * README: explain dev deps and `man/` dir packaging.
28
+
1
29
  ------------------------------------------------------------------------------
2
30
  Version 0.1.2 (2011-10-13)
3
31
  ------------------------------------------------------------------------------
@@ -10,6 +38,9 @@ Housekeeping:
10
38
 
11
39
  * Forgot to introduce leading comment headers in binman(1) man page.
12
40
 
41
+ [Redcarpet2]: https://github.com/tanoku/redcarpet
42
+ [redcarpet-manpage]: http://rdoc.info/github/sunaku/redcarpet-manpage
43
+
13
44
  ------------------------------------------------------------------------------
14
45
  Version 0.1.1 (2011-10-13)
15
46
  ------------------------------------------------------------------------------
data/README.markdown CHANGED
@@ -33,10 +33,14 @@ Prerequisites
33
33
  Installation
34
34
  ------------------------------------------------------------------------------
35
35
 
36
- As a Ruby gem:
36
+ As a Ruby gem (without markdown to roff converter):
37
37
 
38
38
  gem install binman
39
39
 
40
+ As a Ruby gem (with extra cheese and everything please):
41
+
42
+ gem install binman --development
43
+
40
44
  As a Git clone:
41
45
 
42
46
  git clone git://github.com/sunaku/binman
@@ -81,6 +85,16 @@ Add the following line to your `Rakefile` and you've got a `binman` task!
81
85
 
82
86
  require 'binman/rake_tasks'
83
87
 
88
+ It will pre-build UNIX man page files for your `bin/` scripts into a `man/`
89
+ directory so that your end-users do not need the markdown to roff converter
90
+ installed in order to view your man pages! Just remember to add the `man/`
91
+ directory's contents to your gemspec or release package:
92
+
93
+ Gem::Specification.new do |s|
94
+ # ... your stuff ...
95
+ s.files += Dir['man/**/*']
96
+ end
97
+
84
98
  ------------------------------------------------------------------------------
85
99
  License
86
100
  ------------------------------------------------------------------------------
data/bin/binman CHANGED
@@ -2,7 +2,7 @@
2
2
  # encoding: utf-8
3
3
  =begin
4
4
 
5
- BINMAN 1 "2011-10-13" "0.1.2" "Ruby User Manuals"
5
+ BINMAN 1 "2011-10-13" "1.0.0" "Ruby User Manuals"
6
6
  =================================================
7
7
 
8
8
  NAME
@@ -60,16 +60,20 @@ OPTIONS
60
60
  COMMANDS
61
61
  --------
62
62
 
63
- `read` [*FILE*]
64
- Print the leading comment header extracted from the given *FILE* or stdin.
63
+ `show` [*FILE*]
64
+ Use man(1) to display the roff(7) conversion of the leading comment header
65
+ extracted from the given *FILE* or STDIN.
66
+
67
+ `load` [*FILE*]
68
+ Print the leading comment header extracted from the given *FILE* or STDIN.
65
69
 
66
70
  `dump` [*FILE*]
67
71
  Print the roff(7) conversion of the leading comment header extracted from
68
- the given *FILE* or stdin.
72
+ the given *FILE* or STDIN.
69
73
 
70
- `show` [*FILE*]
71
- Use man(1) to display the roff(7) conversion of the leading comment header
72
- extracted from the given *FILE* or stdin.
74
+ `conv` [*FILE*]
75
+ Print the roff(7) conversion of the markdown(7) document read from the given
76
+ *FILE* or STDIN.
73
77
 
74
78
  SEE ALSO
75
79
  --------
@@ -84,12 +88,15 @@ man(1), roff(7), markdown(7)
84
88
  require 'binman'
85
89
  BinMan.help
86
90
 
87
- command, file = ARGV
88
- file ||= STDIN
91
+ command, source = ARGV
92
+ source ||= STDIN
89
93
 
90
94
  case command
91
- when 'read' then puts BinMan.read(file)
92
- when 'dump' then puts BinMan.dump(BinMan.read(file))
93
- when 'show' then BinMan.show(file)
94
- else raise ArgumentError, 'bad command; try --help'
95
+ when 'show'
96
+ BinMan.show source
97
+ when 'load', 'dump', 'conv'
98
+ puts BinMan.send(command, source)
99
+ else
100
+ warn 'bad command; try --help'
101
+ exit!
95
102
  end
data/lib/binman.rb CHANGED
@@ -3,8 +3,7 @@ require "binman/version"
3
3
  module BinMan
4
4
  extend self
5
5
 
6
- ##
7
- # Returns content of leading comment header (which can be one of the
6
+ # Extracts content of leading comment header (which can be one of the
8
7
  # following two choices) from given source (IO, file name, or string).
9
8
  #
10
9
  # (1) A contiguous sequence of single-line comments starting at the
@@ -15,51 +14,48 @@ module BinMan
15
14
  #
16
15
  # Comment markers and shebang/encoding comments are omitted from result.
17
16
  #
18
- def read source=nil
19
- source = source.read if source.respond_to? :read
20
- source ||=
21
- if first_caller = caller.find {|f| not f.start_with? __FILE__ }
22
- first_caller.sub(/:\d+.*$/, '')
23
- end
24
- source = File.read(source) if File.exist? source
25
-
26
- string = source.to_s
17
+ def load source=nil
18
+ header = read(source)
27
19
 
28
20
  # strip shebang and encoding comments
29
21
  [/\A#!.+$/, /\A#.*coding:.+$/].each do |comment|
30
- string = $'.lstrip if string =~ comment
22
+ header = $'.lstrip if header =~ comment
31
23
  end
32
24
 
33
- if string =~ /\A#/
34
- string.split(/^\s*$/, 2).first.gsub(/^# ?/, '')
25
+ if header =~ /\A#/
26
+ header.split(/^\s*$/, 2).first.gsub(/^# ?/, '')
35
27
  else
36
- string[/^=begin\b.*?$(.*?)^=end\b.*?$/m, 1]
28
+ header[/^=begin\b.*?$(.*?)^=end\b.*?$/m, 1]
37
29
  end.strip
38
30
  end
39
31
 
40
- ##
41
- # Converts given leading comment header (produced by #read) into roff(7).
42
- #
43
- def dump header
32
+ # Converts given markdown(7) source into roff(7).
33
+ def conv source=nil
34
+ header = read(source)
44
35
  require 'redcarpet-manpage'
45
36
  RedcarpetManpage::RENDERER.render(header)
46
37
  rescue LoadError
47
- raise 'Run `gem install binman --development` to use dump().'
38
+ raise 'Run `gem install binman --development` to use BinMan::conv().'
48
39
  end
49
40
 
50
- ##
51
- # Shows leading comment header from given source as UNIX man page.
52
- #
41
+ # Extracts leading comment header content from given
42
+ # source and returns the roff(7) conversion thereof.
43
+ def dump source=nil
44
+ conv load(source)
45
+ end
46
+
47
+ # Shows leading comment header from given source as UNIX man page if
48
+ # possible, else falls back to showing leading comment header as-is.
53
49
  def show source=nil
54
50
  # try showing existing man page files for given source
55
- return if source and File.exist? source and
56
- File.exist? man_path = File.expand_path('../../man', source) and
57
- system 'man', '-M', man_path, '-a', File.basename(source)
51
+ return if file = find(source) and File.exist? file and
52
+ File.exist? man_path = File.expand_path('../../man', file) and
53
+ system 'man', '-M', man_path, '-a', File.basename(file)
58
54
 
59
- header = read(source)
55
+ header = load(source)
60
56
 
61
57
  begin
62
- roff = dump(header)
58
+ roff = conv(header)
63
59
  IO.popen('man -l -', 'w') {|man| man.puts roff }
64
60
  rescue => error
65
61
  warn "binman: #{error}"
@@ -67,13 +63,31 @@ module BinMan
67
63
  end
68
64
  end
69
65
 
70
- ##
71
66
  # Shows leading comment header from given source as UNIX man page and exits.
72
- #
73
67
  def help source=nil, argv=ARGV
74
68
  unless argv.grep(/^(-h|--help)$/).empty?
75
69
  show source
76
70
  exit
77
71
  end
78
72
  end
73
+
74
+ private
75
+
76
+ # Returns contents of given source I/O, file name, or string.
77
+ def read source=nil
78
+ if source.respond_to? :read
79
+ source.read
80
+ elsif file = find(source) and File.exist? file
81
+ File.read file
82
+ else
83
+ source
84
+ end
85
+ end
86
+
87
+ # Resolves given source into first caller's file name if nil.
88
+ def find source=nil
89
+ source || if first_caller = caller.find {|f| not f.start_with? __FILE__ }
90
+ first_caller.sub(/:\d+.*$/, '')
91
+ end
92
+ end
79
93
  end
@@ -7,7 +7,7 @@ mans = bins.pathmap("#{path}/%n.1")
7
7
  bins.zip(mans).each do |bin, man|
8
8
  file man => [bin, path] do
9
9
  require 'binman'
10
- roff = BinMan.dump(BinMan.read(bin))
10
+ roff = BinMan.dump(bin)
11
11
  File.open(man, 'w') {|f| f << roff }
12
12
  end
13
13
  end
@@ -1,3 +1,3 @@
1
1
  module BinMan
2
- VERSION = "0.1.2"
2
+ VERSION = "1.0.0"
3
3
  end
data/man/man1/binman.1 CHANGED
@@ -1,4 +1,4 @@
1
- .TH BINMAN 1 "2011-10-13" "0.1.2" "Ruby User Manuals"
1
+ .TH BINMAN 1 "2011-10-13" "1.0.0" "Ruby User Manuals"
2
2
  .SH NAME
3
3
  .PP
4
4
  binman \- UNIX man pages for Ruby \fBbin/\fP scripts
@@ -55,22 +55,30 @@ Display this help manual using
55
55
  .BR man (1).
56
56
  .SH COMMANDS
57
57
  .TP
58
- \fBread\fP [\fIFILE\fP]
59
- Print the leading comment header extracted from the given \fIFILE\fP or stdin.
58
+ \fBshow\fP [\fIFILE\fP]
59
+ Use
60
+ .BR man (1)
61
+ to display the
62
+ .BR roff (7)
63
+ conversion of the leading comment header
64
+ extracted from the given \fIFILE\fP or STDIN.
65
+ .TP
66
+ \fBload\fP [\fIFILE\fP]
67
+ Print the leading comment header extracted from the given \fIFILE\fP or STDIN.
60
68
  .TP
61
69
  \fBdump\fP [\fIFILE\fP]
62
70
  Print the
63
71
  .BR roff (7)
64
72
  conversion of the leading comment header extracted from
65
- the given \fIFILE\fP or stdin.
73
+ the given \fIFILE\fP or STDIN.
66
74
  .TP
67
- \fBshow\fP [\fIFILE\fP]
68
- Use
69
- .BR man (1)
70
- to display the
75
+ \fBconv\fP [\fIFILE\fP]
76
+ Print the
71
77
  .BR roff (7)
72
- conversion of the leading comment header
73
- extracted from the given \fIFILE\fP or stdin.
78
+ conversion of the
79
+ .BR markdown (7)
80
+ document read from the given
81
+ \fIFILE\fP or STDIN.
74
82
  .SH SEE ALSO
75
83
  .PP
76
84
  .BR man (1),
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: binman
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 1.0.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2011-10-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: redcarpet-manpage
16
- requirement: &21068040 !ruby/object:Gem::Requirement
16
+ requirement: &19205100 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,7 +21,7 @@ dependencies:
21
21
  version: 0.0.1
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *21068040
24
+ version_requirements: *19205100
25
25
  description: ''
26
26
  email:
27
27
  - sunaku@gmail.com