aboutsummaryrefslogtreecommitdiffstats
path: root/lib/rdoc/markup/to_table_of_contents.rb
diff options
context:
space:
mode:
authordrbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-12-05 22:20:15 +0000
committerdrbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-12-05 22:20:15 +0000
commit54c40f3db59d6875de0c2c0f47ab7edce0bd3f43 (patch)
tree6dc4fc7137f7d98e84fe01b7270ab08a2f22718f /lib/rdoc/markup/to_table_of_contents.rb
parentfe6b2e20e9f17ed2c2900aa72994e075ffdc7124 (diff)
downloadruby-54c40f3db59d6875de0c2c0f47ab7edce0bd3f43.tar.gz
* lib/rdoc*: Improved display of ChangeLog files as HTML.
* test/rdoc*: Test for above. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38226 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/rdoc/markup/to_table_of_contents.rb')
-rw-r--r--lib/rdoc/markup/to_table_of_contents.rb28
1 files changed, 27 insertions, 1 deletions
diff --git a/lib/rdoc/markup/to_table_of_contents.rb b/lib/rdoc/markup/to_table_of_contents.rb
index 54f2d5f64f..2e0f98cfeb 100644
--- a/lib/rdoc/markup/to_table_of_contents.rb
+++ b/lib/rdoc/markup/to_table_of_contents.rb
@@ -18,15 +18,31 @@ class RDoc::Markup::ToTableOfContents < RDoc::Markup::Formatter
attr_reader :res
+ ##
+ # Omits headings with a level less than the given level.
+
+ attr_accessor :omit_headings_below
+
def initialize # :nodoc:
super nil
+
+ @omit_headings_below = nil
+ end
+
+ ##
+ # Adds +document+ to the output, using its heading cutoff if present
+
+ def accept_document document
+ @omit_headings_below = document.omit_headings_below
+
+ super
end
##
# Adds +heading+ to the table of contents
def accept_heading heading
- @res << heading
+ @res << heading unless suppressed? heading
end
##
@@ -40,9 +56,19 @@ class RDoc::Markup::ToTableOfContents < RDoc::Markup::Formatter
# Prepares the visitor for text generation
def start_accepting
+ @omit_headings_below = nil
@res = []
end
+ ##
+ # Returns true if +heading+ is below the display threshold
+
+ def suppressed? heading
+ return false unless @omit_headings_below
+
+ heading.level > @omit_headings_below
+ end
+
# :stopdoc:
alias accept_block_quote ignore
alias accept_raw ignore