aboutsummaryrefslogtreecommitdiffstats
path: root/lib/rdoc/markup/document.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/rdoc/markup/document.rb')
-rw-r--r--lib/rdoc/markup/document.rb45
1 files changed, 41 insertions, 4 deletions
diff --git a/lib/rdoc/markup/document.rb b/lib/rdoc/markup/document.rb
index 7077f357d3..198cef9ed9 100644
--- a/lib/rdoc/markup/document.rb
+++ b/lib/rdoc/markup/document.rb
@@ -3,11 +3,13 @@
class RDoc::Markup::Document
+ include Enumerable
+
##
# The file this document was created from. See also
# RDoc::ClassModule#add_comment
- attr_accessor :file
+ attr_reader :file
##
# The parts of the Document
@@ -19,7 +21,7 @@ class RDoc::Markup::Document
def initialize *parts
@parts = []
- @parts.push(*parts)
+ @parts.concat parts
@file = nil
end
@@ -31,7 +33,7 @@ class RDoc::Markup::Document
case part
when RDoc::Markup::Document then
unless part.empty? then
- parts.push(*part.parts)
+ parts.concat part.parts
parts << RDoc::Markup::BlankLine.new
end
when String then
@@ -68,6 +70,20 @@ class RDoc::Markup::Document
end
##
+ # Concatenates the given +parts+ onto the document
+
+ def concat parts
+ self.parts.concat parts
+ end
+
+ ##
+ # Enumerator for the parts of this document
+
+ def each &block
+ @parts.each(&block)
+ end
+
+ ##
# Does this document have no parts?
def empty?
@@ -75,6 +91,18 @@ class RDoc::Markup::Document
end
##
+ # The file this Document was created from.
+
+ def file= location
+ @file = case location
+ when RDoc::TopLevel then
+ location.absolute_name
+ else
+ location
+ end
+ 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
@@ -120,7 +148,16 @@ class RDoc::Markup::Document
# Appends +parts+ to the document
def push *parts
- self.parts.push(*parts)
+ self.parts.concat parts
+ end
+
+ ##
+ # Returns an Array of headings in the document.
+ #
+ # Require 'rdoc/markup/formatter' before calling this method.
+
+ def table_of_contents
+ accept RDoc::Markup::ToTableOfContents.to_toc
end
end