summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authordrbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-04-27 03:45:22 +0000
committerdrbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-04-27 03:45:22 +0000
commit336a8301f725bd8fbf5f1e0c4fee162382a76d0f (patch)
tree455c5fb8689d09e734a9ca13cdbe3ef9a7651a6e /lib
parent3a87c3c5603fce8449f78faccaff5f4be6f372e1 (diff)
Import RDoc 2.5.7. Fixes #1318 and ruby-core:29780
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@27509 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib')
-rw-r--r--lib/rdoc.rb2
-rw-r--r--lib/rdoc/known_classes.rb1
-rw-r--r--lib/rdoc/markup.rb12
-rw-r--r--lib/rdoc/markup/formatter_test_case.rb12
-rw-r--r--lib/rdoc/markup/paragraph.rb57
-rw-r--r--lib/rdoc/markup/parser.rb1
-rw-r--r--lib/rdoc/markup/preprocess.rb64
-rw-r--r--lib/rdoc/markup/raw.rb65
-rw-r--r--lib/rdoc/markup/to_html.rb4
-rw-r--r--lib/rdoc/markup/to_rdoc.rb4
-rw-r--r--lib/rdoc/markup/verbatim.rb2
-rw-r--r--lib/rdoc/options.rb5
-rw-r--r--lib/rdoc/parser/c.rb5
-rw-r--r--lib/rdoc/parser/ruby.rb5
-rw-r--r--lib/rdoc/parser/simple.rb5
15 files changed, 160 insertions, 84 deletions
diff --git a/lib/rdoc.rb b/lib/rdoc.rb
index 3dbb63abd3a..7467ef29654 100644
--- a/lib/rdoc.rb
+++ b/lib/rdoc.rb
@@ -383,7 +383,7 @@ module RDoc
##
# RDoc version you are using
- VERSION = '2.5.6'
+ VERSION = '2.5.7'
##
# Name of the dotfile that contains the description of files to be processed
diff --git a/lib/rdoc/known_classes.rb b/lib/rdoc/known_classes.rb
index dbb1802f5ae..720a35f4975 100644
--- a/lib/rdoc/known_classes.rb
+++ b/lib/rdoc/known_classes.rb
@@ -5,6 +5,7 @@ module RDoc
KNOWN_CLASSES = {
"rb_cArray" => "Array",
+ "rb_cBasicObject" => "BasicObject",
"rb_cBignum" => "Bignum",
"rb_cClass" => "Class",
"rb_cData" => "Data",
diff --git a/lib/rdoc/markup.rb b/lib/rdoc/markup.rb
index 8176e904479..32c8179e0d9 100644
--- a/lib/rdoc/markup.rb
+++ b/lib/rdoc/markup.rb
@@ -107,15 +107,13 @@ class RDoc::Markup
end
##
- # We take a string, split it into lines, work out the type of each line,
- # and from there deduce groups of lines (for example all lines in a
- # paragraph). We then invoke the output formatter using a Visitor to
- # display the result.
+ # We take +text+, parse it then invoke the output +formatter+ using a
+ # Visitor to render the result.
- def convert(str, op)
- document = RDoc::Markup::Parser.parse str
+ def convert text, formatter
+ document = RDoc::Markup::Parser.parse text
- document.accept op
+ document.accept formatter
end
end
diff --git a/lib/rdoc/markup/formatter_test_case.rb b/lib/rdoc/markup/formatter_test_case.rb
index 9b9d7cf0003..26c8d63332e 100644
--- a/lib/rdoc/markup/formatter_test_case.rb
+++ b/lib/rdoc/markup/formatter_test_case.rb
@@ -87,6 +87,18 @@ class RDoc::Markup::FormatterTestCase < MiniTest::Unit::TestCase
accept_verbatim
end
+ def test_accept_raw
+ @to.start_accepting
+
+ @to.accept_raw @RM::Raw.new("<table>",
+ "<tr><th>Name<th>Count",
+ "<tr><td>a<td>1",
+ "<tr><td>b<td>2",
+ "</table>")
+
+ accept_raw
+ end
+
def test_accept_rule
@to.start_accepting
diff --git a/lib/rdoc/markup/paragraph.rb b/lib/rdoc/markup/paragraph.rb
index bc23423dfce..a9923ed24d9 100644
--- a/lib/rdoc/markup/paragraph.rb
+++ b/lib/rdoc/markup/paragraph.rb
@@ -1,66 +1,11 @@
##
# A Paragraph of text
-class RDoc::Markup::Paragraph
-
- ##
- # The component parts of the list
-
- attr_reader :parts
-
- ##
- # Creates a new Paragraph containing +parts+
-
- def initialize *parts
- @parts = []
- @parts.push(*parts)
- end
-
- ##
- # Appends +text+ to the Paragraph
-
- def << text
- @parts << text
- end
-
- def == other # :nodoc:
- self.class == other.class and text == other.text
- end
+class RDoc::Markup::Paragraph < RDoc::Markup::Raw
def accept visitor
visitor.accept_paragraph self
end
- ##
- # Appends +other+'s parts into this Paragraph
-
- def merge other
- @parts.push(*other.parts)
- end
-
- def pretty_print q # :nodoc:
- self.class.name =~ /.*::(\w{4})/i
-
- q.group 2, "[#{$1.downcase}: ", ']' do
- q.seplist @parts do |part|
- q.pp part
- end
- end
- end
-
- ##
- # Appends +texts+ onto this Paragraph
-
- def push *texts
- self.parts.push(*texts)
- end
-
- ##
- # The text of this paragraph
-
- def text
- @parts.join ' '
- end
-
end
diff --git a/lib/rdoc/markup/parser.rb b/lib/rdoc/markup/parser.rb
index 166d8f89f72..c214f74782d 100644
--- a/lib/rdoc/markup/parser.rb
+++ b/lib/rdoc/markup/parser.rb
@@ -522,6 +522,7 @@ require 'rdoc/markup/document'
require 'rdoc/markup/heading'
require 'rdoc/markup/list'
require 'rdoc/markup/list_item'
+require 'rdoc/markup/raw'
require 'rdoc/markup/paragraph'
require 'rdoc/markup/rule'
require 'rdoc/markup/verbatim'
diff --git a/lib/rdoc/markup/preprocess.rb b/lib/rdoc/markup/preprocess.rb
index f3925cc692f..cefb498916e 100644
--- a/lib/rdoc/markup/preprocess.rb
+++ b/lib/rdoc/markup/preprocess.rb
@@ -4,9 +4,30 @@ require 'rdoc/markup'
# Handle common directives that can occur in a block of text:
#
# : include : filename
+#
+# RDoc plugin authors can register additional directives to be handled through
+# RDoc::Markup::PreProcess::register
class RDoc::Markup::PreProcess
+ @registered = {}
+
+ ##
+ # Registers +directive+ as one handled by RDoc. If a block is given the
+ # directive will be replaced by the result of the block, otherwise the
+ # directive will be removed from the processed text.
+
+ def self.register directive, &block
+ @registered[directive] = block
+ end
+
+ ##
+ # Registered directives
+
+ def self.registered
+ @registered
+ end
+
##
# Creates a new pre-processor for +input_file_name+ that will look for
# included files in +include_path+
@@ -17,10 +38,20 @@ class RDoc::Markup::PreProcess
end
##
- # Look for common options in a chunk of text. Options that we don't handle
- # are yielded to the caller.
-
- def handle(text)
+ # Look for directives in a chunk of +text+.
+ #
+ # Options that we don't handle are yielded. If the block returns false the
+ # directive is restored to the text. If the block returns nil or no block
+ # was given the directive is handled according to the registered directives.
+ # If a String was returned the directive is replaced with the string.
+ #
+ # If no matching directive was registered the directive is restored to the
+ # text.
+ #
+ # If +code_object+ is given and the param is set as metadata on the
+ # +code_object+. See RDoc::CodeObject#metadata
+
+ def handle text, code_object = nil
text.gsub!(/^([ \t]*#?[ \t]*):(\w+):([ \t]*)(.+)?\n/) do
next $& if $3.empty? and $4 and $4[0, 1] == ':'
@@ -34,11 +65,26 @@ class RDoc::Markup::PreProcess
include_file filename, prefix
else
- result = yield directive, param
- result = "#{prefix}:#{directive}: #{param}\n" unless result
+ result = yield directive, param if block_given?
+
+ case result
+ when nil then
+ code_object.metadata[directive] = param if code_object
+ if RDoc::Markup::PreProcess.registered.include? directive then
+ handler = RDoc::Markup::PreProcess.registered[directive]
+ result = handler.call directive, param if handler
+ else
+ result = "#{prefix}:#{directive}: #{param}\n"
+ end
+ when false then
+ result = "#{prefix}:#{directive}: #{param}\n"
+ end
+
result
end
end
+
+ text
end
##
@@ -46,7 +92,11 @@ class RDoc::Markup::PreProcess
def include_file(name, indent)
if full_name = find_include_file(name) then
- content = File.binread full_name
+ content = if defined?(Encoding) then
+ File.binread full_name
+ else
+ File.read full_name
+ end
# HACK determine content type and force encoding
content = content.sub(/\A# .*coding[=:].*$/, '').lstrip
diff --git a/lib/rdoc/markup/raw.rb b/lib/rdoc/markup/raw.rb
new file mode 100644
index 00000000000..1124be7cc82
--- /dev/null
+++ b/lib/rdoc/markup/raw.rb
@@ -0,0 +1,65 @@
+##
+# A section of text that is added to the output document as-is
+
+class RDoc::Markup::Raw
+
+ ##
+ # The component parts of the list
+
+ attr_reader :parts
+
+ ##
+ # Creates a new Raw containing +parts+
+
+ def initialize *parts
+ @parts = []
+ @parts.push(*parts)
+ end
+
+ ##
+ # Appends +text+
+
+ def << text
+ @parts << text
+ end
+
+ def == other # :nodoc:
+ self.class == other.class and text == other.text
+ end
+
+ def accept visitor
+ visitor.accept_raw self
+ end
+
+ ##
+ # Appends +other+'s parts
+
+ def merge other
+ @parts.push(*other.parts)
+ end
+
+ def pretty_print q # :nodoc:
+ self.class.name =~ /.*::(\w{4})/i
+
+ q.group 2, "[#{$1.downcase}: ", ']' do
+ q.seplist @parts do |part|
+ q.pp part
+ end
+ end
+ end
+
+ ##
+ # Appends +texts+ onto this Paragraph
+
+ def push *texts
+ self.parts.push(*texts)
+ end
+
+ ##
+ # The raw text
+
+ def text
+ @parts.join ' '
+ end
+
+end
diff --git a/lib/rdoc/markup/to_html.rb b/lib/rdoc/markup/to_html.rb
index 66c0ee3d30f..74e3137eb2d 100644
--- a/lib/rdoc/markup/to_html.rb
+++ b/lib/rdoc/markup/to_html.rb
@@ -227,6 +227,10 @@ class RDoc::Markup::ToHtml < RDoc::Markup::Formatter
@res << convert_heading(heading.level, @am.flow(heading.text))
end
+ def accept_raw raw
+ @res << raw.parts.join("\n")
+ end
+
private
##
diff --git a/lib/rdoc/markup/to_rdoc.rb b/lib/rdoc/markup/to_rdoc.rb
index 97c7d0c984e..867715bb1e9 100644
--- a/lib/rdoc/markup/to_rdoc.rb
+++ b/lib/rdoc/markup/to_rdoc.rb
@@ -127,6 +127,10 @@ class RDoc::Markup::ToRdoc < RDoc::Markup::Formatter
wrap attributes(paragraph.text)
end
+ def accept_raw raw
+ @res << raw.parts.join("\n")
+ end
+
def accept_rule rule
use_prefix or @res << ' ' * @indent
@res << '-' * (@width - @indent)
diff --git a/lib/rdoc/markup/verbatim.rb b/lib/rdoc/markup/verbatim.rb
index faf539a7233..c684d787656 100644
--- a/lib/rdoc/markup/verbatim.rb
+++ b/lib/rdoc/markup/verbatim.rb
@@ -1,7 +1,7 @@
##
# A section of verbatim text
-class RDoc::Markup::Verbatim < RDoc::Markup::Paragraph
+class RDoc::Markup::Verbatim < RDoc::Markup::Raw
def accept visitor
visitor.accept_verbatim self
diff --git a/lib/rdoc/options.rb b/lib/rdoc/options.rb
index 7b3a23ca5c9..90415f0aa44 100644
--- a/lib/rdoc/options.rb
+++ b/lib/rdoc/options.rb
@@ -366,6 +366,11 @@ Usage: #{opt.program_name} [options] [names...]
end
end
+ if @pipe and not argv.empty? then
+ @pipe = false
+ ignored << '-p (with files)'
+ end
+
unless ignored.empty? or quiet then
$stderr.puts "invalid options: #{ignored.join ', '}"
$stderr.puts '(invalid options are ignored)'
diff --git a/lib/rdoc/parser/c.rb b/lib/rdoc/parser/c.rb
index 05b1e779256..f30167aafc9 100644
--- a/lib/rdoc/parser/c.rb
+++ b/lib/rdoc/parser/c.rb
@@ -661,7 +661,7 @@ class RDoc::Parser::C < RDoc::Parser
def look_for_directives_in(context, comment)
preprocess = RDoc::Markup::PreProcess.new @file_name, @options.rdoc_include
- preprocess.handle comment do |directive, param|
+ preprocess.handle comment, context do |directive, param|
case directive
when 'main' then
@options.main_page = param
@@ -669,9 +669,6 @@ class RDoc::Parser::C < RDoc::Parser
when 'title' then
@options.title = param
''
- else
- context.metadata[directive] = param
- false
end
end
diff --git a/lib/rdoc/parser/ruby.rb b/lib/rdoc/parser/ruby.rb
index c8bab57607d..1876c339fa0 100644
--- a/lib/rdoc/parser/ruby.rb
+++ b/lib/rdoc/parser/ruby.rb
@@ -379,7 +379,7 @@ class RDoc::Parser::Ruby < RDoc::Parser
def look_for_directives_in(context, comment)
preprocess = RDoc::Markup::PreProcess.new @file_name, @options.rdoc_include
- preprocess.handle comment do |directive, param|
+ preprocess.handle comment, context do |directive, param|
case directive
when 'enddoc' then
throw :enddoc
@@ -403,9 +403,6 @@ class RDoc::Parser::Ruby < RDoc::Parser
when 'title' then
@options.title = param
''
- else
- @top_level.metadata[directive] = param
- false
end
end
diff --git a/lib/rdoc/parser/simple.rb b/lib/rdoc/parser/simple.rb
index 25fa3c5159b..e99d2d43195 100644
--- a/lib/rdoc/parser/simple.rb
+++ b/lib/rdoc/parser/simple.rb
@@ -17,10 +17,7 @@ class RDoc::Parser::Simple < RDoc::Parser
preprocess = RDoc::Markup::PreProcess.new @file_name, @options.rdoc_include
- preprocess.handle @content do |directive, param|
- top_level.metadata[directive] = param
- false
- end
+ preprocess.handle @content, @top_level
end
##