Class: Choosy::Printing::ManpagePrinter
- Inherits:
-
BasePrinter
- Object
- BasePrinter
- Choosy::Printing::ManpagePrinter
- Defined in:
- lib/choosy/printing/manpage_printer.rb
Constant Summary
Constants included from Terminal
Terminal::DEFAULT_COLUMN_COUNT, Terminal::DEFAULT_LINE_COUNT
Instance Attribute Summary collapse
-
#manpage ⇒ Object
readonly
Returns the value of attribute manpage.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#synopsis ⇒ Object
readonly
Returns the value of attribute synopsis.
Attributes inherited from BasePrinter
#formatting_options, #heading_styles, #indent, #offset, #option_styles
Attributes included from Terminal
Instance Method Summary collapse
- #format_command(command, formatted_command, indent) ⇒ Object
- #format_element(item) ⇒ Object
- #format_epilogue(command) ⇒ Object
- #format_name(command) ⇒ Object
- #format_option(option, formatted_option, indent) ⇒ Object
- #format_prologue(command) ⇒ Object
- #format_synopsis(command) ⇒ Object
-
#initialize(options = {}) ⇒ ManpagePrinter
constructor
A new instance of ManpagePrinter.
- #print!(command) ⇒ Object
Methods inherited from BasePrinter
#command_name, #format!, #line_count, #regular_option, #usage_option, #usage_wrapped
Methods included from Terminal
#color, #command_exists?, die, #die, #page, #pager, #pager?, #pipe_in, #pipe_out, #stdin?, #unformatted
Constructor Details
#initialize(options = {}) ⇒ ManpagePrinter
Returns a new instance of ManpagePrinter.
11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/choosy/printing/manpage_printer.rb', line 11 def initialize(={}) super() @name = [:name] || "NAME" @synopsis = [:synopsis] || 'SYNOPSIS' @manpage = Manpage.new @manpage.section = [:section] || 1 @manpage.date = [:date] @manpage.manual = [:manual] @manpage.version = [:version] end |
Instance Attribute Details
#manpage ⇒ Object (readonly)
Returns the value of attribute manpage.
9 10 11 |
# File 'lib/choosy/printing/manpage_printer.rb', line 9 def manpage @manpage end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
9 10 11 |
# File 'lib/choosy/printing/manpage_printer.rb', line 9 def name @name end |
#synopsis ⇒ Object (readonly)
Returns the value of attribute synopsis.
9 10 11 |
# File 'lib/choosy/printing/manpage_printer.rb', line 9 def synopsis @synopsis end |
Instance Method Details
#format_command(command, formatted_command, indent) ⇒ Object
70 71 72 |
# File 'lib/choosy/printing/manpage_printer.rb', line 70 def format_command(command, formatted_command, indent) @manpage.term_paragraph(@manpage.format.italics(formatted_command), command.summary || "", indent.length) end |
#format_element(item) ⇒ Object
74 75 76 77 78 79 80 |
# File 'lib/choosy/printing/manpage_printer.rb', line 74 def format_element(item) if item.header? @manpage.section_heading(item.value) else @manpage.paragraph(item.value) end end |
#format_epilogue(command) ⇒ Object
82 83 84 |
# File 'lib/choosy/printing/manpage_printer.rb', line 82 def format_epilogue(command) @manpage.to_s end |
#format_name(command) ⇒ Object
50 51 52 53 54 55 |
# File 'lib/choosy/printing/manpage_printer.rb', line 50 def format_name(command) if command.summary @manpage.section_heading(@name) @manpage.text("#{command.name} - #{command.summary}") end end |
#format_option(option, formatted_option, indent) ⇒ Object
66 67 68 |
# File 'lib/choosy/printing/manpage_printer.rb', line 66 def format_option(option, formatted_option, indent) @manpage.term_paragraph(formatted_option, option.description, indent.length) end |
#format_prologue(command) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/choosy/printing/manpage_printer.rb', line 35 def format_prologue(command) @manpage.name = command_name(command) version_option = command.option_builders[Choosy::DSL::OptionBuilder::VERSION] if version_option && @manpage.version.nil? begin version_option.entity.validation_step.call(nil, nil) rescue Choosy::VersionCalled => e @manpage.version = e. end end format_name(command) format_synopsis(command) end |
#format_synopsis(command) ⇒ Object
57 58 59 60 61 62 63 64 |
# File 'lib/choosy/printing/manpage_printer.rb', line 57 def format_synopsis(command) @manpage.section_heading(@synopsis) @manpage.nofill do |man| usage_wrapped(command, '', columns).each do |line| man.text line end end end |
#print!(command) ⇒ Object
24 25 26 27 28 29 30 31 32 33 |
# File 'lib/choosy/printing/manpage_printer.rb', line 24 def print!(command) if command_exists?('groff') && pager? fix_termcap page format!(command), 'groff -t -e -W all -Tutf8 -mandoc' else # Fall back to a help printer if there is no pager help = HelpPrinter.new() help.print!(command) end end |