From f2ff67952fd965bb5751e68d3d51b1c5e668b657 Mon Sep 17 00:00:00 2001 From: dave Date: Tue, 14 Sep 2004 14:49:19 +0000 Subject: Add simple formatter to ri git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@6909 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- lib/rdoc/README | 5 ++- lib/rdoc/ri/ri_formatter.rb | 80 +++++++++++++++++++++++++++++++++++++-------- 2 files changed, 70 insertions(+), 15 deletions(-) (limited to 'lib/rdoc') diff --git a/lib/rdoc/README b/lib/rdoc/README index cfc99cb50f..5e90d792a2 100644 --- a/lib/rdoc/README +++ b/lib/rdoc/README @@ -164,7 +164,10 @@ Options are: include line numbers in the source code [--main _name_] - set the class, module, or file to appear on the index page + the class of module _name_ will appear on the index page. If you + want to set a particular file as a main page (a README, for + example) simply specifiy its name as the first on the command + line. [--merge] when generating _ri_ output, if classes being processed already diff --git a/lib/rdoc/ri/ri_formatter.rb b/lib/rdoc/ri/ri_formatter.rb index f86c3687e5..15c964618c 100644 --- a/lib/rdoc/ri/ri_formatter.rb +++ b/lib/rdoc/ri/ri_formatter.rb @@ -1,20 +1,6 @@ module RI class TextFormatter - def TextFormatter.list - "plain, html, bs, ansi" - end - - def TextFormatter.for(name) - case name - when /plain/i then TextFormatter - when /html/i then HtmlFormatter - when /bs/i then OverstrikeFormatter - when /ansi/i then AnsiFormatter - else nil - end - end - attr_reader :indent def initialize(options, indent) @@ -594,6 +580,72 @@ module RI end end + + ################################################## + + # This formatter reduces extra lines for a simpler output. + # It improves way output looks for tools like IRC bots. + + class SimpleFormatter < TextFormatter + + ###################################################################### + + # No extra blank lines + + def blankline + end + + ###################################################################### + + # Display labels only, no lines + + def draw_line(label=nil) + unless label.nil? then + bold_print(label) + puts + end + end + + ###################################################################### + + # Place heading level indicators inline with heading. + + def display_heading(text, level, indent) + case level + when 1 + puts "= " + text.upcase + when 2 + puts "-- " + text + else + print indent, text, "\n" + end + end + + end + + + # Finally, fill in the list of known formatters + + class TextFormatter + + FORMATTERS = { + "ansi" => AnsiFormatter, + "bs" => OverstrikeFormatter, + "html" => HtmlFormatter, + "plain" => TextFormatter, + "simple" => SimpleFormatter, + } + + def TextFormatter.list + FORMATTERS.keys.sort.join(", ") + end + + def TextFormatter.for(name) + FORMATTERS[name.downcase] + end + + end + end -- cgit v1.2.3