summaryrefslogtreecommitdiff
path: root/lib/rdoc/markup
diff options
context:
space:
mode:
authordrbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-06-16 04:59:24 +0000
committerdrbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-06-16 04:59:24 +0000
commitb7528b5edb1f9148ea00ebb6151720e5943b3f0b (patch)
tree4caf55c53adb188170240f54b924892fbc5f9814 /lib/rdoc/markup
parent97ac172d58d695305c39d555155318edb99f1ea7 (diff)
* lib/rdoc.rb: Import RDoc 3.7 release candidate
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@32115 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/rdoc/markup')
-rw-r--r--lib/rdoc/markup/document.rb36
-rw-r--r--lib/rdoc/markup/formatter.rb16
-rw-r--r--lib/rdoc/markup/formatter_test_case.rb10
-rw-r--r--lib/rdoc/markup/indented_paragraph.rb33
-rw-r--r--lib/rdoc/markup/parser.rb1
-rw-r--r--lib/rdoc/markup/pre_process.rb7
-rw-r--r--lib/rdoc/markup/to_ansi.rb2
-rw-r--r--lib/rdoc/markup/to_bs.rb2
-rw-r--r--lib/rdoc/markup/to_html.rb4
-rw-r--r--lib/rdoc/markup/to_html_crossref.rb5
-rw-r--r--lib/rdoc/markup/to_rdoc.rb11
-rw-r--r--lib/rdoc/markup/to_test.rb2
-rw-r--r--lib/rdoc/markup/to_tt_only.rb2
13 files changed, 117 insertions, 14 deletions
diff --git a/lib/rdoc/markup/document.rb b/lib/rdoc/markup/document.rb
index 688e8e822e..b4e070285e 100644
--- a/lib/rdoc/markup/document.rb
+++ b/lib/rdoc/markup/document.rb
@@ -4,6 +4,12 @@
class RDoc::Markup::Document
##
+ # The file this document was created from. See also
+ # RDoc::ClassModule#add_comment
+
+ attr_accessor :file
+
+ ##
# The parts of the Document
attr_reader :parts
@@ -14,6 +20,8 @@ class RDoc::Markup::Document
def initialize *parts
@parts = []
@parts.push(*parts)
+
+ @file = nil
end
##
@@ -36,7 +44,9 @@ class RDoc::Markup::Document
end
def == other # :nodoc:
- self.class == other.class and @parts == other.parts
+ self.class == other.class and
+ @file == other.file and
+ @parts == other.parts
end
##
@@ -59,8 +69,30 @@ class RDoc::Markup::Document
@parts.empty?
end
+ ##
+ # When this is a collection of documents (#file is not set and this document
+ # contains only other documents as its direct children) #merge replaces
+ # documents in this class with documents from +other+ when the file matches
+ # and adds documents from +other+ when the files do not.
+ #
+ # The information in +other+ is preferred over the receiver
+
+ def merge other
+ other.parts.each do |other_part|
+ self.parts.delete_if do |self_part|
+ self_part.file and self_part.file == other_part.file
+ end
+
+ self.parts << other_part
+ end
+
+ self
+ end
+
def pretty_print q # :nodoc:
- q.group 2, '[doc: ', ']' do
+ start = @file ? "[doc (#{@file}): " : '[doc: '
+
+ q.group 2, start, ']' do
q.seplist @parts do |part|
q.pp part
end
diff --git a/lib/rdoc/markup/formatter.rb b/lib/rdoc/markup/formatter.rb
index 9308954de1..b6e12f82e7 100644
--- a/lib/rdoc/markup/formatter.rb
+++ b/lib/rdoc/markup/formatter.rb
@@ -16,9 +16,10 @@ class RDoc::Markup::Formatter
##
# Creates a new Formatter
- def initialize
- @markup = RDoc::Markup.new
- @am = @markup.attribute_manager
+ def initialize markup = nil
+ @markup = markup || RDoc::Markup.new
+ @am = @markup.attribute_manager
+
@attr_tags = []
@in_tt = 0
@@ -26,6 +27,15 @@ class RDoc::Markup::Formatter
end
##
+ # Adds +document+ to the output
+
+ def accept_document document
+ document.parts.each do |item|
+ item.accept self
+ end
+ end
+
+ ##
# Add a new set of tags for an attribute. We allow separate start and end
# tags for flexibility
diff --git a/lib/rdoc/markup/formatter_test_case.rb b/lib/rdoc/markup/formatter_test_case.rb
index 26dc4b25e9..c739f990b3 100644
--- a/lib/rdoc/markup/formatter_test_case.rb
+++ b/lib/rdoc/markup/formatter_test_case.rb
@@ -120,6 +120,16 @@ class RDoc::Markup::FormatterTestCase < MiniTest::Unit::TestCase
end
##
+ # Test case that calls <tt>@to.accept_document</tt>
+
+ def test_accept_document
+ @to.start_accepting
+ @to.accept_document @RM::Document.new @RM::Paragraph.new 'hello'
+
+ accept_document
+ end
+
+ ##
# Calls accept_heading with a level 5 RDoc::Markup::Heading
def test_accept_heading
diff --git a/lib/rdoc/markup/indented_paragraph.rb b/lib/rdoc/markup/indented_paragraph.rb
new file mode 100644
index 0000000000..d995c7d8ed
--- /dev/null
+++ b/lib/rdoc/markup/indented_paragraph.rb
@@ -0,0 +1,33 @@
+##
+# An Indented Paragraph of text
+
+class RDoc::Markup::IndentedParagraph < RDoc::Markup::Raw
+
+ ##
+ # The indent in number of spaces
+
+ attr_reader :indent
+
+ ##
+ # Creates a new IndentedParagraph containing +parts+ indented with +indent+
+ # spaces
+
+ def initialize indent, *parts
+ @indent = indent
+
+ super(*parts)
+ end
+
+ def == other # :nodoc:
+ super and indent == other.indent
+ end
+
+ ##
+ # Calls #accept_indented_paragraph on +visitor+
+
+ def accept visitor
+ visitor.accept_indented_paragraph self
+ end
+
+end
+
diff --git a/lib/rdoc/markup/parser.rb b/lib/rdoc/markup/parser.rb
index c94b900154..68616d7787 100644
--- a/lib/rdoc/markup/parser.rb
+++ b/lib/rdoc/markup/parser.rb
@@ -478,6 +478,7 @@ require 'rdoc/markup/list'
require 'rdoc/markup/list_item'
require 'rdoc/markup/raw'
require 'rdoc/markup/paragraph'
+require 'rdoc/markup/indented_paragraph'
require 'rdoc/markup/rule'
require 'rdoc/markup/verbatim'
diff --git a/lib/rdoc/markup/pre_process.rb b/lib/rdoc/markup/pre_process.rb
index ccc2688050..03f919aa0e 100644
--- a/lib/rdoc/markup/pre_process.rb
+++ b/lib/rdoc/markup/pre_process.rb
@@ -74,6 +74,13 @@ class RDoc::Markup::PreProcess
filename = param.split[0]
encoding = if defined?(Encoding) then text.encoding else nil end
include_file filename, prefix, encoding
+ when 'category' then
+ if RDoc::Context === code_object then
+ section = code_object.add_section param, ''
+ code_object.temporary_section = section
+ end
+
+ '' # ignore category if we're not on an RDoc::Context
else
result = yield directive, param if block_given?
diff --git a/lib/rdoc/markup/to_ansi.rb b/lib/rdoc/markup/to_ansi.rb
index c9f874ea3c..108a038075 100644
--- a/lib/rdoc/markup/to_ansi.rb
+++ b/lib/rdoc/markup/to_ansi.rb
@@ -8,7 +8,7 @@ class RDoc::Markup::ToAnsi < RDoc::Markup::ToRdoc
##
# Creates a new ToAnsi visitor that is ready to output vibrant ANSI color!
- def initialize
+ def initialize markup = nil
super
@headings.clear
diff --git a/lib/rdoc/markup/to_bs.rb b/lib/rdoc/markup/to_bs.rb
index 931edd81ea..32b1bbb9eb 100644
--- a/lib/rdoc/markup/to_bs.rb
+++ b/lib/rdoc/markup/to_bs.rb
@@ -11,7 +11,7 @@ class RDoc::Markup::ToBs < RDoc::Markup::ToRdoc
##
# Returns a new ToBs that is ready for hot backspace action!
- def initialize
+ def initialize markup = nil
super
@in_b = false
diff --git a/lib/rdoc/markup/to_html.rb b/lib/rdoc/markup/to_html.rb
index 599f3713f1..b518fbf265 100644
--- a/lib/rdoc/markup/to_html.rb
+++ b/lib/rdoc/markup/to_html.rb
@@ -17,7 +17,7 @@ class RDoc::Markup::ToHtml < RDoc::Markup::Formatter
LIST_TYPE_TO_HTML = {
:BULLET => ['<ul>', '</ul>'],
- :LABEL => ['<dl>', '</dl>'],
+ :LABEL => ['<dl class="rdoc-list">', '</dl>'],
:LALPHA => ['<ol style="display: lower-alpha">', '</ol>'],
:NOTE => ['<table class="rdoc-list">', '</table>'],
:NUMBER => ['<ol>', '</ol>'],
@@ -62,7 +62,7 @@ class RDoc::Markup::ToHtml < RDoc::Markup::Formatter
##
# Creates a new formatter that will output HTML
- def initialize
+ def initialize markup = nil
super
@th = nil
diff --git a/lib/rdoc/markup/to_html_crossref.rb b/lib/rdoc/markup/to_html_crossref.rb
index 026defb862..aeecc3f4d0 100644
--- a/lib/rdoc/markup/to_html_crossref.rb
+++ b/lib/rdoc/markup/to_html_crossref.rb
@@ -104,9 +104,10 @@ class RDoc::Markup::ToHtmlCrossref < RDoc::Markup::ToHtml
# references are removed unless +show_hash+ is true. Only method names
# preceded by '#' or '::' are hyperlinked, unless +hyperlink_all+ is true.
- def initialize(from_path, context, show_hash, hyperlink_all = false)
+ def initialize(from_path, context, show_hash, hyperlink_all = false,
+ markup = nil)
raise ArgumentError, 'from_path cannot be nil' if from_path.nil?
- super()
+ super markup
crossref_re = hyperlink_all ? ALL_CROSSREF_REGEXP : CROSSREF_REGEXP
diff --git a/lib/rdoc/markup/to_rdoc.rb b/lib/rdoc/markup/to_rdoc.rb
index b10af036d9..6f2faac2f6 100644
--- a/lib/rdoc/markup/to_rdoc.rb
+++ b/lib/rdoc/markup/to_rdoc.rb
@@ -44,7 +44,7 @@ class RDoc::Markup::ToRdoc < RDoc::Markup::Formatter
##
# Creates a new formatter that will output (mostly) \RDoc markup
- def initialize
+ def initialize markup = nil
super
@markup.add_special(/\\\S/, :SUPPRESSED_CROSSREF)
@@ -172,6 +172,15 @@ class RDoc::Markup::ToRdoc < RDoc::Markup::Formatter
end
##
+ # Adds +paragraph+ to the output
+
+ def accept_indented_paragraph paragraph
+ @indent += paragraph.indent
+ wrap attributes(paragraph.text)
+ @indent -= paragraph.indent
+ end
+
+ ##
# Adds +raw+ to the output
def accept_raw raw
diff --git a/lib/rdoc/markup/to_test.rb b/lib/rdoc/markup/to_test.rb
index f79f9475f1..4847fd29f7 100644
--- a/lib/rdoc/markup/to_test.rb
+++ b/lib/rdoc/markup/to_test.rb
@@ -21,7 +21,7 @@ class RDoc::Markup::ToTest < RDoc::Markup::Formatter
end
def accept_paragraph(paragraph)
- @res << paragraph.text
+ @res << convert_flow(@am.flow(paragraph.text))
end
def accept_raw raw
diff --git a/lib/rdoc/markup/to_tt_only.rb b/lib/rdoc/markup/to_tt_only.rb
index 98ad2f6936..078e87db98 100644
--- a/lib/rdoc/markup/to_tt_only.rb
+++ b/lib/rdoc/markup/to_tt_only.rb
@@ -20,7 +20,7 @@ class RDoc::Markup::ToTtOnly < RDoc::Markup::Formatter
##
# Creates a new tt-only formatter.
- def initialize
+ def initialize markup = nil
super
add_tag :TT, nil, nil