summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog18
-rw-r--r--lib/rdoc/markup.rb33
-rw-r--r--lib/rdoc/markup/fragments.rb58
-rw-r--r--lib/rdoc/markup/lines.rb16
-rw-r--r--lib/rdoc/markup/to_flow.rb12
-rw-r--r--lib/rdoc/markup/to_html.rb30
-rw-r--r--lib/rdoc/markup/to_latex.rb28
-rw-r--r--lib/rdoc/markup/to_test.rb49
-rw-r--r--lib/rdoc/ri/display.rb2
-rw-r--r--lib/rdoc/ri/formatter.rb217
-rw-r--r--test/rdoc/test_rdoc_c_parser.rb (renamed from test/rdoc/parsers/test_parse_c.rb)2
-rw-r--r--test/rdoc/test_rdoc_markup.rb (renamed from test/rdoc/test_simple_markup.rb)61
-rw-r--r--test/rdoc/test_rdoc_markup_attribute_manager.rb (renamed from test/rdoc/test_simple_markup_attribute_manager.rb)12
-rw-r--r--test/rdoc/test_rdoc_ri_attribute_formatter.rb42
-rw-r--r--test/rdoc/test_rdoc_ri_formatter.rb124
15 files changed, 443 insertions, 261 deletions
diff --git a/ChangeLog b/ChangeLog
index 2c9948600c..8c313e819f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,21 @@
+Sat Jan 19 08:58:47 2008 Eric Hodel <drbrain@segment7.net>
+
+ * 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.
+
Sat Jan 19 08:35:36 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
* parse.y (parser_prepare): get encoding from the first line.
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 => [ "<ul>", "</ul>" ],
- RDoc::Markup::ListBase::NUMBER => [ "<ol>", "</ol>" ],
- RDoc::Markup::ListBase::UPPERALPHA => [ "<ol>", "</ol>" ],
- RDoc::Markup::ListBase::LOWERALPHA => [ "<ol>", "</ol>" ],
- RDoc::Markup::ListBase::LABELED => [ "<dl>", "</dl>" ],
- RDoc::Markup::ListBase::NOTE => [ "<table>", "</table>" ],
+ :BULLET => [ "<ul>", "</ul>" ],
+ :NUMBER => [ "<ol>", "</ol>" ],
+ :UPPERALPHA => [ "<ol>", "</ol>" ],
+ :LOWERALPHA => [ "<ol>", "</ol>" ],
+ :LABELED => [ "<dl>", "</dl>" ],
+ :NOTE => [ "<table>", "</table>" ],
}
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 => [ "<ul>", "</ul>" ],
- RDoc::Markup::ListBase::NUMBER => [ "<ol>", "</ol>" ],
- RDoc::Markup::ListBase::UPPERALPHA => [ "<ol>", "</ol>" ],
- RDoc::Markup::ListBase::LOWERALPHA => [ "<ol>", "</ol>" ],
- RDoc::Markup::ListBase::LABELED => [ "<dl>", "</dl>" ],
- RDoc::Markup::ListBase::NOTE => [ "<table>", "</table>" ],
+ :BULLET => [ "<ul>", "</ul>" ],
+ :NUMBER => [ "<ol>", "</ol>" ],
+ :UPPERALPHA => [ "<ol>", "</ol>" ],
+ :LOWERALPHA => [ "<ol>", "</ol>" ],
+ :LABELED => [ "<dl>", "</dl>" ],
+ :NOTE => [ "<table>", "</table>" ],
}
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("<li>")
- when RDoc::Markup::ListBase::UPPERALPHA then
+ when :UPPERALPHA then
annotate("<li type=\"A\">")
- when RDoc::Markup::ListBase::LOWERALPHA then
+ when :LOWERALPHA then
annotate("<li type=\"a\">")
- when RDoc::Markup::ListBase::LABELED then
+ when :LABELED then
annotate("<dt>") +
convert_flow(am.flow(fragment.param)) +
annotate("</dt>") +
annotate("<dd>")
- when RDoc::Markup::ListBase::NOTE then
+ when :NOTE then
annotate("<tr>") +
annotate("<td valign=\"top\">") +
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
"</li>"
- when RDoc::Markup::ListBase::LABELED then
+ when :LABELED then
"</dd>"
- when RDoc::Markup::ListBase::NOTE then
+ when :NOTE then
"</td></tr>"
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(/&lt;/, '<').
gsub(/&quot;/, '"').
gsub(/&amp;/, '&')
-
end
##
@@ -78,25 +99,22 @@ class RDoc::RI::Formatter
def conv_markup(txt)
txt.
gsub(%r{<tt>(.*?)</tt>}) { "+#$1+" } .
- gsub(%r{<code>(.*?)</code>}) { "+#$1+" } .
- gsub(%r{<b>(.*?)</b>}) { "*#$1*" } .
- gsub(%r{<em>(.*?)</em>}) { "_#$1_" }
+ gsub(%r{<code>(.*?)</code>}) { "+#$1+" } .
+ gsub(%r{<b>(.*?)</b>}) { "*#$1*" } .
+ gsub(%r{<em>(.*?)</em>}) { "_#$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 <tt>...</tt> etc sequences
- # and generates an array of AttrChars. This array is then used
- # as the basis for the split
+ # Overrides base class. Looks for <tt>...</tt> 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("<hr>")
+ @output.puts("<hr>")
end
def bold_print(txt)
@@ -462,38 +479,36 @@ class RDoc::RI::HtmlFormatter < RDoc::RI::AttributeFormatter
end
def blankline()
- puts("<p>")
+ @output.puts("<p>")
end
def break_to_newline
- puts("<br>")
+ @output.puts("<br>")
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| "<li>" }
- when RDoc::Markup::ListBase::NUMBER,
- RDoc::Markup::ListBase::UPPERALPHA,
- RDoc::Markup::ListBase::LOWERALPHA
+ when :NUMBER, :UPPERALPHA, :LOWERALPHA then
list_type = "ol"
prefixer = proc { |ignored| "<li>" }
- when RDoc::Markup::ListBase::LABELED
+ when :LABELED then
list_type = "dl"
prefixer = proc do |li|
"<dt><b>" + escape(li.label) + "</b><dd>"
end
- when RDoc::Markup::ListBase::NOTE
+ when :NOTE then
list_type = "table"
prefixer = proc do |li|
%{<tr valign="top"><td>#{li.label.gsub(/ /, '&nbsp;')}</td><td>}
@@ -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 "</#{list_type}>"
+ @output.print "</#{list_type}>"
end
def display_verbatim_flow_item(item, prefix=@indent)
- print("<pre>")
+ @output.print("<pre>")
item.body.split(/\n/).each do |line|
- puts conv_html(line)
+ @output.puts conv_html(line)
end
- puts("</pre>")
+ @output.puts("</pre>")
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("</#{code}>")
+ @output.print("<#{code}>")
+ @output.print(yield)
+ @output.print("</#{code}>")
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
diff --git a/test/rdoc/parsers/test_parse_c.rb b/test/rdoc/test_rdoc_c_parser.rb
index 6157a9e1d4..ef686daed4 100644
--- a/test/rdoc/parsers/test_parse_c.rb
+++ b/test/rdoc/test_rdoc_c_parser.rb
@@ -17,7 +17,7 @@ class TestRdocC_Parser < Test::Unit::TestCase
@top_level = RDoc::TopLevel.new filename
@fn = filename
- @options = Options.instance
+ @options = RDoc::Options.new Hash.new
@stats = RDoc::Stats.new
@progress = StringIO.new
diff --git a/test/rdoc/test_simple_markup.rb b/test/rdoc/test_rdoc_markup.rb
index 89d66c9eb5..3d68511a7b 100644
--- a/test/rdoc/test_simple_markup.rb
+++ b/test/rdoc/test_rdoc_markup.rb
@@ -1,62 +1,19 @@
require 'test/unit'
-require 'rdoc/markup/simple_markup'
+require 'rdoc/markup'
+require 'rdoc/markup/to_test'
-class TestSimpleMarkup < Test::Unit::TestCase
-
- class MockOutput
-
- 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
+class TestRDocMarkup < Test::Unit::TestCase
def basic_conv(str)
- sm = SM::SimpleMarkup.new
- mock = MockOutput.new
+ sm = RDoc::Markup.new
+ mock = RDoc::Markup::ToTest.new
sm.convert(str, mock)
sm.content
end
def line_groups(str, expected)
- p = SM::SimpleMarkup.new
- mock = MockOutput.new
+ p = RDoc::Markup.new
+ mock = RDoc::Markup::ToTest.new
block = p.convert(str, mock)
@@ -72,8 +29,8 @@ class TestSimpleMarkup < Test::Unit::TestCase
end
def line_types(str, expected)
- p = SM::SimpleMarkup.new
- mock = MockOutput.new
+ p = RDoc::Markup.new
+ mock = RDoc::Markup::ToTest.new
p.convert(str, mock)
assert_equal(expected, p.get_line_types.map{|type| type.to_s[0,1]}.join(''))
end
diff --git a/test/rdoc/test_simple_markup_attribute_manager.rb b/test/rdoc/test_rdoc_markup_attribute_manager.rb
index c37d821b7d..0f3bb3a449 100644
--- a/test/rdoc/test_simple_markup_attribute_manager.rb
+++ b/test/rdoc/test_rdoc_markup_attribute_manager.rb
@@ -1,10 +1,10 @@
require "test/unit"
-require "rdoc/markup/simple_markup/inline"
+require "rdoc/markup/inline"
-class TestSimpleMarkupAttributeManager < Test::Unit::TestCase
+class TestRDocMarkupAttributeManager < Test::Unit::TestCase
def setup
- @am = SM::AttributeManager.new
+ @am = RDoc::Markup::AttributeManager.new
@bold_on = @am.changed_attribute_by_name([], [:BOLD])
@bold_off = @am.changed_attribute_by_name([:BOLD], [])
@@ -28,11 +28,11 @@ class TestSimpleMarkupAttributeManager < Test::Unit::TestCase
end
def crossref(text)
- crossref_bitmap = SM::Attribute.bitmap_for(:_SPECIAL_) |
- SM::Attribute.bitmap_for(:CROSSREF)
+ crossref_bitmap = RDoc::Markup::Attribute.bitmap_for(:_SPECIAL_) |
+ RDoc::Markup::Attribute.bitmap_for(:CROSSREF)
[ @am.changed_attribute_by_name([], [:CROSSREF] | [:_SPECIAL_]),
- SM::Special.new(crossref_bitmap, text),
+ RDoc::Markup::Special.new(crossref_bitmap, text),
@am.changed_attribute_by_name([:CROSSREF] | [:_SPECIAL_], [])
]
end
diff --git a/test/rdoc/test_rdoc_ri_attribute_formatter.rb b/test/rdoc/test_rdoc_ri_attribute_formatter.rb
new file mode 100644
index 0000000000..d61a6f5cbc
--- /dev/null
+++ b/test/rdoc/test_rdoc_ri_attribute_formatter.rb
@@ -0,0 +1,42 @@
+require 'stringio'
+require 'test/unit'
+require 'rdoc/ri/formatter'
+
+class TestRDocRIAttributeFormatter < Test::Unit::TestCase
+
+ def setup
+ @output = StringIO.new
+ @width = 78
+ @indent = ' '
+
+ @f = RDoc::RI::AttributeFormatter.new @output, @width, @indent
+ end
+
+ def test_wrap_empty
+ @f.wrap ''
+ assert_equal '', @output.string
+ end
+
+ def test_wrap_long
+ @f.wrap 'a ' * (@width / 2)
+ assert_equal " a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a \n a \n",
+ @output.string
+ end
+
+ def test_wrap_markup
+ @f.wrap 'a <tt>b</tt> c'
+ assert_equal " a b c\n", @output.string
+ end
+
+ def test_wrap_nil
+ @f.wrap nil
+ assert_equal '', @output.string
+ end
+
+ def test_wrap_short
+ @f.wrap 'a b c'
+ assert_equal " a b c\n", @output.string
+ end
+
+end
+
diff --git a/test/rdoc/test_rdoc_ri_formatter.rb b/test/rdoc/test_rdoc_ri_formatter.rb
new file mode 100644
index 0000000000..a92f6cf7b8
--- /dev/null
+++ b/test/rdoc/test_rdoc_ri_formatter.rb
@@ -0,0 +1,124 @@
+require 'stringio'
+require 'test/unit'
+require 'rdoc/ri/formatter'
+require 'rdoc/markup/to_flow'
+
+class TestRDocRIFormatter < Test::Unit::TestCase
+
+ def setup
+ @output = StringIO.new
+ @width = 78
+ @indent = ' '
+
+ @f = RDoc::RI::Formatter.new @output, @width, @indent
+ @markup = RDoc::Markup.new
+ @flow = RDoc::Markup::ToFlow.new
+ end
+
+ def test_blankline
+ @f.blankline
+
+ assert_equal "\n", @output.string
+ end
+
+ def test_bold_print
+ @f.bold_print 'a b c'
+
+ assert_equal 'a b c', @output.string
+ end
+
+ def test_break_to_newline
+ @f.break_to_newline
+
+ assert_equal '', @output.string
+ end
+
+ def test_conv_html
+ assert_equal '> < " &', @f.conv_html('&gt; &lt; &quot; &amp;')
+ end
+
+ def test_conv_markup
+ text = '<tt>a</tt> <code>b</code> <b>c</b> <em>d</em>'
+
+ expected = '+a+ +b+ *c* _d_'
+
+ assert_equal expected, @f.conv_markup(text)
+ end
+
+ def test_display_list_bullet
+ list = util_convert('* a b c').first
+
+ @f.display_list list
+
+ assert_equal " * a b c\n\n", @output.string
+ end
+
+ def test_display_list_unknown
+ list = util_convert('* a b c').first
+ list.instance_variable_set :@type, :UNKNOWN
+
+ e = assert_raise ArgumentError do
+ @f.display_list list
+ end
+
+ assert_equal 'unknown list type UNKNOWN', e.message
+ end
+
+ def test_draw_line
+ @f.draw_line
+
+ expected = '-' * @width + "\n"
+ assert_equal expected, @output.string
+ end
+
+ def test_draw_line_label
+ @f.draw_line 'label'
+
+ expected = '-' * (@width - 6) + " label\n"
+ assert_equal expected, @output.string
+ end
+
+ def test_draw_line_label_long
+ @f.draw_line 'a' * @width
+
+ expected = '-' * @width + "\n" + ('a' * @width) + "\n"
+ assert_equal expected, @output.string
+ end
+
+ def test_raw_print_line
+ @f.raw_print_line 'a b c'
+
+ assert_equal "a b c\n", @output.string
+ end
+
+ def test_wrap_empty
+ @f.wrap ''
+ assert_equal '', @output.string
+ end
+
+ def test_wrap_long
+ @f.wrap 'a ' * (@width / 2)
+ assert_equal " a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a\n a \n",
+ @output.string
+ end
+
+ def test_wrap_markup
+ @f.wrap 'a <tt>b</tt> c'
+ assert_equal " a +b+ c\n", @output.string
+ end
+
+ def test_wrap_nil
+ @f.wrap nil
+ assert_equal '', @output.string
+ end
+
+ def test_wrap_short
+ @f.wrap 'a b c'
+ assert_equal " a b c\n", @output.string
+ end
+
+ def util_convert(text)
+ @markup.convert text, @flow
+ end
+end
+