Skip to content
Browse files

Tag RDoc 3.0

  • Loading branch information...
1 parent d4ff3f6 commit 321d6905bb69e5f10b14a5cc4213768914e3d5d9 @drbrain drbrain committed
View
24 History.txt
@@ -1,21 +1,26 @@
-=== 3.0
+=== 3.0 / 2010-12-19
+
+Special thanks to Thierry Lambert for massive improvements to RDoc.
* Major enhancements
* Ruby 1.8.6 is no longer supported by RDoc.
+ * RDoc now converts input files to a single encoding specified by
+ <tt>--encoding</tt>. See RDoc::RDoc and RDoc::Options#encoding.
+ <tt>--encoding</tt> is now preferred over <tt>--charset</tt>
+ * RDoc now supports a <tt>--coverage-report</tt> flag (also <tt>-C</tt> and
+ <tt>--dcov</tt>) that outputs a report on items lacking documentation.
+ * Templates (<tt>rdoc -T</tt>) are now checked for existence in
+ RDoc::Options. Generator authors can now use RDoc::Options#template_dir
+ which is the full path to the template directory.
+ * Added support for class aliases. Patch by Thierry Lambert.
* Improved merging of classes and modules across multiple files including
more accurate documentation statistics. Patch by Thierry Lambert.
* Improved handling of method aliases. Patch by Thierry Lambert.
- * Added support for class aliases. Patch by Thierry Lambert.
* Improved handling of visibility of RDoc code objects. Patch by Thierry
Lambert.
- * RDoc now converts input files to a single encoding specified by
- <tt>--encoding</tt>. See RDoc::RDoc and RDoc::Options#encoding.
- <tt>--encoding</tt> is now preferred over <tt>--charset</tt>
* RDoc::Attr#type is now RDoc::Attr#definition. Patch by Thierry Lambert.
* Removed TimeConstantMethods
- * Templates (<tt>rdoc -T</tt>) are now checked for existence in
- RDoc::Options. Generator authors can now use RDoc::Options#template_dir
- which is the full path to the template directory.
+ * RDoc now calls ::new instead of ::for on generators.
* Minor enhancements
* Added rdoc arguments <tt>--dry-run</tt>, <tt>--all</tt>,
<tt>--visibility</tt>, <tt>--force-output</tt>, <tt>--hyperlink-all</tt>.
@@ -53,6 +58,9 @@
* Removed "':' not followed by operator or identifier" warning for new Hash
syntax.
* rb_attr() is now supported for attributes.
+ * RDoc::Parser::C now supports yields, doc, and args directives like
+ RDoc::Parser::Ruby.
+ * Moved RDoc::Parser::PerlPOD to the rdoc-perl_pod gem.
* Bug fixes
* RDoc::Generator tests no longer require any installed RDoc on Ruby 1.9
* Load existing cache before generating ri. Ruby r27749 by NAKAMURA Usaku.
View
5 Manifest.txt
@@ -87,7 +87,6 @@ lib/rdoc/normal_module.rb
lib/rdoc/options.rb
lib/rdoc/parser.rb
lib/rdoc/parser/c.rb
-lib/rdoc/parser/perl.rb
lib/rdoc/parser/ruby.rb
lib/rdoc/parser/ruby_tools.rb
lib/rdoc/parser/simple.rb
@@ -102,6 +101,9 @@ lib/rdoc/ruby_lex.rb
lib/rdoc/ruby_token.rb
lib/rdoc/single_class.rb
lib/rdoc/stats.rb
+lib/rdoc/stats/normal.rb
+lib/rdoc/stats/quiet.rb
+lib/rdoc/stats/verbose.rb
lib/rdoc/task.rb
lib/rdoc/text.rb
lib/rdoc/token_stream.rb
@@ -142,7 +144,6 @@ test/test_rdoc_normal_module.rb
test/test_rdoc_options.rb
test/test_rdoc_parser.rb
test/test_rdoc_parser_c.rb
-test/test_rdoc_parser_perl.rb
test/test_rdoc_parser_ruby.rb
test/test_rdoc_parser_simple.rb
test/test_rdoc_rdoc.rb
View
2 Rakefile
@@ -13,7 +13,7 @@ Hoe.spec 'rdoc' do
self.remote_rdoc_dir = ''
self.testlib = :minitest
- extra_dev_deps << ['minitest', '~> 1.3']
+ extra_dev_deps << ['minitest', '~> 2']
extra_rdoc_files << 'Rakefile'
spec_extras['required_rubygems_version'] = '>= 1.3'
spec_extras['homepage'] = 'http://rdoc.rubyforge.org'
View
2 lib/rdoc.rb
@@ -95,7 +95,7 @@ def self.const_missing const_name # :nodoc:
##
# RDoc version you are using
- VERSION = '2.6'
+ VERSION = '3.0'
##
# Method visibilities
View
1 lib/rdoc/context.rb
@@ -841,6 +841,7 @@ def full_name
def fully_documented?
documented? and
+ attributes.all? { |a| a.documented? } and
method_list.all? { |m| m.documented? } and
constants.all? { |c| c.documented? }
end
View
9 lib/rdoc/erbio.rb
@@ -6,7 +6,7 @@
#
# To use:
#
-# erbio = RDoc::ERBIO.new '<%= "hello world" %>', nil, nil, 'io'
+# erbio = RDoc::ERBIO.new '<%= "hello world" %>', nil, nil
#
# open 'hello.txt', 'w' do |io|
# erbio.result binding
@@ -17,6 +17,13 @@
class RDoc::ERBIO < ERB
##
+ # Defaults +eoutvar+ to 'io', otherwise is identical to ERB's initialize
+
+ def initialize str, safe_level = nil, trim_mode = nil, eoutvar = 'io'
+ super
+ end
+
+ ##
# Instructs +compiler+ how to write to +io_variable+
def set_eoutvar compiler, io_variable
View
3 lib/rdoc/gauntlet.rb
@@ -7,6 +7,9 @@
class RDoc::Gauntlet < Gauntlet
+ ##
+ # Runs an RDoc generator for gem +name+
+
def run name
return if self.data.key? name
View
71 lib/rdoc/generator/darkfish.rb
@@ -53,38 +53,15 @@ class RDoc::Generator::Darkfish
include ERB::Util
- ##
- # Subversion rev
-
- SVNRev = %$Rev: 52 $
-
- ##
- # Subversion ID
-
- SVNId = %$Id: darkfish.rb 52 2009-01-07 02:08:11Z deveiant $
-
# Path to this file's parent directory. Used to find templates and other
# resources.
GENERATOR_DIR = File.join 'rdoc', 'generator'
+ ##
# Release Version
- VERSION = '1.1.6'
-
- # Directory where generated classes live relative to the root
-
- CLASS_DIR = nil
-
- # Directory where generated files live relative to the root
-
- FILE_DIR = nil
-
- # Standard generator factory method
-
- def self.for options
- new options
- end
+ VERSION = '2'
##
# Initialize a few instance variables before we start
@@ -93,6 +70,7 @@ def initialize options
@options = options
@template_dir = Pathname.new options.template_dir
+ @template_cache = {}
@files = nil
@classes = nil
@@ -113,12 +91,20 @@ def debug_msg *msg
$stderr.puts(*msg)
end
+ ##
+ # Directory where generated class HTML files live relative to the output
+ # dir.
+
def class_dir
- CLASS_DIR
+ nil
end
+ ##
+ # Directory where generated class HTML files live relative to the output
+ # dir.
+
def file_dir
- FILE_DIR
+ nil
end
##
@@ -229,9 +215,10 @@ def generate_class_files
@classes.each do |klass|
debug_msg " working on %s (%s)" % [klass.full_name, klass.path]
- out_file = @outputdir + klass.path
- rel_prefix = @outputdir.relative_path_from out_file.dirname
- svninfo = self.get_svninfo klass
+ out_file = @outputdir + klass.path
+ # suppress 1.9.3 warning
+ rel_prefix = rel_prefix = @outputdir.relative_path_from(out_file.dirname)
+ svninfo = svninfo = self.get_svninfo(klass)
debug_msg " rendering #{out_file}"
render_template template_file, out_file do |io| binding end
@@ -249,7 +236,8 @@ def generate_file_files
@files.each do |file|
out_file = @outputdir + file.path
debug_msg " working on %s (%s)" % [ file.full_name, out_file ]
- rel_prefix = @outputdir.relative_path_from out_file.dirname
+ # suppress 1.9.3 warning
+ rel_prefix = rel_prefix = @outputdir.relative_path_from(out_file.dirname)
debug_msg " rendering #{out_file}"
render_template template_file, out_file do |io| binding end
@@ -317,7 +305,7 @@ def get_svninfo klass
# An io will be yielded which must be captured by binding in the caller.
def render_template template_file, out_file # :yield: io
- template_src = template_file.read
+ template = template_for template_file
unless @options.dry_run then
debug_msg "Outputting to %s" % [out_file.expand_path]
@@ -326,15 +314,11 @@ def render_template template_file, out_file # :yield: io
out_file.open 'w', 0644 do |io|
io.set_encoding @options.encoding if Object.const_defined? :Encoding
- template = RDoc::ERBIO.new template_src, nil, '<>', 'io'
-
context = yield io
template_result template, context, template_file
end
else
- template = ERB.new template_src, nil, '<>'
-
context = yield nil
output = template_result template, context, template_file
@@ -359,5 +343,20 @@ def template_result template, context, template_file
], e.backtrace
end
+ ##
+ # Retrieves a cache template for +file+, if present, or fills the cache.
+
+ def template_for file
+ template = @template_cache[file]
+
+ return template if template
+
+ klass = @options.dry_run ? ERB : RDoc::ERBIO
+
+ template = klass.new file.read, nil, '<>'
+ @template_cache[file] = template
+ template
+ end
+
end
View
4 lib/rdoc/generator/ri.rb
@@ -8,10 +8,6 @@ class RDoc::Generator::RI
RDoc::RDoc.add_generator self
- def self.for options
- new options
- end
-
##
# Set up a new ri generator
View
3 lib/rdoc/markup.rb
@@ -527,6 +527,9 @@
class RDoc::Markup
+ ##
+ # An AttributeManager which handles inline markup.
+
attr_reader :attribute_manager
##
View
7 lib/rdoc/markup/attribute_manager.rb
@@ -15,9 +15,12 @@ class RDoc::Markup::AttributeManager
# optimistic
#++
- A_PROTECT = 004 # :nodoc:
+ A_PROTECT = 004 # :nodoc:
- PROTECT_ATTR = A_PROTECT.chr # :nodoc:
+ ##
+ # Special mask character to prevent inline markup handling
+
+ PROTECT_ATTR = A_PROTECT.chr # :nodoc:
##
# This maps delimiters that occur around words (such as *bold* or +tt+)
View
160 lib/rdoc/markup/formatter_test_case.rb
@@ -5,6 +5,16 @@
# Test case for creating new RDoc::Markup formatters. See
# test/test_rdoc_markup_to_*.rb for examples.
#
+# This test case adds a variety of tests to your subclass when
+# #add_visitor_tests is called. Most tests set up a scenario then call a
+# method you will provide to perform the assertion on the output.
+#
+# Your subclass must instantiate a visitor and assign it to <tt>@to</tt>.
+#
+# For example, test_accept_blank_line sets up a RDoc::Markup::BlockLine then
+# calls accept_blank_line on your visitor. You are responsible for asserting
+# that the output is correct.
+#
# Example:
#
# class TestRDocMarkupToNewFormat < RDoc::Markup::FormatterTestCase
@@ -76,14 +86,21 @@ def setup
# Call to add the visitor tests to your test case
def self.add_visitor_tests
- # :stopdoc:
self.class_eval do
+
+ ##
+ # Calls start_accepting which needs to verify startup state
+
def test_start_accepting
@to.start_accepting
start_accepting
end
+ ##
+ # Calls end_accepting on your test case which needs to call
+ # <tt>@to.end_accepting</tt> and verify document generation
+
def test_end_accepting
@to.start_accepting
@to.res << 'hi'
@@ -91,6 +108,9 @@ def test_end_accepting
end_accepting
end
+ ##
+ # Calls accept_blank_line
+
def test_accept_blank_line
@to.start_accepting
@@ -99,6 +119,9 @@ def test_accept_blank_line
accept_blank_line
end
+ ##
+ # Calls accept_heading with a level 5 RDoc::Markup::Heading
+
def test_accept_heading
@to.start_accepting
@@ -107,6 +130,9 @@ def test_accept_heading
accept_heading
end
+ ##
+ # Calls accept_heading_1 with a level 1 RDoc::Markup::Heading
+
def test_accept_heading_1
@to.start_accepting
@@ -115,6 +141,9 @@ def test_accept_heading_1
accept_heading_1
end
+ ##
+ # Calls accept_heading_2 with a level 2 RDoc::Markup::Heading
+
def test_accept_heading_2
@to.start_accepting
@@ -123,7 +152,11 @@ def test_accept_heading_2
accept_heading_2
end
+ ##
+ # Calls accept_heading_3 with a level 3 RDoc::Markup::Heading
+
def test_accept_heading_3
+ # HACK this doesn't belong here
skip "No String#chars, upgrade your ruby" unless ''.respond_to? :chars
@to.start_accepting
@@ -133,6 +166,9 @@ def test_accept_heading_3
accept_heading_3
end
+ ##
+ # Calls accept_heading_4 with a level 4 RDoc::Markup::Heading
+
def test_accept_heading_4
@to.start_accepting
@@ -141,6 +177,9 @@ def test_accept_heading_4
accept_heading_4
end
+ ##
+ # Calls accept_heading_b with a bold level 1 RDoc::Markup::Heading
+
def test_accept_heading_b
@to.start_accepting
@@ -149,6 +188,10 @@ def test_accept_heading_b
accept_heading_b
end
+ ##
+ # Calls accept_heading_suppressed_crossref with a level 1
+ # RDoc::Markup::Heading containing a suppressed crossref
+
def test_accept_heading_suppressed_crossref # HACK to_html_crossref test
@to.start_accepting
@@ -157,6 +200,9 @@ def test_accept_heading_suppressed_crossref # HACK to_html_crossref test
accept_heading_suppressed_crossref
end
+ ##
+ # Calls accept_paragraph
+
def test_accept_paragraph
@to.start_accepting
@@ -165,6 +211,10 @@ def test_accept_paragraph
accept_paragraph
end
+ ##
+ # Calls accept_paragraph_b with a RDoc::Markup::Paragraph containing
+ # bold words
+
def test_accept_paragraph_b
@to.start_accepting
@@ -173,6 +223,10 @@ def test_accept_paragraph_b
accept_paragraph_b
end
+ ##
+ # Calls accept_paragraph_i with a RDoc::Markup::Paragraph containing
+ # emphasized words
+
def test_accept_paragraph_i
@to.start_accepting
@@ -181,6 +235,10 @@ def test_accept_paragraph_i
accept_paragraph_i
end
+ ##
+ # Calls accept_paragraph_plus with a RDoc::Markup::Paragraph containing
+ # teletype words
+
def test_accept_paragraph_plus
@to.start_accepting
@@ -189,6 +247,10 @@ def test_accept_paragraph_plus
accept_paragraph_plus
end
+ ##
+ # Calls accept_paragraph_star with a RDoc::Markup::Paragraph containing
+ # bold words
+
def test_accept_paragraph_star
@to.start_accepting
@@ -197,6 +259,10 @@ def test_accept_paragraph_star
accept_paragraph_star
end
+ ##
+ # Calls accept_paragraph_underscore with a RDoc::Markup::Paragraph
+ # containing emphasized words
+
def test_accept_paragraph_underscore
@to.start_accepting
@@ -205,6 +271,9 @@ def test_accept_paragraph_underscore
accept_paragraph_underscore
end
+ ##
+ # Calls accept_verbatim with a RDoc::Markup::Verbatim
+
def test_accept_verbatim
@to.start_accepting
@@ -213,6 +282,9 @@ def test_accept_verbatim
accept_verbatim
end
+ ##
+ # Calls accept_raw with a RDoc::Markup::Raw
+
def test_accept_raw
@to.start_accepting
@@ -225,6 +297,9 @@ def test_accept_raw
accept_raw
end
+ ##
+ # Calls accept_rule with a RDoc::Markup::Rule
+
def test_accept_rule
@to.start_accepting
@@ -233,6 +308,9 @@ def test_accept_rule
accept_rule
end
+ ##
+ # Calls accept_list_item_start_bullet
+
def test_accept_list_item_start_bullet
@to.start_accepting
@@ -243,6 +321,9 @@ def test_accept_list_item_start_bullet
accept_list_item_start_bullet
end
+ ##
+ # Calls accept_list_item_start_label
+
def test_accept_list_item_start_label
@to.start_accepting
@@ -253,6 +334,9 @@ def test_accept_list_item_start_label
accept_list_item_start_label
end
+ ##
+ # Calls accept_list_item_start_lalpha
+
def test_accept_list_item_start_lalpha
@to.start_accepting
@@ -263,6 +347,9 @@ def test_accept_list_item_start_lalpha
accept_list_item_start_lalpha
end
+ ##
+ # Calls accept_list_item_start_note
+
def test_accept_list_item_start_note
@to.start_accepting
@@ -273,6 +360,9 @@ def test_accept_list_item_start_note
accept_list_item_start_note
end
+ ##
+ # Calls accept_list_item_start_note_2
+
def test_accept_list_item_start_note_2
list = @RM::List.new(:NOTE,
@RM::ListItem.new('<tt>teletype</tt>',
@@ -287,6 +377,9 @@ def test_accept_list_item_start_note_2
accept_list_item_start_note_2
end
+ ##
+ # Calls accept_list_item_start_number
+
def test_accept_list_item_start_number
@to.start_accepting
@@ -297,6 +390,9 @@ def test_accept_list_item_start_number
accept_list_item_start_number
end
+ ##
+ # Calls accept_list_item_start_ualpha
+
def test_accept_list_item_start_ualpha
@to.start_accepting
@@ -307,6 +403,9 @@ def test_accept_list_item_start_ualpha
accept_list_item_start_ualpha
end
+ ##
+ # Calls accept_list_item_end_bullet
+
def test_accept_list_item_end_bullet
@to.start_accepting
@@ -319,6 +418,9 @@ def test_accept_list_item_end_bullet
accept_list_item_end_bullet
end
+ ##
+ # Calls accept_list_item_end_label
+
def test_accept_list_item_end_label
@to.start_accepting
@@ -331,6 +433,9 @@ def test_accept_list_item_end_label
accept_list_item_end_label
end
+ ##
+ # Calls accept_list_item_end_lalpha
+
def test_accept_list_item_end_lalpha
@to.start_accepting
@@ -343,6 +448,9 @@ def test_accept_list_item_end_lalpha
accept_list_item_end_lalpha
end
+ ##
+ # Calls accept_list_item_end_note
+
def test_accept_list_item_end_note
@to.start_accepting
@@ -355,6 +463,9 @@ def test_accept_list_item_end_note
accept_list_item_end_note
end
+ ##
+ # Calls accept_list_item_end_number
+
def test_accept_list_item_end_number
@to.start_accepting
@@ -367,6 +478,9 @@ def test_accept_list_item_end_number
accept_list_item_end_number
end
+ ##
+ # Calls accept_list_item_end_ualpha
+
def test_accept_list_item_end_ualpha
@to.start_accepting
@@ -379,6 +493,9 @@ def test_accept_list_item_end_ualpha
accept_list_item_end_ualpha
end
+ ##
+ # Calls accept_list_start_bullet
+
def test_accept_list_start_bullet
@to.start_accepting
@@ -387,6 +504,9 @@ def test_accept_list_start_bullet
accept_list_start_bullet
end
+ ##
+ # Calls accept_list_start_label
+
def test_accept_list_start_label
@to.start_accepting
@@ -395,6 +515,9 @@ def test_accept_list_start_label
accept_list_start_label
end
+ ##
+ # Calls accept_list_start_lalpha
+
def test_accept_list_start_lalpha
@to.start_accepting
@@ -403,6 +526,9 @@ def test_accept_list_start_lalpha
accept_list_start_lalpha
end
+ ##
+ # Calls accept_list_start_note
+
def test_accept_list_start_note
@to.start_accepting
@@ -411,6 +537,9 @@ def test_accept_list_start_note
accept_list_start_note
end
+ ##
+ # Calls accept_list_start_number
+
def test_accept_list_start_number
@to.start_accepting
@@ -419,6 +548,9 @@ def test_accept_list_start_number
accept_list_start_number
end
+ ##
+ # Calls accept_list_start_ualpha
+
def test_accept_list_start_ualpha
@to.start_accepting
@@ -427,6 +559,9 @@ def test_accept_list_start_ualpha
accept_list_start_ualpha
end
+ ##
+ # Calls accept_list_end_bullet
+
def test_accept_list_end_bullet
@to.start_accepting
@@ -437,6 +572,9 @@ def test_accept_list_end_bullet
accept_list_end_bullet
end
+ ##
+ # Calls accept_list_end_label
+
def test_accept_list_end_label
@to.start_accepting
@@ -447,6 +585,9 @@ def test_accept_list_end_label
accept_list_end_label
end
+ ##
+ # Calls accept_list_end_lalpha
+
def test_accept_list_end_lalpha
@to.start_accepting
@@ -457,6 +598,9 @@ def test_accept_list_end_lalpha
accept_list_end_lalpha
end
+ ##
+ # Calls accept_list_end_number
+
def test_accept_list_end_number
@to.start_accepting
@@ -467,6 +611,9 @@ def test_accept_list_end_number
accept_list_end_number
end
+ ##
+ # Calls accept_list_end_note
+
def test_accept_list_end_note
@to.start_accepting
@@ -477,6 +624,9 @@ def test_accept_list_end_note
accept_list_end_note
end
+ ##
+ # Calls accept_list_end_ulpha
+
def test_accept_list_end_ualpha
@to.start_accepting
@@ -487,6 +637,9 @@ def test_accept_list_end_ualpha
accept_list_end_ualpha
end
+ ##
+ # Calls list_nested with a two-level list
+
def test_list_nested
doc = @RM::Document.new(
@RM::List.new(:BULLET,
@@ -503,6 +656,9 @@ def test_list_nested
list_nested
end
+ ##
+ # Calls list_verbatim with a list containing a verbatim block
+
def test_list_verbatim # HACK overblown
doc = @RM::Document.new(
@RM::List.new(:BULLET,
@@ -525,7 +681,7 @@ def test_list_verbatim # HACK overblown
list_verbatim
end
- # :stopdoc:
+
end
end
View
167 lib/rdoc/markup/to_html.rb
@@ -2,13 +2,14 @@
require 'rdoc/markup/inline'
require 'cgi'
-require 'strscan'
##
# Outputs RDoc markup as HTML
class RDoc::Markup::ToHtml < RDoc::Markup::Formatter
+ include RDoc::Text
+
##
# Maps RDoc::Markup::Parser::LIST_TOKENS types to HTML tags
@@ -124,7 +125,7 @@ def handle_special_HYPERLINK(special)
##
# Here's a hypedlink where the label is different to the URL
- # <label>[url] or {long label}[url]
+ # <label>[url] or {long label}[url]
def handle_special_TIDYLINK(special)
text = special.text
@@ -139,7 +140,7 @@ def handle_special_TIDYLINK(special)
# :section: Utilities
##
- # This is a higher speed (if messier) version of wrap
+ # Wraps +txt+ to +line_len+
def wrap(txt, line_len = 76)
res = []
@@ -172,40 +173,61 @@ def wrap(txt, line_len = 76)
# :section: Visitor
+ ##
+ # Prepares the visitor for HTML generation
+
def start_accepting
@res = []
@in_list_entry = []
@list = []
end
+ ##
+ # Returns the generated output
+
def end_accepting
@res.join
end
+ ##
+ # Adds +paragraph+ to the output
+
def accept_paragraph(paragraph)
@res << "\n<p>"
@res << wrap(to_html(paragraph.text))
@res << "</p>\n"
end
+ ##
+ # Adds +verbatim+ to the output
+
def accept_verbatim(verbatim)
@res << "\n<pre>"
@res << CGI.escapeHTML(verbatim.text.rstrip)
@res << "</pre>\n"
end
+ ##
+ # Adds +rule+ to the output
+
def accept_rule(rule)
size = rule.weight
size = 10 if size > 10
@res << "<hr style=\"height: #{size}px\">\n"
end
+ ##
+ # Prepares the visitor for consuming +list+
+
def accept_list_start(list)
@list << list.type
@res << html_list_name(list.type, true)
@in_list_entry.push false
end
+ ##
+ # Finishes consumption of +list+
+
def accept_list_end(list)
@list.pop
if tag = @in_list_entry.pop
@@ -214,6 +236,9 @@ def accept_list_end(list)
@res << html_list_name(list.type, false) << "\n"
end
+ ##
+ # Prepares the visitor for consuming +list_item+
+
def accept_list_item_start(list_item)
if tag = @in_list_entry.last
@res << tag
@@ -222,35 +247,45 @@ def accept_list_item_start(list_item)
@res << list_item_start(list_item, @list.last)
end
+ ##
+ # Finishes consumption of +list_item+
+
def accept_list_item_end(list_item)
@in_list_entry[-1] = list_end_for(@list.last)
end
+ ##
+ # Adds +blank_line+ to the output
+
def accept_blank_line(blank_line)
# @res << annotate("<p />") << "\n"
end
+ ##
+ # Adds +heading+ to the output
+
def accept_heading(heading)
@res << "\n<h#{heading.level}>"
@res << to_html(heading.text)
@res << "</h#{heading.level}>\n"
end
+ ##
+ # Adds +raw+ to the output
+
def accept_raw raw
@res << raw.parts.join("\n")
end
- private
-
##
- # Converts string +item+
+ # CGI escapes +text+
- def convert_string(item)
- CGI.escapeHTML item
+ def convert_string(text)
+ CGI.escapeHTML text
end
##
- # Determins the HTML list element for +list_type+ and +open_tag+
+ # Determines the HTML list element for +list_type+ and +open_tag+
def html_list_name(list_type, open_tag)
tags = LIST_TYPE_TO_HTML[list_type]
@@ -259,23 +294,24 @@ def html_list_name(list_type, open_tag)
end
##
- # Starts a list item
+ # Returns the HTML tag for +list_type+, possible using a label from
+ # +list_item+
def list_item_start(list_item, list_type)
case list_type
when :BULLET, :LALPHA, :NUMBER, :UALPHA then
"<li>"
when :LABEL then
- "<dt>" << to_html(list_item.label) << "</dt>\n<dd>"
+ "<dt>#{to_html list_item.label}</dt>\n<dd>"
when :NOTE then
- '<tr><td class="rdoc-term"><p>' + to_html(list_item.label) + "</p></td>\n<td>"
+ "<tr><td class=\"rdoc-term\"><p>#{to_html list_item.label}</p></td>\n<td>"
else
raise RDoc::Error, "Invalid list type: #{list_type.inspect}"
end
end
##
- # Ends a list item
+ # Returns the HTML end-tag for +list_type+
def list_end_for(list_type)
case list_type
@@ -291,109 +327,10 @@ def list_end_for(list_type)
end
##
- # Converts ampersand, dashes, ellipsis, quotes, copyright and registered
- # trademark symbols to HTML escaped Unicode.
- #--
- # TODO transcode when the output encoding is not UTF-8
-
- def to_html(text)
- html = ''
- s = StringScanner.new convert_flow @am.flow text
- insquotes = false
- indquotes = false
- after_word = nil
-
-#p :start => s
-
- until s.eos? do
- case
- # skip HTML tags
- when s.scan(/<[^>]+\/?s*>/)
-#p "tag: #{s.matched}"
- html << s.matched
- # skip <tt>...</tt> sections
- if s.matched == '<tt>'
- if s.scan(/.*?<\/tt>/)
- html << s.matched.gsub('\\\\', '\\')
- else
- # TODO signal non-paired tags
- html << s.rest
- break
- end
- end
- # escape of \ not handled by RDoc::Markup::ToHtmlCrossref
- # \<non space> => <non space> (markup spec)
- when s.scan(/\\(\S)/)
-#p "backslashes: #{s.matched}"
- html << s[1]
- after_word = nil
- # ... => ellipses (.... => . + ellipses)
- when s.scan(/\.\.\.(\.?)/)
-#p "ellipses: #{s.matched}"
- html << s[1] << '&#8230;'
- after_word = nil
- # (c) => copyright
- when s.scan(/\(c\)/)
-#p "copyright: #{s.matched}"
- html << '&#169;'
- after_word = nil
- # (r) => registered trademark
- when s.scan(/\(r\)/)
-#p "trademark: #{s.matched}"
- html << '&#174;'
- after_word = nil
- # --- or -- => em-dash
- when s.scan(/---?/)
-#p "em-dash: #{s.matched}"
- html << '&#8212;'
- after_word = nil
- # double quotes
- when s.scan(/&quot;/) #"
-#p "dquotes: #{s.matched}"
- html << (indquotes ? '&#8221;' : '&#8220;')
- indquotes = !indquotes
- after_word = nil
- # faked double quotes
- when s.scan(/``/)
-#p "dquotes: #{s.matched}"
- html << '&#8220;' # opening
- after_word = nil
- when s.scan(/''/)
-#p "dquotes: #{s.matched}"
- html << '&#8221;' # closing
- after_word = nil
- # single quotes
- when s.scan(/'/) #'
-#p "squotes: #{s.matched}"
- if insquotes
- html << '&#8217;' # closing
- insquotes = false
- else
- # Mary's dog, my parents' house: do not start paired quotes
- if after_word
- html << '&#8217;' # closing
- else
- html << '&#8216;' # opening
- insquotes = true
- end
- end
- after_word = nil
- # none of the above: advance to the next potentially significant character
- else
- match = s.scan(/.+?(?=[-<\\\.\("'`&])/) #"
- if match
-#p "next: #{match}"
- html << match
- after_word = match =~ /\w$/
- else
-#p "rest: #{s.rest}"
- html << s.rest
- break
- end
- end
- end
+ # Converts +item+ to HTML using RDoc::Text#to_html
- html
+ def to_html item
+ super convert_flow @am.flow item
end
end
View
75 lib/rdoc/markup/to_rdoc.rb
@@ -6,12 +6,39 @@
class RDoc::Markup::ToRdoc < RDoc::Markup::Formatter
+ ##
+ # Current indent amount for output in characters
+
attr_accessor :indent
+
+ ##
+ # Output width in characters
+
attr_accessor :width
+
+ ##
+ # Stack of current list indexes for alphabetic and numeric lists
+
attr_reader :list_index
+
+ ##
+ # Stack of list types
+
attr_reader :list_type
+
+ ##
+ # Stack of list widths for indentation
+
attr_reader :list_width
+
+ ##
+ # Prefix for the next list item. See #use_prefix
+
attr_reader :prefix
+
+ ##
+ # Output accumulator
+
attr_reader :res
##
@@ -36,7 +63,7 @@ def initialize
end
##
- # Maps attributes to ANSI sequences
+ # Maps attributes to HTML sequences
def init_tags
add_tag :BOLD, "<b>", "</b>"
@@ -44,10 +71,16 @@ def init_tags
add_tag :EM, "<em>", "</em>"
end
+ ##
+ # Adds +blank_line+ to the output
+
def accept_blank_line blank_line
@res << "\n"
end
+ ##
+ # Adds +heading+ to the output
+
def accept_heading heading
use_prefix or @res << ' ' * @indent
@res << @headings[heading.level][0]
@@ -56,12 +89,18 @@ def accept_heading heading
@res << "\n"
end
+ ##
+ # Finishes consumption of +list+
+
def accept_list_end list
@list_index.pop
@list_type.pop
@list_width.pop
end
+ ##
+ # Finishes consumption of +list_item+
+
def accept_list_item_end list_item
width = case @list_type.last
when :BULLET then
@@ -78,6 +117,9 @@ def accept_list_item_end list_item
@indent -= width
end
+ ##
+ # Prepares the visitor for consuming +list_item+
+
def accept_list_item_start list_item
type = @list_type.last
@@ -95,6 +137,9 @@ def accept_list_item_start list_item
end
end
+ ##
+ # Prepares the visitor for consuming +list+
+
def accept_list_start list
case list.type
when :BULLET then
@@ -119,14 +164,23 @@ def accept_list_start list
@list_type << list.type
end
+ ##
+ # Adds +paragraph+ to the output
+
def accept_paragraph paragraph
wrap attributes(paragraph.text)
end
+ ##
+ # Adds +raw+ to the output
+
def accept_raw raw
@res << raw.parts.join("\n")
end
+ ##
+ # Adds +rule+ to the output
+
def accept_rule rule
use_prefix or @res << ' ' * @indent
@res << '-' * (@width - @indent)
@@ -147,21 +201,33 @@ def accept_verbatim verbatim
@res << "\n" unless @res =~ /\n\z/
end
+ ##
+ # Applies attribute-specific markup to +text+ using RDoc::AttributeManager
+
def attributes text
flow = @am.flow text.dup
convert_flow flow
end
+ ##
+ # Returns the generated output
+
def end_accepting
@res.join
end
+ ##
+ # Removes preceeding \\ from the suppressed crossref +special+
+
def handle_special_SUPPRESSED_CROSSREF special
text = special.text
text = text.sub('\\', '') unless in_tt?
text
end
+ ##
+ # Prepares the visitor for text generation
+
def start_accepting
@res = [""]
@indent = 0
@@ -172,6 +238,10 @@ def start_accepting
@list_width = []
end
+ ##
+ # Adds the stored #prefix to the output and clears it. Lists generate a
+ # prefix for later consumption.
+
def use_prefix
prefix = @prefix
@prefix = nil
@@ -180,6 +250,9 @@ def use_prefix
prefix
end
+ ##
+ # Wraps +text+ to #width
+
def wrap text
return unless text && !text.empty?
View
8 lib/rdoc/options.rb
@@ -101,7 +101,7 @@ class RDoc::Options
##
# If true, only report on undocumented files
- attr_accessor :only_undocumented
+ attr_accessor :coverage_report
##
# The name of the output directory
@@ -178,7 +178,7 @@ def initialize # :nodoc:
@hyperlink_all = false
@line_numbers = false
@main_page = nil
- @only_undocumented = false
+ @coverage_report = false
@op_dir = nil
@pipe = false
@rdoc_include = []
@@ -422,10 +422,10 @@ def parse(argv)
opt.separator nil
- opt.on("--[no-]only-undocumented", "-u",
+ opt.on("--[no-]coverage-report", "--[no-]dcov", "-C",
"Prints a report on undocumented items.",
"Does not generate files.") do |value|
- @only_undocumented = value
+ @coverage_report = value
@force_update = true if value
end
View
31 lib/rdoc/parser.rb
@@ -43,7 +43,15 @@ class RDoc::Parser
@parsers = []
class << self
+
+ ##
+ # A Hash that maps file exetensions regular expressions to parsers that
+ # will consume them.
+ #
+ # Use parse_files_matching to register a parser's file extensions.
+
attr_reader :parsers
+
end
##
@@ -93,6 +101,29 @@ def self.binary?(file)
end
##
+ # Processes common directives for CodeObjects for the C and Ruby parsers.
+ #
+ # Applies +directive+'s +value+ to +code_object+, if appropriate
+
+ def self.process_directive code_object, directive, value
+ case directive
+ when 'nodoc' then
+ code_object.document_self = nil # notify nodoc
+ code_object.document_children = value.downcase != 'all'
+ when 'doc' then
+ code_object.document_self = true
+ code_object.force_documentation = true
+ when 'yield', 'yields' then
+ # remove parameter &block
+ code_object.params.sub!(/,?\s*&\w+/, '') if code_object.params
+
+ code_object.block_params = value
+ when 'arg', 'args' then
+ code_object.params = value
+ end
+ end
+
+ ##
# Checks if +file+ is a zip file in disguise. Signatures from
# http://www.garykessler.net/library/file_sigs.html
View
135 lib/rdoc/parser/c.rb
@@ -137,6 +137,9 @@ def initialize(top_level, file_name, content, options, stats)
@file_dir = File.dirname(@file_name)
end
+ ##
+ # Scans #content for rb_define_alias
+
def do_aliases
@content.scan(/rb_define_alias\s*\(
\s*(\w+),
@@ -158,6 +161,9 @@ def do_aliases
end
end
+ ##
+ # Scans #content for rb_attr and rb_define_attr
+
def do_attrs
@content.scan(/rb_attr\s*\(
\s*(\w+),
@@ -178,6 +184,10 @@ def do_attrs
end
end
+ ##
+ # Scans #content for rb_define_module, rb_define_class, boot_defclass,
+ # rb_define_module_under, rb_define_class_under and rb_singleton_class
+
def do_classes
@content.scan(/(\w+)\s* = \s*rb_define_module\s*\(\s*"(\w+)"\s*\)/mx) do
|var_name, class_name|
@@ -224,6 +234,10 @@ def do_classes
end
end
+ ##
+ # Scans #content for rb_define_variable, rb_define_readonly_variable,
+ # rb_define_const and rb_define_global_const
+
def do_constants
@content.scan(%r%\Wrb_define_
( variable |
@@ -241,9 +255,7 @@ def do_constants
end
##
- # Look for includes of the form:
- #
- # rb_include_module(rb_cArray, rb_mEnumerable);
+ # Scans #content for rb_include_module
def do_includes
@content.scan(/rb_include_module\s*\(\s*(\w+?),\s*(\w+?)\s*\)/) do |c,m|
@@ -254,6 +266,11 @@ def do_includes
end
end
+ ##
+ # Scans #content for rb_define_method, rb_define_singleton_method,
+ # rb_define_module_function, rb_define_private_method,
+ # rb_define_global_function and define_filetest_function
+
def do_methods
@content.scan(%r%rb_define_
(
@@ -300,6 +317,10 @@ def do_methods
end
end
+ ##
+ # Finds the comment for an alias on +class_name+ from +new_name+ to
+ # +old_name+
+
def find_alias_comment class_name, new_name, old_name
content =~ %r%((?>/\*.*?\*/\s+))
rb_define_alias\(\s*#{Regexp.escape class_name}\s*,
@@ -412,6 +433,9 @@ def find_body(class_name, meth_name, meth_obj, body, quiet = false)
true
end
+ ##
+ # Finds a RDoc::NormalClass or RDoc::NormalModule for +raw_name+
+
def find_class(raw_name, name)
unless @classes[raw_name]
if raw_name =~ /^rb_m/
@@ -497,41 +521,31 @@ def find_const_comment(type, const_name)
end
##
- # If the comment block contains a section that looks like:
+ # Handles modifiers in +comment+ and updates +meth_obj+ as appropriate.
#
- # call-seq:
- # Array.new
- # Array.new(10)
+ # If <tt>:nodoc:</tt> is found, documentation on +meth_obj+ is suppressed.
#
- # use it for the parameters.
-
- def find_modifiers(comment, meth_obj)
- if comment.sub!(/:nodoc:\s*^\s*\*?\s*$/m, '') or
- comment.sub!(/\A\/\*\s*:nodoc:\s*\*\/\Z/, '') then
- meth_obj.document_self = nil # notify nodoc
- end
+ # If <tt>:yields:</tt> is followed by an argument list it is used for the
+ # #block_params of +meth_obj+.
+ #
+ # If the comment block contains a <tt>call-seq:</tt> section like:
+ #
+ # call-seq:
+ # ARGF.readlines(sep=$/) -> array
+ # ARGF.readlines(limit) -> array
+ # ARGF.readlines(sep, limit) -> array
+ #
+ # ARGF.to_a(sep=$/) -> array
+ # ARGF.to_a(limit) -> array
+ # ARGF.to_a(sep, limit) -> array
+ #
+ # it is used for the parameters of +meth_obj+.
- # we must handle situations like this:
- # /*
- # * call-seq:
- # * ARGF.readlines(sep=$/) -> array
- # * ARGF.readlines(limit) -> array
- # * ARGF.readlines(sep, limit) -> array
- # *
- # * ARGF.to_a(sep=$/) -> array
- # * ARGF.to_a(limit) -> array
- # * ARGF.to_a(sep, limit) -> array
- # *
- # * Reads +ARGF+'s current file in its entirety, returning an +Array+
- # * of its lines, one line per element. Lines are assumed to be
- # * separated by _sep_.
- # *
- # * lines = ARGF.readlines
- # * lines[0] #=> "This is line one\n"
- # */
- #
- # the difficulty is to make sure not to match lines starting with ARGF at
- # the same indent, but that are after the first description paragraph.
+ def find_modifiers comment, meth_obj
+ # we must handle situations like the above followed by an unindented first
+ # comment. The difficulty is to make sure not to match lines starting
+ # with ARGF at the same indent, but that are after the first description
+ # paragraph.
if comment =~ /call-seq:(.*?[^\s\*].*?)^\s*\*?\s*$/m then
all_start, all_stop = $~.offset(0)
@@ -561,8 +575,15 @@ def find_modifiers(comment, meth_obj)
elsif comment.sub!(/\A\/\*\s*call-seq:(.*?)\*\/\Z/, '') then
meth_obj.call_seq = $1.strip
end
+
+ if comment.sub!(/\s*:(nodoc|doc|yields?|args?):\s*(.*)/, '') then
+ RDoc::Parser.process_directive meth_obj, $1, $2
+ end
end
+ ##
+ # Finds a <tt>Document-method</tt> override for +meth_name+ in +class_name+
+
def find_override_comment(class_name, meth_name)
name = Regexp.escape(meth_name)
@@ -573,6 +594,10 @@ def find_override_comment(class_name, meth_name)
end
end
+ ##
+ # Creates a new RDoc::Attr +attr_name+ on class +var_name+ that is either
+ # +read+, +write+ or both
+
def handle_attr(var_name, attr_name, read, write)
rw = ''
rw << 'R' if '1' == read
@@ -594,9 +619,13 @@ def handle_attr(var_name, attr_name, read, write)
attr = RDoc::Attr.new '', name, rw, comment
class_obj.add_attribute attr
- @stats.add_method attr
+ @stats.add_attribute attr
end
+ ##
+ # Creates a new RDoc::NormalClass or RDoc::NormalModule based on +type+
+ # named +class_name+ in +parent+ which was assigned to the C +var_name+.
+
def handle_class_module(var_name, type, class_name, parent, in_module)
parent_name = @known_classes[parent] || parent
@@ -646,15 +675,14 @@ def handle_class_module(var_name, type, class_name, parent, in_module)
end
##
- # Adds constant comments. By providing some_value: at the start ofthe
- # comment you can override the C value of the comment to give a friendly
- # definition.
+ # Adds constants. By providing some_value: at the start of the comment you
+ # can override the C value of the comment to give a friendly definition.
#
# /* 300: The perfect score in bowling */
# rb_define_const(cFoo, "PERFECT", INT2FIX(300);
#
- # Will override +INT2FIX(300)+ with the value +300+ in the output RDoc.
- # Values may include quotes and escaped colons (\:).
+ # Will override <tt>INT2FIX(300)</tt> with the value +300+ in the output
+ # RDoc. Values may include quotes and escaped colons (\:).
def handle_constants(type, var_name, const_name, definition)
class_name = @known_classes[var_name]
@@ -715,6 +743,11 @@ def handle_ifdefs_in(body)
body.gsub(/^#ifdef HAVE_PROTOTYPES.*?#else.*?\n(.*?)#endif.*?\n/m, '\1')
end
+ ##
+ # Adds an RDoc::AnyMethod +meth_name+ defined on a class or module assigned
+ # to +var_name+. +type+ is the type of method definition function used.
+ # +singleton_method+ and +module_function+ create a singleton method.
+
def handle_method(type, var_name, meth_name, meth_body, param_count,
source_file = nil)
singleton = false
@@ -771,19 +804,27 @@ def handle_method(type, var_name, meth_name, meth_body, param_count,
end
end
+ ##
+ # Registers a singleton class +sclass_var+ as a singleton of +class_var+
+
def handle_singleton sclass_var, class_var
class_name = @known_classes[class_var]
@singleton_classes[sclass_var] = class_name
end
+ ##
+ # Normalizes tabs in +body+
+
def handle_tab_width(body)
if /\t/ =~ body
tab_width = @options.tab_width
body.split(/\n/).map do |line|
- 1 while line.gsub!(/\t+/) { ' ' * (tab_width*$&.length - $`.length % tab_width)} && $~ #`
+ 1 while line.gsub!(/\t+/) do
+ ' ' * (tab_width * $&.length - $`.length % tab_width)
+ end && $~
line
- end .join("\n")
+ end.join "\n"
else
body
end
@@ -814,6 +855,7 @@ def look_for_directives_in(context, comment)
comment
end
+
##
# Removes lines that are commented out that might otherwise get picked up
# when scanning for classes and methods
@@ -822,14 +864,17 @@ def remove_commented_out_lines
@content.gsub!(%r%//.*rb_define_%, '//')
end
+ ##
+ # Removes private comments from +comment+
+
def remove_private_comments(comment)
comment.gsub!(/\/?\*--\n(.*?)\/?\*\+\+/m, '')
comment.sub!(/\/?\*--\n.*/m, '')
end
##
- # Extract the classes/modules and methods from a C file and return the
- # corresponding top-level object
+ # Extracts the classes, modules, methods, attributes, constants and aliases
+ # from a C file and returns an RDoc::TopLevel for this file
def scan
remove_commented_out_lines
View
165 lib/rdoc/parser/perl.rb
@@ -1,165 +0,0 @@
-require 'rdoc/parser'
-
-##
-#
-# This is an attamept to write a basic parser for Perl's
-# POD (Plain old Documentation) format. Ruby code must
-# co-exist with Perl, and some tasks are easier in Perl
-# than Ruby because of existing libraries.
-#
-# One difficult is that Perl POD has no means of identifying
-# the classes (packages) and methods (subs) with which it
-# is associated, it is more like literate programming in so
-# far as it just happens to be in the same place as the code,
-# but need not be.
-#
-# We would like to support all the markup the POD provides
-# so that it will convert happily to HTML. At the moment
-# I don't think I can do that: time constraints.
-#
-
-class RDoc::Parser::PerlPOD < RDoc::Parser
-
- parse_files_matching(/.p[lm]$/)
-
- ##
- # Prepare to parse a perl file
-
- def initialize(top_level, file_name, content, options, stats)
- super
-
- preprocess = RDoc::Markup::PreProcess.new @file_name, @options.rdoc_include
-
- preprocess.handle @content do |directive, param|
- warn "Unrecognized directive '#{directive}' in #{@file_name}"
- end
- end
-
- ##
- # Extract the Pod(-like) comments from the code.
- # At its most basic there will ne no need to distinguish
- # between the different types of header, etc.
- #
- # This uses a simple finite state machine, in a very
- # procedural pattern. I could "replace case with polymorphism"
- # but I think it would obscure the intent, scatter the
- # code all over tha place. This machine is necessary
- # because POD requires that directives be preceded by
- # blank lines, so reading line by line is necessary,
- # and preserving state about what is seen is necesary.
-
- def scan
-
- @top_level.comment ||= ""
- state=:code_blank
- line_number = 0
- line = nil
-
- # This started out as a really long nested case statement,
- # which also led to repetitive code. I'd like to avoid that
- # so I'm using a "table" instead.
-
- # Firstly we need some procs to do the transition and processing
- # work. Because these are procs they are closures, and they can
- # use variables in the local scope.
- #
- # First, the "nothing to see here" stuff.
- code_noop = lambda do
- if line =~ /^\s+$/
- state = :code_blank
- end
- end
-
- pod_noop = lambda do
- if line =~ /^\s+$/
- state = :pod_blank
- end
- @top_level.comment += filter(line)
- end
-
- begin_noop = lambda do
- if line =~ /^\s+$/
- state = :begin_blank
- end
- @top_level.comment += filter(line)
- end
-
- # Now for the blocks that process code and comments...
-
- transit_to_pod = lambda do
- case line
- when /^=(?:pod|head\d+)/
- state = :pod_no_blank
- @top_level.comment += filter(line)
- when /^=over/
- state = :over_no_blank
- @top_level.comment += filter(line)
- when /^=(?:begin|for)/
- state = :begin_no_blank
- end
- end
-
- process_pod = lambda do
- case line
- when /^\s*$/
- state = :pod_blank
- @top_level.comment += filter(line)
- when /^=cut/
- state = :code_no_blank
- when /^=end/
- $stderr.puts "'=end' unexpected at #{line_number} in #{@file_name}"
- else
- @top_level.comment += filter(line)
- end
- end
-
-
- process_begin = lambda do
- case line
- when /^\s*$/
- state = :begin_blank
- @top_level.comment += filter(line)
- when /^=end/
- state = :code_no_blank
- when /^=cut/
- $stderr.puts "'=cut' unexpected at #{line_number} in #{@file_name}"
- else
- @top_level.comment += filter(line)
- end
-
- end
-
-
- transitions = { :code_no_blank => code_noop,
- :code_blank => transit_to_pod,
- :pod_no_blank => pod_noop,
- :pod_blank => process_pod,
- :begin_no_blank => begin_noop,
- :begin_blank => process_begin}
- @content.each_line do |l|
- line = l
- line_number += 1
- transitions[state].call
- end # each line
-
- @top_level
- end
-
- # Filter the perl markup that does the same as the rdoc
- # filtering. Only basic for now. Will probably need a
- # proper parser to cope with C<<...>> etc
- def filter(comment)
- return '' if comment =~ /^=pod\s*$/
- comment.gsub!(/^=pod/, '==')
- comment.gsub!(/^=head(\d+)/) do
- "=" * $1.to_i
- end
- comment.gsub!(/=item/, '');
- comment.gsub!(/C<(.*?)>/, '<tt>\1</tt>');
- comment.gsub!(/I<(.*?)>/, '<i>\1</i>');
- comment.gsub!(/B<(.*?)>/, '<b>\1</b>');
- comment
- end
-
-end
-
View
130 lib/rdoc/parser/ruby.rb
@@ -162,6 +162,9 @@ class RDoc::Parser::Ruby < RDoc::Parser
SINGLE = "<<"
+ ##
+ # Creates a new Ruby parser.
+
def initialize(top_level, file_name, content, options, stats)
super
@@ -209,10 +212,13 @@ def collect_first_comment
comment
end
+ ##
+ # Aborts with +msg+
+
def error(msg)
msg = make_message msg
- $stderr.puts msg
- exit false
+
+ abort msg
end
##
@@ -229,6 +235,10 @@ def extract_call_seq(comment, meth)
meth
end
+ ##
+ # Looks for a true or false token. Returns false if TkFALSE or TkNIL are
+ # found.
+
def get_bool
skip_tkspace
tk = get_tk
@@ -352,6 +362,9 @@ def get_constant_with_optional_parens
name
end
+ ##
+ # Extracts a name or symbol from the token stream.
+
def get_symbol_or_name
tk = get_tk
case tk
@@ -453,6 +466,8 @@ def parse_attr(context, single, tk, comment)
read_documentation_modifiers att, RDoc::ATTR_MODIFIERS
context.add_attribute att if att.document_self
+
+ @stats.add_attribute att
else
warn "'attr' ignored - looks like a variable"
end
@@ -483,9 +498,13 @@ def parse_attr_accessor(context, single, tk, comment)
att.record_location @top_level
context.add_attribute att
+ @stats.add_attribute att
end
end
+ ##
+ # Parses an +alias+ in +context+ with +comment+
+
def parse_alias(context, single, tk, comment)
skip_tkspace
@@ -521,6 +540,9 @@ def parse_alias(context, single, tk, comment)
al
end
+ ##
+ # Extracts call parameters from the token stream.
+
def parse_call_parameters(tk)
end_token = case tk
when TkLPAREN, TkfLPAREN
@@ -558,6 +580,9 @@ def parse_call_parameters(tk)
res
end
+ ##
+ # Parses a class in +context+ with +comment+
+
def parse_class(container, single, tk, comment)
declaration_context = container
container, name_t, given_name = get_class_or_module container
@@ -618,6 +643,9 @@ def parse_class(container, single, tk, comment)
end
end
+ ##
+ # Parses a constant in +context+ with +comment+
+
def parse_constant(container, tk, comment)
name = tk.name
skip_tkspace false
@@ -749,10 +777,13 @@ def parse_comment(container, tk, comment)
container.add_attribute att
- @stats.add_method att
+ @stats.add_attribute att
end
end
+ ##
+ # Parses an +include+ in +context+ with +comment+
+
def parse_include(context, comment)
loop do
skip_tkspace_comment
@@ -818,6 +849,7 @@ def parse_meta_attr(context, single, tk, comment)
att.record_location @top_level
context.add_attribute att
+ @stats.add_attribute att
else
args.each do |attr_name|
att = RDoc::Attr.new(get_tkread, attr_name, rw, comment,
@@ -825,6 +857,7 @@ def parse_meta_attr(context, single, tk, comment)
att.record_location @top_level
context.add_attribute att
+ @stats.add_attribute att
end
end
end
@@ -1050,6 +1083,9 @@ def parse_method(container, single, tk, comment)
@stats.add_method meth
end
+ ##
+ # Extracts +yield+ parameters from +method+
+
def parse_method_or_yield_parameters(method = nil,
modifiers = RDoc::METHOD_MODIFIERS)
skip_tkspace false
@@ -1131,6 +1167,9 @@ def parse_method_parameters(method)
end
end
+ ##
+ # Parses an RDoc::NormalModule in +container+ with +comment+
+
def parse_module(container, single, tk, comment)
container, name_t, = get_class_or_module container
@@ -1147,6 +1186,9 @@ def parse_module(container, single, tk, comment)
@stats.add_module mod
end
+ ##
+ # Parses an RDoc::Require in +context+ containing +comment+
+
def parse_require(context,