From 8d37cefaf8795fe80d457f101fb9678fc7f6adf6 Mon Sep 17 00:00:00 2001 From: drbrain Date: Sat, 19 Jan 2008 00:06:19 +0000 Subject: * lib/rdoc/markup: Remove ListBase and Line constants. * lib/rdoc/ri: Allow output IO to be specified. * test/rdoc/parser/test_parse_c.rb: Move up one level, fixed. * test/rdoc/parser/test_rdoc_markup_attribute_manager.rb: Renamed to match new class name, updated to match new classes. * test/rdoc/test_rdoc_ri_formatter.rb: Start of RI formatting tests. * test/rdoc/test_rdoc_ri_attribute_manager.rb: Start of RDoc::RI::AttributeManager tests. * test/rdoc/test_simple_markup.rb: Moved to match new class name. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@15120 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- lib/rdoc/markup.rb | 33 ++++--- lib/rdoc/markup/fragments.rb | 58 ++++++------ lib/rdoc/markup/lines.rb | 16 ++-- lib/rdoc/markup/to_flow.rb | 12 +-- lib/rdoc/markup/to_html.rb | 30 +++--- lib/rdoc/markup/to_latex.rb | 28 +++--- lib/rdoc/markup/to_test.rb | 49 ++++++++++ lib/rdoc/ri/display.rb | 2 +- lib/rdoc/ri/formatter.rb | 217 +++++++++++++++++++++---------------------- 9 files changed, 243 insertions(+), 202 deletions(-) create mode 100644 lib/rdoc/markup/to_test.rb (limited to 'lib') diff --git a/lib/rdoc/markup.rb b/lib/rdoc/markup.rb index 46654ebb58..8f978dc7bc 100644 --- a/lib/rdoc/markup.rb +++ b/lib/rdoc/markup.rb @@ -159,7 +159,6 @@ require 'rdoc' # #-- # Author:: Dave Thomas, dave@pragmaticprogrammer.com -# Version:: 0.0 # License:: Ruby license class RDoc::Markup @@ -256,7 +255,7 @@ class RDoc::Markup while line = @lines.next if line.isBlank? - line.stamp(Line::BLANK, level) + line.stamp :BLANK, level next end @@ -282,7 +281,7 @@ class RDoc::Markup # if /^(---+)\s*$/ =~ active_line - line.stamp(Line::RULE, level, $1.length-2) + line.stamp :RULE, level, $1.length-2 next end @@ -296,14 +295,14 @@ class RDoc::Markup prefix_length = prefix.length flag = case prefix - when "*","-" then ListBase::BULLET - when /^\d/ then ListBase::NUMBER - when /^[A-Z]/ then ListBase::UPPERALPHA - when /^[a-z]/ then ListBase::LOWERALPHA + when "*","-" then :BULLET + when /^\d/ then :NUMBER + when /^[A-Z]/ then :UPPERALPHA + when /^[a-z]/ then :LOWERALPHA else raise "Invalid List Type: #{self.inspect}" end - line.stamp(Line::LIST, level+1, prefix, flag) + line.stamp :LIST, level+1, prefix, flag text[margin, prefix_length] = " " * prefix_length assign_types_to_lines(offset, level + 1) next @@ -328,7 +327,7 @@ class RDoc::Markup if active_line[0] == ?= and active_line =~ /^(=+)\s*(.*)/ prefix_length = $1.length prefix_length = 6 if prefix_length > 6 - line.stamp(Line::HEADING, 0, prefix_length) + line.stamp :HEADING, 0, prefix_length line.strip_leading(margin + prefix_length) next end @@ -338,9 +337,9 @@ class RDoc::Markup if active_line[0] == SPACE line.strip_leading(margin) if margin > 0 - line.stamp(Line::VERBATIM, level) + line.stamp :VERBATIM, level else - line.stamp(Line::PARAGRAPH, level) + line.stamp :PARAGRAPH, level end end end @@ -369,10 +368,10 @@ class RDoc::Markup flag = nil case prefix when /^\[/ - flag = ListBase::LABELED + flag = :LABELED prefix = prefix[1, prefix.length-2] when /:$/ - flag = ListBase::NOTE + flag = :NOTE prefix.chop! else raise "Invalid List Type: #{self.inspect}" end @@ -403,7 +402,7 @@ class RDoc::Markup end end - line.stamp(Line::LIST, level+1, prefix, flag) + line.stamp :LIST, level+1, prefix, flag text[margin, prefix_length] = " " * prefix_length assign_types_to_lines(offset, level + 1) return true @@ -431,12 +430,12 @@ class RDoc::Markup else group = block.fragment_for(line) block.add(group) - if line.type == Line::LIST - wantedType = Line::PARAGRAPH + if line.type == :LIST + wantedType = :PARAGRAPH else wantedType = line.type end - wantedLevel = line.type == Line::HEADING ? line.param : line.level + wantedLevel = line.type == :HEADING ? line.param : line.level end end diff --git a/lib/rdoc/markup/fragments.rb b/lib/rdoc/markup/fragments.rb index 2dd3614fc1..39b63cae22 100644 --- a/lib/rdoc/markup/fragments.rb +++ b/lib/rdoc/markup/fragments.rb @@ -11,6 +11,22 @@ class RDoc::Markup attr_reader :level, :param, :txt attr_accessor :type + ###### + # This is a simple factory system that lets us associate fragement + # types (a string) with a subclass of fragment + + TYPE_MAP = {} + + def self.type_name(name) + TYPE_MAP[name] = self + end + + def self.for(line) + klass = TYPE_MAP[line.type] || + raise("Unknown line type: '#{line.type.inspect}:' '#{line.text}'") + return klass.new(line.level, line.param, line.flag, line.text) + end + def initialize(level, param, type, txt) @level = level @param = param @@ -28,21 +44,6 @@ class RDoc::Markup "L#@level: #{self.class.name.split('::')[-1]}\n#@txt" end - ###### - # This is a simple factory system that lets us associate fragement - # types (a string) with a subclass of fragment - - TYPE_MAP = {} - - def Fragment.type_name(name) - TYPE_MAP[name] = self - end - - def Fragment.for(line) - klass = TYPE_MAP[line.type] || - raise("Unknown line type: '#{line.type.inspect}:' '#{line.text}'") - return klass.new(line.level, line.param, line.flag, line.text) - end end ## @@ -50,15 +51,15 @@ class RDoc::Markup # newlines when we're created, and have them put back on output. class Paragraph < Fragment - type_name Line::PARAGRAPH + type_name :PARAGRAPH end class BlankLine < Paragraph - type_name Line::BLANK + type_name :BLANK end class Heading < Paragraph - type_name Line::HEADING + type_name :HEADING def head_level @param.to_i @@ -69,17 +70,18 @@ class RDoc::Markup # A List is a fragment with some kind of label class ListBase < Paragraph - # List types - BULLET = :BULLET - NUMBER = :NUMBER - UPPERALPHA = :UPPERALPHA - LOWERALPHA = :LOWERALPHA - LABELED = :LABELED - NOTE = :NOTE + LIST_TYPES = [ + :BULLET, + :NUMBER, + :UPPERALPHA, + :LOWERALPHA, + :LABELED, + :NOTE, + ] end class ListItem < ListBase - type_name Line::LIST + type_name :LIST # def label # am = AttributeManager.new(@param) @@ -103,7 +105,7 @@ class RDoc::Markup # Verbatim code contains lines that don't get wrapped. class Verbatim < Fragment - type_name Line::VERBATIM + type_name :VERBATIM def add_text(txt) @txt << txt.chomp << "\n" @@ -115,7 +117,7 @@ class RDoc::Markup # A horizontal rule class Rule < Fragment - type_name Line::RULE + type_name :RULE end ## diff --git a/lib/rdoc/markup/lines.rb b/lib/rdoc/markup/lines.rb index 5fb5bde993..985304c225 100644 --- a/lib/rdoc/markup/lines.rb +++ b/lib/rdoc/markup/lines.rb @@ -8,12 +8,14 @@ class RDoc::Markup class Line INFINITY = 9999 - BLANK = :BLANK - HEADING = :HEADING - LIST = :LIST - RULE = :RULE - PARAGRAPH = :PARAGRAPH - VERBATIM = :VERBATIM + LINE_TYPES = [ + :BLANK, + :HEADING, + :LIST, + :PARAGRAPH, + :RULE, + :VERBATIM, + ] # line type attr_accessor :type @@ -132,7 +134,7 @@ class RDoc::Markup def normalize margin = @lines.collect{|l| l.leading_spaces}.min - margin = 0 if margin == Line::INFINITY + margin = 0 if margin == :INFINITY @lines.each {|line| line.strip_leading(margin) } if margin > 0 end diff --git a/lib/rdoc/markup/to_flow.rb b/lib/rdoc/markup/to_flow.rb index 58ae52be24..cb7da5fa88 100644 --- a/lib/rdoc/markup/to_flow.rb +++ b/lib/rdoc/markup/to_flow.rb @@ -24,12 +24,12 @@ class RDoc::Markup class ToFlow LIST_TYPE_TO_HTML = { - RDoc::Markup::ListBase::BULLET => [ "" ], - RDoc::Markup::ListBase::NUMBER => [ "
    ", "
" ], - RDoc::Markup::ListBase::UPPERALPHA => [ "
    ", "
" ], - RDoc::Markup::ListBase::LOWERALPHA => [ "
    ", "
" ], - RDoc::Markup::ListBase::LABELED => [ "
", "
" ], - RDoc::Markup::ListBase::NOTE => [ "", "
" ], + :BULLET => [ "" ], + :NUMBER => [ "
    ", "
" ], + :UPPERALPHA => [ "
    ", "
" ], + :LOWERALPHA => [ "
    ", "
" ], + :LABELED => [ "
", "
" ], + :NOTE => [ "", "
" ], } InlineTag = Struct.new(:bit, :on, :off) diff --git a/lib/rdoc/markup/to_html.rb b/lib/rdoc/markup/to_html.rb index 98259cfd16..0238d5ae67 100644 --- a/lib/rdoc/markup/to_html.rb +++ b/lib/rdoc/markup/to_html.rb @@ -6,12 +6,12 @@ require 'cgi' class RDoc::Markup::ToHtml LIST_TYPE_TO_HTML = { - RDoc::Markup::ListBase::BULLET => [ "" ], - RDoc::Markup::ListBase::NUMBER => [ "
    ", "
" ], - RDoc::Markup::ListBase::UPPERALPHA => [ "
    ", "
" ], - RDoc::Markup::ListBase::LOWERALPHA => [ "
    ", "
" ], - RDoc::Markup::ListBase::LABELED => [ "
", "
" ], - RDoc::Markup::ListBase::NOTE => [ "", "
" ], + :BULLET => [ "" ], + :NUMBER => [ "
    ", "
" ], + :UPPERALPHA => [ "
    ", "
" ], + :LOWERALPHA => [ "
    ", "
" ], + :LABELED => [ "
", "
" ], + :NOTE => [ "", "
" ], } InlineTag = Struct.new(:bit, :on, :off) @@ -241,22 +241,22 @@ class RDoc::Markup::ToHtml def list_item_start(am, fragment) case fragment.type - when RDoc::Markup::ListBase::BULLET, RDoc::Markup::ListBase::NUMBER then + when :BULLET, :NUMBER then annotate("
  • ") - when RDoc::Markup::ListBase::UPPERALPHA then + when :UPPERALPHA then annotate("
  • ") - when RDoc::Markup::ListBase::LOWERALPHA then + when :LOWERALPHA then annotate("
  • ") - when RDoc::Markup::ListBase::LABELED then + when :LABELED then annotate("
    ") + convert_flow(am.flow(fragment.param)) + annotate("
    ") + annotate("
    ") - when RDoc::Markup::ListBase::NOTE then + when :NOTE then annotate("") + annotate("") + convert_flow(am.flow(fragment.param)) + @@ -269,13 +269,11 @@ class RDoc::Markup::ToHtml def list_end_for(fragment_type) case fragment_type - when RDoc::Markup::ListBase::BULLET, RDoc::Markup::ListBase::NUMBER, - RDoc::Markup::ListBase::UPPERALPHA, - RDoc::Markup::ListBase::LOWERALPHA then + when :BULLET, :NUMBER, :UPPERALPHA, :LOWERALPHA then "
  • " - when RDoc::Markup::ListBase::LABELED then + when :LABELED then "" - when RDoc::Markup::ListBase::NOTE then + when :NOTE then "" else raise "Invalid list type" diff --git a/lib/rdoc/markup/to_latex.rb b/lib/rdoc/markup/to_latex.rb index 7389ba112f..8b7e33719b 100644 --- a/lib/rdoc/markup/to_latex.rb +++ b/lib/rdoc/markup/to_latex.rb @@ -29,12 +29,12 @@ class RDoc::Markup::ToLaTeX end LIST_TYPE_TO_LATEX = { - RDoc::Markup::ListBase::BULLET => [ l("\\begin{itemize}"), l("\\end{itemize}") ], - RDoc::Markup::ListBase::NUMBER => [ l("\\begin{enumerate}"), l("\\end{enumerate}"), "\\arabic" ], - RDoc::Markup::ListBase::UPPERALPHA => [ l("\\begin{enumerate}"), l("\\end{enumerate}"), "\\Alph" ], - RDoc::Markup::ListBase::LOWERALPHA => [ l("\\begin{enumerate}"), l("\\end{enumerate}"), "\\alph" ], - RDoc::Markup::ListBase::LABELED => [ l("\\begin{description}"), l("\\end{description}") ], - RDoc::Markup::ListBase::NOTE => [ + :BULLET => [ l("\\begin{itemize}"), l("\\end{itemize}") ], + :NUMBER => [ l("\\begin{enumerate}"), l("\\end{enumerate}"), "\\arabic" ], + :UPPERALPHA => [ l("\\begin{enumerate}"), l("\\end{enumerate}"), "\\Alph" ], + :LOWERALPHA => [ l("\\begin{enumerate}"), l("\\end{enumerate}"), "\\alph" ], + :LABELED => [ l("\\begin{description}"), l("\\end{description}") ], + :NOTE => [ l("\\begin{tabularx}{\\linewidth}{@{} l X @{}}"), l("\\end{tabularx}") ], } @@ -299,15 +299,13 @@ class RDoc::Markup::ToLaTeX def list_item_start(am, fragment) case fragment.type - when RDoc::Markup::ListBase::BULLET, RDoc::Markup::ListBase::NUMBER, - RDoc::Markup::ListBase::UPPERALPHA, - RDoc::Markup::ListBase::LOWERALPHA then + when :BULLET, :NUMBER, :UPPERALPHA, :LOWERALPHA then "\\item " - when RDoc::Markup::ListBase::LABELED then + when :LABELED then "\\item[" + convert_flow(am.flow(fragment.param)) + "] " - when RDoc::Markup::ListBase::NOTE then + when :NOTE then convert_flow(am.flow(fragment.param)) + " & " else raise "Invalid list type" @@ -316,13 +314,9 @@ class RDoc::Markup::ToLaTeX def list_end_for(fragment_type) case fragment_type - when RDoc::Markup::ListBase::BULLET, - RDoc::Markup::ListBase::NUMBER, - RDoc::Markup::ListBase::UPPERALPHA, - RDoc::Markup::ListBase::LOWERALPHA, - RDoc::Markup::ListBase::LABELED then + when :BULLET, :NUMBER, :UPPERALPHA, :LOWERALPHA, :LABELED then "" - when RDoc::Markup::ListBase::NOTE + when :NOTE "\\\\\n" else raise "Invalid list type" diff --git a/lib/rdoc/markup/to_test.rb b/lib/rdoc/markup/to_test.rb new file mode 100644 index 0000000000..eb183e5ba4 --- /dev/null +++ b/lib/rdoc/markup/to_test.rb @@ -0,0 +1,49 @@ +require 'rdoc/markup' + +## +# This Markup outputter is used for testing purposes. + +class RDoc::Markup::ToTest + + def start_accepting + @res = [] + end + + def end_accepting + @res + end + + def accept_paragraph(am, fragment) + @res << fragment.to_s + end + + def accept_verbatim(am, fragment) + @res << fragment.to_s + end + + def accept_list_start(am, fragment) + @res << fragment.to_s + end + + def accept_list_end(am, fragment) + @res << fragment.to_s + end + + def accept_list_item(am, fragment) + @res << fragment.to_s + end + + def accept_blank_line(am, fragment) + @res << fragment.to_s + end + + def accept_heading(am, fragment) + @res << fragment.to_s + end + + def accept_rule(am, fragment) + @res << fragment.to_s + end + +end + diff --git a/lib/rdoc/ri/display.rb b/lib/rdoc/ri/display.rb index 1aa66b7ac5..d5ac8c2f01 100644 --- a/lib/rdoc/ri/display.rb +++ b/lib/rdoc/ri/display.rb @@ -34,7 +34,7 @@ class RDoc::RI::DefaultDisplay def initialize(formatter, width, use_stdout) @use_stdout = use_stdout - @formatter = formatter.new width, " " + @formatter = formatter.new $stdout, width, " " end def display_method_info(method) diff --git a/lib/rdoc/ri/formatter.rb b/lib/rdoc/ri/formatter.rb index 2b0db322e0..a525fa8f1c 100644 --- a/lib/rdoc/ri/formatter.rb +++ b/lib/rdoc/ri/formatter.rb @@ -1,27 +1,49 @@ require 'rdoc/ri' +require 'rdoc/markup' class RDoc::RI::Formatter attr_reader :indent - def initialize(width, indent) - @width = width - @indent = indent + FORMATTERS = { } + + def self.for(name) + FORMATTERS[name.downcase] + end + + def self.list + FORMATTERS.keys.sort.join ", " + end + + def initialize(output, width, indent) + @output = output + @width = width + @indent = indent end def draw_line(label=nil) len = @width - len -= (label.size+1) if label - print "-"*len - if label - print(" ") - bold_print(label) + len -= (label.size + 1) if label + + if len > 0 then + @output.print '-' * len + if label + @output.print ' ' + bold_print label + end + + @output.puts + else + @output.print '-' * @width + @output.puts + + @output.puts label end - puts end - def wrap(txt, prefix=@indent, linelen=@width) + def wrap(txt, prefix=@indent, linelen=@width) return unless txt && !txt.empty? + work = conv_markup(txt) textLen = linelen - prefix.length patt = Regexp.new("^(.{0,#{textLen}})[ \n]") @@ -38,11 +60,11 @@ class RDoc::RI::Formatter end end res << work if work.length.nonzero? - puts(prefix + res.join("\n" + next_prefix)) + @output.puts(prefix + res.join("\n" + next_prefix)) end def blankline - puts + @output.puts end ## @@ -53,11 +75,11 @@ class RDoc::RI::Formatter end def bold_print(txt) - print txt + @output.print txt end def raw_print_line(txt) - puts txt + @output.puts txt end ## @@ -69,7 +91,6 @@ class RDoc::RI::Formatter gsub(/</, '<'). gsub(/"/, '"'). gsub(/&/, '&') - end ## @@ -78,25 +99,22 @@ class RDoc::RI::Formatter def conv_markup(txt) txt. gsub(%r{(.*?)}) { "+#$1+" } . - gsub(%r{(.*?)}) { "+#$1+" } . - gsub(%r{(.*?)}) { "*#$1*" } . - gsub(%r{(.*?)}) { "_#$1_" } + gsub(%r{(.*?)}) { "+#$1+" } . + gsub(%r{(.*?)}) { "*#$1*" } . + gsub(%r{(.*?)}) { "_#$1_" } end def display_list(list) case list.type - - when RDoc::Markup::ListBase::BULLET + when :BULLET prefixer = proc { |ignored| @indent + "* " } - when RDoc::Markup::ListBase::NUMBER, - RDoc::Markup::ListBase::UPPERALPHA, - RDoc::Markup::ListBase::LOWERALPHA + when :NUMBER, :UPPERALPHA, :LOWERALPHA then start = case list.type - when RDoc::Markup::ListBase::NUMBER then 1 - when RDoc::Markup::ListBase::UPPERALPHA then 'A' - when RDoc::Markup::ListBase::LOWERALPHA then 'a' + when :NUMBER then 1 + when :UPPERALPHA then 'A' + when :LOWERALPHA then 'a' end prefixer = proc do |ignored| res = @indent + "#{start}.".ljust(4) @@ -104,12 +122,12 @@ class RDoc::RI::Formatter res end - when RDoc::Markup::ListBase::LABELED + when :LABELED then prefixer = proc do |li| li.label end - when RDoc::Markup::ListBase::NOTE + when :NOTE then longest = 0 list.contents.each do |item| if item.kind_of?(RDoc::Markup::Flow::LI) && item.label.length > longest @@ -122,8 +140,7 @@ class RDoc::RI::Formatter end else - fail "unknown list type" - + raise ArgumentError, "unknown list type #{list.type}" end list.contents.each do |item| @@ -161,7 +178,7 @@ class RDoc::RI::Formatter def display_verbatim_flow_item(item, prefix=@indent) item.body.split(/\n/).each do |line| - print @indent, conv_html(line), "\n" + @output.print @indent, conv_html(line), "\n" end blankline end @@ -171,19 +188,19 @@ class RDoc::RI::Formatter case level when 1 ul = "=" * text.length - puts - puts text.upcase - puts ul + @output.puts + @output.puts text.upcase + @output.puts ul # puts when 2 ul = "-" * text.length - puts - puts text - puts ul + @output.puts + @output.puts text + @output.puts ul # puts else - print indent, text, "\n" + @output.print indent, text, "\n" end end @@ -274,11 +291,11 @@ class RDoc::RI::AttributeFormatter < RDoc::RI::Formatter end ## - # Overrides base class. Looks for ... etc sequences - # and generates an array of AttrChars. This array is then used - # as the basis for the split + # Overrides base class. Looks for ... etc sequences and generates + # an array of AttrChars. This array is then used as the basis for the + # split. - def wrap(txt, prefix=@indent, linelen=@width) + def wrap(txt, prefix=@indent, linelen=@width) return unless txt && !txt.empty? txt = add_attributes_to(txt) @@ -303,15 +320,15 @@ class RDoc::RI::AttributeFormatter < RDoc::RI::Formatter protected def write_attribute_text(prefix, line) - print prefix + @output.print prefix line.each do |achar| - print achar.char + @output.print achar.char end - puts + @output.puts end def bold_print(txt) - print txt + @output.print txt end private @@ -342,18 +359,18 @@ class RDoc::RI::OverstrikeFormatter < RDoc::RI::AttributeFormatter BS = "\C-h" def write_attribute_text(prefix, line) - print prefix + @output.print prefix line.each do |achar| attr = achar.attr if (attr & (ITALIC+CODE)) != 0 - print "_", BS + @output.print "_", BS end if (attr & BOLD) != 0 - print achar.char, BS + @output.print achar.char, BS end - print achar.char + @output.print achar.char end - puts + @output.puts end ## @@ -361,7 +378,7 @@ class RDoc::RI::OverstrikeFormatter < RDoc::RI::AttributeFormatter def bold_print(text) text.split(//).each do |ch| - print ch, BS, ch + @output.print ch, BS, ch end end @@ -374,12 +391,12 @@ end class RDoc::RI::AnsiFormatter < RDoc::RI::AttributeFormatter def initialize(*args) - print "\033[0m" super + @output.print "\033[0m" end def write_attribute_text(prefix, line) - print prefix + @output.print prefix curr_attr = 0 line.each do |achar| attr = achar.attr @@ -387,14 +404,14 @@ class RDoc::RI::AnsiFormatter < RDoc::RI::AttributeFormatter update_attributes(achar.attr) curr_attr = achar.attr end - print achar.char + @output.print achar.char end update_attributes(0) unless curr_attr.zero? - puts + @output.puts end def bold_print(txt) - print "\033[1m#{txt}\033[m" + @output.print "\033[1m#{txt}\033[m" end HEADINGS = { @@ -406,10 +423,10 @@ class RDoc::RI::AnsiFormatter < RDoc::RI::AttributeFormatter def display_heading(text, level, indent) level = 3 if level > 3 heading = HEADINGS[level] - print indent - print heading[0] - print strip_attributes(text) - puts heading[1] + @output.print indent + @output.print heading[0] + @output.print strip_attributes(text) + @output.puts heading[1] end private @@ -427,7 +444,7 @@ class RDoc::RI::AnsiFormatter < RDoc::RI::AttributeFormatter str << ATTR_MAP[quality] end end - print str, "m" + @output.print str, "m" end end @@ -445,7 +462,7 @@ class RDoc::RI::HtmlFormatter < RDoc::RI::AttributeFormatter update_attributes(curr_attr, achar.attr) curr_attr = achar.attr end - print(escape(achar.char)) + @output.print(escape(achar.char)) end update_attributes(curr_attr, 0) unless curr_attr.zero? end @@ -454,7 +471,7 @@ class RDoc::RI::HtmlFormatter < RDoc::RI::AttributeFormatter if label != nil bold_print(label) end - puts("
    ") + @output.puts("
    ") end def bold_print(txt) @@ -462,38 +479,36 @@ class RDoc::RI::HtmlFormatter < RDoc::RI::AttributeFormatter end def blankline() - puts("

    ") + @output.puts("

    ") end def break_to_newline - puts("
    ") + @output.puts("
    ") end def display_heading(text, level, indent) level = 4 if level > 4 tag("h#{level}") { text } - puts + @output.puts end def display_list(list) case list.type - when RDoc::Markup::ListBase::BULLET + when :BULLET then list_type = "ul" prefixer = proc { |ignored| "

  • " } - when RDoc::Markup::ListBase::NUMBER, - RDoc::Markup::ListBase::UPPERALPHA, - RDoc::Markup::ListBase::LOWERALPHA + when :NUMBER, :UPPERALPHA, :LOWERALPHA then list_type = "ol" prefixer = proc { |ignored| "
  • " } - when RDoc::Markup::ListBase::LABELED + when :LABELED then list_type = "dl" prefixer = proc do |li| "
    " + escape(li.label) + "
    " end - when RDoc::Markup::ListBase::NOTE + when :NOTE then list_type = "table" prefixer = proc do |li| %{#{li.label.gsub(/ /, ' ')}} @@ -502,25 +517,25 @@ class RDoc::RI::HtmlFormatter < RDoc::RI::AttributeFormatter fail "unknown list type" end - print "<#{list_type}>" + @output.print "<#{list_type}>" list.contents.each do |item| if item.kind_of? RDoc::Markup::Flow::LI prefix = prefixer.call(item) - print prefix + @output.print prefix display_flow_item(item, prefix) else display_flow_item(item) end end - print "" + @output.print "" end def display_verbatim_flow_item(item, prefix=@indent) - print("
    ")
    +    @output.print("
    ")
         item.body.split(/\n/).each do |line|
    -      puts conv_html(line)
    +      @output.puts conv_html(line)
         end
    -    puts("
    ") + @output.puts("
    ") end private @@ -547,13 +562,13 @@ class RDoc::RI::HtmlFormatter < RDoc::RI::AttributeFormatter str << "<" << ATTR_MAP[quality] end end - print str + @output.print str end def tag(code) - print("<#{code}>") - print(yield) - print("") + @output.print("<#{code}>") + @output.print(yield) + @output.print("") end def escape(str) @@ -584,7 +599,7 @@ class RDoc::RI::SimpleFormatter < RDoc::RI::Formatter def draw_line(label=nil) unless label.nil? then bold_print(label) - puts + @output.puts end end @@ -595,36 +610,18 @@ class RDoc::RI::SimpleFormatter < RDoc::RI::Formatter text = strip_attributes(text) case level when 1 - puts "= " + text.upcase + @output.puts "= " + text.upcase when 2 - puts "-- " + text + @output.puts "-- " + text else - print indent, text, "\n" + @output.print indent, text, "\n" end end end -## -# Finally, fill in the list of known formatters - -class RDoc::RI::Formatter - - FORMATTERS = { - "plain" => RDoc::RI::Formatter, - "simple" => RDoc::RI::SimpleFormatter, - "bs" => RDoc::RI::OverstrikeFormatter, - "ansi" => RDoc::RI::AnsiFormatter, - "html" => RDoc::RI::HtmlFormatter, - } - - def self.list - FORMATTERS.keys.sort.join(", ") - end - - def self.for(name) - FORMATTERS[name.downcase] - end - -end - +RDoc::RI::Formatter::FORMATTERS['plain'] = RDoc::RI::Formatter +RDoc::RI::Formatter::FORMATTERS['simple'] = RDoc::RI::SimpleFormatter +RDoc::RI::Formatter::FORMATTERS['bs'] = RDoc::RI::OverstrikeFormatter +RDoc::RI::Formatter::FORMATTERS['ansi'] = RDoc::RI::AnsiFormatter +RDoc::RI::Formatter::FORMATTERS['html'] = RDoc::RI::HtmlFormatter -- cgit v1.2.3