1
0
Fork 0
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:
drbrain 2012-12-05 22:20:15 +00:00
parent fe6b2e20e9
commit 54c40f3db5
9 changed files with 136 additions and 14 deletions

View file

@ -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> Thu Dec 6 04:34:19 2012 KOSAKI Motohiro <kosaki.motohiro@gmail.com>
* thread.c (rb_uninterruptible): helper function for providing * thread.c (rb_uninterruptible): helper function for providing

View file

@ -11,6 +11,12 @@ class RDoc::Markup::Document
attr_reader :file 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 # The parts of the Document
@ -24,6 +30,7 @@ class RDoc::Markup::Document
@parts.concat parts @parts.concat parts
@file = nil @file = nil
@omit_headings_from_table_of_contents_below = nil
end end
## ##
@ -57,14 +64,7 @@ class RDoc::Markup::Document
def accept visitor def accept visitor
visitor.start_accepting visitor.start_accepting
@parts.each do |item| visitor.accept_document self
case item
when RDoc::Markup::Document then # HACK
visitor.accept_document item
else
item.accept visitor
end
end
visitor.end_accepting visitor.end_accepting
end end

View file

@ -42,7 +42,12 @@ class RDoc::Markup::Formatter
def accept_document document def accept_document document
document.parts.each do |item| document.parts.each do |item|
item.accept self case item
when RDoc::Markup::Document then # HACK
accept_document item
else
item.accept self
end
end end
end end

View file

@ -1,7 +1,8 @@
## ##
# A heading with a level (1-6) and text # 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_html = nil
@to_label = nil @to_label = nil

View file

@ -18,15 +18,31 @@ class RDoc::Markup::ToTableOfContents < RDoc::Markup::Formatter
attr_reader :res attr_reader :res
##
# Omits headings with a level less than the given level.
attr_accessor :omit_headings_below
def initialize # :nodoc: def initialize # :nodoc:
super nil 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 end
## ##
# Adds +heading+ to the table of contents # Adds +heading+ to the table of contents
def accept_heading heading def accept_heading heading
@res << heading @res << heading unless suppressed? heading
end end
## ##
@ -40,9 +56,19 @@ class RDoc::Markup::ToTableOfContents < RDoc::Markup::Formatter
# Prepares the visitor for text generation # Prepares the visitor for text generation
def start_accepting def start_accepting
@omit_headings_below = nil
@res = [] @res = []
end 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: # :stopdoc:
alias accept_block_quote ignore alias accept_block_quote ignore
alias accept_raw ignore alias accept_raw ignore

View file

@ -23,13 +23,14 @@ class RDoc::Parser::ChangeLog < RDoc::Parser
def create_document groups def create_document groups
doc = RDoc::Markup::Document.new doc = RDoc::Markup::Document.new
doc.omit_headings_below = 2
doc.file = @top_level doc.file = @top_level
doc << RDoc::Markup::Heading.new(1, File.basename(@file_name)) doc << RDoc::Markup::Heading.new(1, File.basename(@file_name))
doc << RDoc::Markup::BlankLine.new doc << RDoc::Markup::BlankLine.new
groups.sort_by do |day,| day end.reverse_each do |day, entries| 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 << RDoc::Markup::BlankLine.new
doc.concat create_entries entries doc.concat create_entries entries
@ -55,7 +56,11 @@ class RDoc::Parser::ChangeLog < RDoc::Parser
list = RDoc::Markup::List.new :NOTE list = RDoc::Markup::List.new :NOTE
items.each do |item| items.each do |item|
title, body = item.split(/:\s*/, 2) item =~ /\A(.*?(?:\([^)]+\))?):\s*/
title = $1
body = $'
paragraph = RDoc::Markup::Paragraph.new body paragraph = RDoc::Markup::Paragraph.new body
list_item = RDoc::Markup::ListItem.new title, paragraph list_item = RDoc::Markup::ListItem.new title, paragraph
list << list_item list << list_item

View file

@ -191,5 +191,24 @@ class TestRDocMarkupDocument < RDoc::TestCase
assert_equal expected, doc.table_of_contents assert_equal expected, doc.table_of_contents
end 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 end

View file

@ -91,5 +91,36 @@ class TestRDocMarkupToTableOfContents < RDoc::Markup::FormatterTestCase
alias list_verbatim empty alias list_verbatim empty
alias start_accepting 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 end

View file

@ -96,7 +96,17 @@ class TestRDocParserChangeLog < RDoc::TestCase
expected.file = @top_level 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 end
def test_create_entries def test_create_entries
@ -118,6 +128,26 @@ class TestRDocParserChangeLog < RDoc::TestCase
list(:NOTE, item('c', para('three')), item('d', para('four'))), 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) assert_equal expected, parser.create_entries(entries)
end end