aboutsummaryrefslogtreecommitdiffstats
path: root/lib/rdoc/ri
diff options
context:
space:
mode:
authordave <dave@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2004-09-14 14:49:19 +0000
committerdave <dave@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2004-09-14 14:49:19 +0000
commit0964c4781652bcdfcf940017722164d2effc69ee (patch)
tree41697e222662b668abbb8355cfa504147d659401 /lib/rdoc/ri
parentd4e341c43d435c42a9da85beb1c999b721c9dffb (diff)
downloadruby-0964c4781652bcdfcf940017722164d2effc69ee.tar.gz
Add simple formatter to ri
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6909 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/rdoc/ri')
-rw-r--r--lib/rdoc/ri/ri_formatter.rb80
1 files changed, 66 insertions, 14 deletions
diff --git a/lib/rdoc/ri/ri_formatter.rb b/lib/rdoc/ri/ri_formatter.rb
index 63c12aaced..25bd3000f9 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