mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* 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
This commit is contained in:
parent
9872d4d600
commit
8d37cefaf8
15 changed files with 443 additions and 261 deletions
|
@ -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
|
||||
|
||||
##
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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"
|
||||
|
|
49
lib/rdoc/markup/to_test.rb
Normal file
49
lib/rdoc/markup/to_test.rb
Normal file
|
@ -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
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue