mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* 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
This commit is contained in:
parent
fe6b2e20e9
commit
54c40f3db5
9 changed files with 136 additions and 14 deletions
|
@ -1,3 +1,8 @@
|
|||
Thu Dec 6 07:19:58 2012 Eric Hodel <drbrain@segment7.net>
|
||||
|
||||
* lib/rdoc*: Improved display of ChangeLog files as HTML.
|
||||
* test/rdoc*: Test for above.
|
||||
|
||||
Thu Dec 6 04:34:19 2012 KOSAKI Motohiro <kosaki.motohiro@gmail.com>
|
||||
|
||||
* thread.c (rb_uninterruptible): helper function for providing
|
||||
|
|
|
@ -11,6 +11,12 @@ class RDoc::Markup::Document
|
|||
|
||||
attr_reader :file
|
||||
|
||||
##
|
||||
# If a heading is below the given level it will be omitted from the
|
||||
# table_of_contents
|
||||
|
||||
attr_accessor :omit_headings_below
|
||||
|
||||
##
|
||||
# The parts of the Document
|
||||
|
||||
|
@ -24,6 +30,7 @@ class RDoc::Markup::Document
|
|||
@parts.concat parts
|
||||
|
||||
@file = nil
|
||||
@omit_headings_from_table_of_contents_below = nil
|
||||
end
|
||||
|
||||
##
|
||||
|
@ -57,14 +64,7 @@ class RDoc::Markup::Document
|
|||
def accept visitor
|
||||
visitor.start_accepting
|
||||
|
||||
@parts.each do |item|
|
||||
case item
|
||||
when RDoc::Markup::Document then # HACK
|
||||
visitor.accept_document item
|
||||
else
|
||||
item.accept visitor
|
||||
end
|
||||
end
|
||||
visitor.accept_document self
|
||||
|
||||
visitor.end_accepting
|
||||
end
|
||||
|
|
|
@ -42,9 +42,14 @@ class RDoc::Markup::Formatter
|
|||
|
||||
def accept_document document
|
||||
document.parts.each do |item|
|
||||
case item
|
||||
when RDoc::Markup::Document then # HACK
|
||||
accept_document item
|
||||
else
|
||||
item.accept self
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
##
|
||||
# Add a new set of tags for an attribute. We allow separate start and end
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
##
|
||||
# A heading with a level (1-6) and text
|
||||
|
||||
class RDoc::Markup::Heading < Struct.new :level, :text
|
||||
RDoc::Markup::Heading =
|
||||
Struct.new :level, :text do
|
||||
|
||||
@to_html = nil
|
||||
@to_label = nil
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -23,13 +23,14 @@ class RDoc::Parser::ChangeLog < RDoc::Parser
|
|||
|
||||
def create_document groups
|
||||
doc = RDoc::Markup::Document.new
|
||||
doc.omit_headings_below = 2
|
||||
doc.file = @top_level
|
||||
|
||||
doc << RDoc::Markup::Heading.new(1, File.basename(@file_name))
|
||||
doc << RDoc::Markup::BlankLine.new
|
||||
|
||||
groups.sort_by do |day,| day end.reverse_each do |day, entries|
|
||||
doc << RDoc::Markup::Heading.new(2, day)
|
||||
doc << RDoc::Markup::Heading.new(2, day.dup)
|
||||
doc << RDoc::Markup::BlankLine.new
|
||||
|
||||
doc.concat create_entries entries
|
||||
|
@ -55,7 +56,11 @@ class RDoc::Parser::ChangeLog < RDoc::Parser
|
|||
list = RDoc::Markup::List.new :NOTE
|
||||
|
||||
items.each do |item|
|
||||
title, body = item.split(/:\s*/, 2)
|
||||
item =~ /\A(.*?(?:\([^)]+\))?):\s*/
|
||||
|
||||
title = $1
|
||||
body = $'
|
||||
|
||||
paragraph = RDoc::Markup::Paragraph.new body
|
||||
list_item = RDoc::Markup::ListItem.new title, paragraph
|
||||
list << list_item
|
||||
|
|
|
@ -191,5 +191,24 @@ class TestRDocMarkupDocument < RDoc::TestCase
|
|||
assert_equal expected, doc.table_of_contents
|
||||
end
|
||||
|
||||
def test_table_of_contents_omit_headings_below
|
||||
document = doc(
|
||||
head(1, 'A'),
|
||||
para('B'),
|
||||
head(2, 'C'),
|
||||
para('D'),
|
||||
head(1, 'E'),
|
||||
para('F'))
|
||||
|
||||
document.omit_headings_below = 1
|
||||
|
||||
expected = [
|
||||
head(1, 'A'),
|
||||
head(1, 'E'),
|
||||
]
|
||||
|
||||
assert_equal expected, document.table_of_contents
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
|
|
@ -91,5 +91,36 @@ class TestRDocMarkupToTableOfContents < RDoc::Markup::FormatterTestCase
|
|||
alias list_verbatim empty
|
||||
alias start_accepting empty
|
||||
|
||||
def test_accept_document_omit_headings_below
|
||||
document = doc
|
||||
document.omit_headings_below = 2
|
||||
|
||||
@to.accept_document document
|
||||
|
||||
assert_equal 2, @to.omit_headings_below
|
||||
end
|
||||
|
||||
def test_accept_heading_suppressed
|
||||
@to.start_accepting
|
||||
@to.omit_headings_below = 4
|
||||
|
||||
suppressed = head 5, 'Hello'
|
||||
|
||||
@to.accept_heading suppressed
|
||||
|
||||
assert_empty @to.res
|
||||
end
|
||||
|
||||
def test_suppressed_eh
|
||||
@to.omit_headings_below = nil
|
||||
|
||||
refute @to.suppressed? head(1, '')
|
||||
|
||||
@to.omit_headings_below = 1
|
||||
|
||||
refute @to.suppressed? head(1, '')
|
||||
assert @to.suppressed? head(2, '')
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
|
|
@ -96,7 +96,17 @@ class TestRDocParserChangeLog < RDoc::TestCase
|
|||
|
||||
expected.file = @top_level
|
||||
|
||||
assert_equal expected, parser.create_document(groups)
|
||||
document = parser.create_document(groups)
|
||||
|
||||
assert_equal expected, document
|
||||
|
||||
assert_equal 2, document.omit_headings_below
|
||||
|
||||
headings = document.parts.select do |part|
|
||||
RDoc::Markup::Heading === part and part.level == 2
|
||||
end
|
||||
|
||||
refute headings.all? { |heading| heading.text.frozen? }
|
||||
end
|
||||
|
||||
def test_create_entries
|
||||
|
@ -118,6 +128,26 @@ class TestRDocParserChangeLog < RDoc::TestCase
|
|||
list(:NOTE, item('c', para('three')), item('d', para('four'))),
|
||||
]
|
||||
|
||||
entries = parser.create_entries(entries)
|
||||
assert_equal expected, entries
|
||||
end
|
||||
|
||||
def test_create_entries_colons
|
||||
parser = util_parser
|
||||
|
||||
entries = [
|
||||
['Wed Dec 5 12:17:11 2012 Naohisa Goto <ngotogenome@gmail.com>',
|
||||
['func.rb (DL::Function#bind): log stuff [ruby-core:50562]']],
|
||||
]
|
||||
|
||||
expected = [
|
||||
head(3,
|
||||
'Wed Dec 5 12:17:11 2012 Naohisa Goto <ngotogenome@gmail.com>'),
|
||||
blank_line,
|
||||
list(:NOTE,
|
||||
item('func.rb (DL::Function#bind)',
|
||||
para('log stuff [ruby-core:50562]')))]
|
||||
|
||||
assert_equal expected, parser.create_entries(entries)
|
||||
end
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue