Permalink
Browse files

2.4.3

  • Loading branch information...
1 parent ad8d95a commit 9b7c6ca4305832c89bcb4b57f9a8d9543c0965ee @drbrain drbrain committed Apr 1, 2009
View
31 History.txt
@@ -1,3 +1,34 @@
+=== 2.4.3 / 2009-04-01
+
+* 2 Bug Fixes
+ * Corrected patch for file links
+ * Corrected display of file popup
+
+=== 2.4.2 / 2009-03-25
+
+* 2 Minor Enhancements
+ * Added --pipe for turning RDoc on stdin into HTML
+ * Added rdoc/task.rb containing a replacement for rake/rdoctask.rb. Use
+ RDoc::Task now instead of Rake::RDocTask.
+
+* 10 Bug Fixes
+ * Writing the ri cache file to the proper directory. Bug #24459 by Lars
+ Christensen.
+ * Possible fix for Dir::[] and Pathname interaction on 1.9. Bug #24650 by
+ tiburon.
+ * Fixed scanning constants for if/end, etc. pairs. Bug #24609 by Ryan
+ Davis.
+ * Fixed private methods in the C parser. Bug #24599 by Aaron Patterson.
+ * Fixed display of markup on RDoc main page. Bug #24168 by rhubarb.
+ * Fixed display of \\ character in documentation proceeding words.
+ Bug #22112 by James Gray. See RDoc for details.
+ * Fixed parsing and display of arg params for some corner cases. Bug #21113
+ by Csiszár Attila.
+ * Fixed links in Files box. Patch #24403 by Eric Wong.
+ * Toplevel methods now appear in Object. Bug #22677 by Ryan Davis.
+ * Added back --promiscuous which didn't do anything you cared about. Why
+ did you enable it? Nobody looked at that page! Oh, it warns, too.
+
=== 2.4.1 / 2009-02-26
* 1 Minor Enhancements
View
2 Manifest.txt
@@ -92,6 +92,7 @@ lib/rdoc/ri/util.rb
lib/rdoc/ri/writer.rb
lib/rdoc/single_class.rb
lib/rdoc/stats.rb
+lib/rdoc/task.rb
lib/rdoc/tokenstream.rb
lib/rdoc/top_level.rb
test/binary.dat
@@ -119,6 +120,7 @@ test/test_rdoc_ri_driver.rb
test/test_rdoc_ri_formatter.rb
test/test_rdoc_ri_html_formatter.rb
test/test_rdoc_ri_overstrike_formatter.rb
+test/test_rdoc_task.rb
test/test_rdoc_top_level.rb
test/xref_data.rb
test/xref_test_case.rb
View
2 Rakefile
@@ -11,9 +11,11 @@ Hoe.new "rdoc", RDoc::VERSION do |rdoc|
rdoc.developer 'Phil Hagelberg', 'technomancy@gmail.com'
rdoc.developer 'Tony Strauss', 'tony.strauss@designingpatterns.com'
rdoc.remote_rdoc_dir = ''
+ rdoc.testlib = :minitest
rdoc.extra_dev_deps << ['minitest', '~> 1.3']
rdoc.spec_extras['required_rubygems_version'] = '>= 1.3'
+ rdoc.spec_extras['homepage'] = 'http://rdoc.rubyforge.org'
end
# These tasks expect to have the following directory structure:
View
41 lib/rdoc.rb
@@ -61,6 +61,7 @@
# recursively for C and Ruby source files only.
#
# == \Options
+#
# rdoc can be passed a variety of command-line options. In addition,
# options can be specified via the +RDOCOPT+ environment variable, which
# functions similarly to the +RUBYOPT+ environment variable.
@@ -70,28 +71,15 @@
# will make rdoc default to inline method source code. Command-line options
# always will override those in +RDOCOPT+.
#
-# Run
+# Run:
#
-# % rdoc --help
+# rdoc --help
#
# for full details on rdoc's options.
#
-# Here are some of the most commonly used options.
-# [-d, --diagram]
-# Generate diagrams showing modules and
-# classes. You need dot V1.8.6 or later to
-# use the --diagram option correctly. Dot is
-# available from http://graphviz.org
-#
-# [-S, --inline-source]
-# Show method source code inline, rather than via a popup link.
-#
-# [-T, --template=NAME]
-# Set the template used when generating output.
-#
# == Documenting Source Code
#
-# Comment blocks can be written fairly naturally, either using +#+ on
+# Comment blocks can be written fairly naturally, either using <tt>#</tt> on
# successive lines of the comment, or by including the comment in
# a =begin/=end block. If you use the latter form, the =begin line must be
# flagged with an RDoc tag:
@@ -150,6 +138,11 @@
# +:yields:+ is an example of a documentation directive. These appear
# immediately after the start of the document element they are modifying.
#
+# RDoc automatically cross-references words with underscores or camel-case.
+# To suppress cross-references, prefix the word with a \\ character. To
+# include special characters like "\\n", you'll need to use two \\
+# characters like "\\\\\\n".
+#
# == \Markup
#
# * The markup engine looks for a document's natural left margin. This is
@@ -216,17 +209,17 @@
#
# Word-based markup uses flag characters around individual words:
#
-# [\*word*] displays word in a *bold* font
-# [\_word_] displays word in an _emphasized_ font
-# [\+word+] displays word in a +code+ font
+# [<tt>\*word*</tt>] displays word in a *bold* font
+# [<tt>\_word_</tt>] displays word in an _emphasized_ font
+# [<tt>\+word+</tt>] displays word in a +code+ font
#
# General markup affects text between a start delimiter and and end
# delimiter. Not surprisingly, these delimiters look like HTML markup.
#
-# [\<b>text...</b>] displays word in a *bold* font
-# [\<em>text...</em>] displays word in an _emphasized_ font
-# [\<i>text...</i>] displays word in an <i>italicized</i> font
-# [\<tt>text...</tt>] displays word in a +code+ font
+# [<tt>\<b>text...</b></tt>] displays word in a *bold* font
+# [<tt>\<em>text...</em></tt>] displays word in an _emphasized_ font
+# [<tt>\<i>text...</i></tt>] displays word in an <i>italicized</i> font
+# [<tt>\<tt>text...\</tt></tt>] displays word in a +code+ font
#
# Unlike conventional Wiki markup, general markup can cross line
# boundaries. You can turn off the interpretation of markup by
@@ -382,7 +375,7 @@ class Error < RuntimeError; end
##
# RDoc version you are using
- VERSION = "2.4.1"
+ VERSION = '2.4.3'
##
# Name of the dotfile that contains the description of files to be processed
View
2 lib/rdoc/context.rb
@@ -361,7 +361,7 @@ def add_include(include)
def add_method(method)
method.visibility = @visibility
- add_to(@method_list, method)
+ add_to @method_list, method
unmatched_alias_list = @unmatched_alias_lists[method.name]
if unmatched_alias_list then
View
2 lib/rdoc/generator/darkfish.rb
@@ -155,7 +155,7 @@ def write_style_sheet
FileUtils.cp @template_dir + 'rdoc.css', '.', options
- Dir[@template_dir + "{js,images}/**/*"].each do |path|
+ Dir[(@template_dir + "{js,images}/**/*").to_s].each do |path|
next if File.directory? path
next if path =~ /#{File::SEPARATOR}\./
View
2 lib/rdoc/generator/template/darkfish/classpage.rhtml
@@ -28,7 +28,7 @@
<div class="section-body">
<ul>
<% klass.in_files.each do |tl| %>
- <li><a href="<%= rel_prefix %>/<%= h tl.absolute_name %>.html?TB_iframe=true&amp;height=550&amp;width=785"
+ <li><a href="<%= rel_prefix %>/<%= h tl.path %>?TB_iframe=true&amp;height=550&amp;width=785"
class="thickbox" title="<%= h tl.absolute_name %>"><%= h tl.absolute_name %></a></li>
<% end %>
</ul>
View
4 lib/rdoc/generator/template/darkfish/filepage.rhtml
@@ -22,7 +22,7 @@
<% if file.parser == RDoc::Parser::Simple %>
<body class="file">
- <div id="metadata">
+ <div id="metadata">
<div id="project-metadata">
<% simple_files = @files.select { |f| f.parser == RDoc::Parser::Simple } %>
<% unless simple_files.empty? then %>
@@ -98,7 +98,9 @@
href="<%= file.cvs_url %>"><%= file.cvs_url %></a></dd>
<% end %>
</dl>
+ </div>
+ <div id="documentation">
<% if file.comment %>
<div class="description">
<h2>Description</h2>
View
4 lib/rdoc/markup/attribute_manager.rb
@@ -227,7 +227,7 @@ def flow(str)
unmask_protected_sequences
- return split_into_flow
+ split_into_flow
end
##
@@ -304,7 +304,7 @@ def split_into_flow
# and reset to all attributes off
res << change_attribute(current_attr, 0) if current_attr != 0
- return res
+ res
end
end
View
4 lib/rdoc/markup/to_html_crossref.rb
@@ -121,7 +121,9 @@ def handle_special_CROSSREF(special)
ref = @context.find_symbol lookup unless ref
- out = if lookup =~ /^\\/ then
+ out = if lookup == '\\' then
+ lookup
+ elsif lookup =~ /^\\/ then
$'
elsif ref and ref.document_self then
"<a href=\"#{ref.as_href(@from_path)}\">#{name}</a>"
View
230 lib/rdoc/options.rb
@@ -74,6 +74,11 @@ class RDoc::Options
attr_accessor :op_dir
##
+ # Is RDoc in pipe mode?
+
+ attr_accessor :pipe
+
+ ##
# Array of directories to search for files to satisfy an :include:
attr_reader :rdoc_include
@@ -127,6 +132,7 @@ def initialize # :nodoc:
@exclude = []
@generators = RDoc::RDoc::GENERATORS
@generator = RDoc::Generator::Darkfish
+ @generator_name = nil
@rdoc_include = []
@title = nil
@template = nil
@@ -143,6 +149,7 @@ def initialize # :nodoc:
@include_line_numbers = false
@force_update = true
@verbosity = 1
+ @pipe = false
@webcvs = nil
@@ -176,7 +183,7 @@ def parse(argv)
EOF
opt.separator nil
- opt.separator "Options:"
+ opt.separator "Parsing Options:"
opt.separator nil
opt.on("--all", "-a",
@@ -187,31 +194,6 @@ def parse(argv)
opt.separator nil
- opt.on("--charset=CHARSET", "-c",
- "Specifies the output HTML character-set.") do |value|
- @charset = value
- end
-
- opt.separator nil
-
- opt.on("--debug", "-D",
- "Displays lots on internal stuff.") do |value|
- $DEBUG_RDOC = value
- end
-
- opt.separator nil
-
- opt.on("--diagram", "-d",
- "Generate diagrams showing modules and",
- "classes. You need dot V1.8.6 or later to",
- "use the --diagram option correctly. Dot is",
- "available from http://graphviz.org") do |value|
- check_diagram
- @diagram = true
- end
-
- opt.separator nil
-
opt.on("--exclude=PATTERN", "-x", Regexp,
"Do not process files or directories",
"matching PATTERN.") do |value|
@@ -237,18 +219,6 @@ def parse(argv)
opt.separator nil
- opt.on("--fileboxes", "-F",
- "Classes are put in boxes which represents",
- "files, where these classes reside. Classes",
- "shared between more than one file are",
- "shown with list of files that are sharing",
- "them. Silently discarded if --diagram is",
- "not given.") do |value|
- @fileboxes = value
- end
-
- opt.separator nil
-
opt.on("--force-update", "-U",
"Forces rdoc to scan all sources even if",
"newer than the flag file.") do |value|
@@ -257,6 +227,29 @@ def parse(argv)
opt.separator nil
+ opt.on("--pipe",
+ "Convert RDoc on stdin to HTML") do
+ @pipe = true
+ end
+
+ opt.separator nil
+
+ opt.on("--threads=THREADS", Integer,
+ "Number of threads to parse with.") do |threads|
+ @threads = threads
+ end
+
+ opt.separator nil
+ opt.separator "Generator Options:"
+ opt.separator nil
+
+ opt.on("--charset=CHARSET", "-c",
+ "Specifies the output HTML character-set.") do |value|
+ @charset = value
+ end
+
+ opt.separator nil
+
generator_text = @generators.keys.map { |name| " #{name}" }.sort
opt.on("--fmt=FORMAT", "--format=FORMAT", "-f", @generators.keys,
@@ -267,19 +260,8 @@ def parse(argv)
opt.separator nil
- image_formats = %w[gif png jpg jpeg]
- opt.on("--image-format=FORMAT", "-I", image_formats,
- "Sets output image format for diagrams. Can",
- "be #{image_formats.join ', '}. If this option",
- "is omitted, png is used. Requires",
- "diagrams.") do |value|
- @image_format = value
- end
-
- opt.separator nil
-
opt.on("--include=DIRECTORIES", "-i", Array,
- "set (or add to) the list of directories to",
+ "Set (or add to) the list of directories to",
"be searched when satisfying :include:",
"requests. Can be used more than once.") do |value|
@rdoc_include.concat value.map { |dir| dir.strip }
@@ -301,29 +283,94 @@ def parse(argv)
opt.separator nil
- opt.on("--merge", "-M",
- "When creating ri output, merge previously",
- "processed classes into previously",
- "documented classes of the same name.") do |value|
- @merge = value
+ opt.on("--output=DIR", "--op", "-o",
+ "Set the output directory.") do |value|
+ @op_dir = value
end
opt.separator nil
- opt.on("--output=DIR", "--op", "-o",
- "Set the output directory.") do |value|
- @op_dir = value
+ opt.on("--show-hash", "-H",
+ "A name of the form #name in a comment is a",
+ "possible hyperlink to an instance method",
+ "name. When displayed, the '#' is removed",
+ "unless this option is specified.") do |value|
+ @show_hash = value
end
opt.separator nil
- opt.on("--quiet", "-q",
- "Don't show progress as we parse.") do |value|
- @verbosity = 0
+ opt.on("--tab-width=WIDTH", "-w", OptionParser::DecimalInteger,
+ "Set the width of tab characters.") do |value|
+ @tab_width = value
+ end
+
+ opt.separator nil
+
+ opt.on("--template=NAME", "-T",
+ "Set the template used when generating",
+ "output.") do |value|
+ @template = value
end
opt.separator nil
+ opt.on("--title=TITLE", "-t",
+ "Set TITLE as the title for HTML output.") do |value|
+ @title = value
+ end
+
+ opt.separator nil
+
+ opt.on("--webcvs=URL", "-W",
+ "Specify a URL for linking to a web frontend",
+ "to CVS. If the URL contains a '\%s', the",
+ "name of the current file will be",
+ "substituted; if the URL doesn't contain a",
+ "'\%s', the filename will be appended to it.") do |value|
+ @webcvs = value
+ end
+
+ opt.separator nil
+ opt.separator "Diagram Options:"
+ opt.separator nil
+
+ image_formats = %w[gif png jpg jpeg]
+ opt.on("--image-format=FORMAT", "-I", image_formats,
+ "Sets output image format for diagrams. Can",
+ "be #{image_formats.join ', '}. If this option",
+ "is omitted, png is used. Requires",
+ "diagrams.") do |value|
+ @image_format = value
+ end
+
+ opt.separator nil
+
+ opt.on("--diagram", "-d",
+ "Generate diagrams showing modules and",
+ "classes. You need dot V1.8.6 or later to",
+ "use the --diagram option correctly. Dot is",
+ "available from http://graphviz.org") do |value|
+ check_diagram
+ @diagram = true
+ end
+
+ opt.separator nil
+
+ opt.on("--fileboxes", "-F",
+ "Classes are put in boxes which represents",
+ "files, where these classes reside. Classes",
+ "shared between more than one file are",
+ "shown with list of files that are sharing",
+ "them. Silently discarded if --diagram is",
+ "not given.") do |value|
+ @fileboxes = value
+ end
+
+ opt.separator nil
+ opt.separator "ri Generator Options:"
+ opt.separator nil
+
opt.on("--ri", "-r",
"Generate output for use by `ri`. The files",
"are stored in the '.rdoc' directory under",
@@ -349,70 +396,45 @@ def parse(argv)
opt.separator nil
- opt.on("--show-hash", "-H",
- "A name of the form #name in a comment is a",
- "possible hyperlink to an instance method",
- "name. When displayed, the '#' is removed",
- "unless this option is specified.") do |value|
- @show_hash = value
- end
-
- opt.separator nil
-
- opt.on("--tab-width=WIDTH", "-w", OptionParser::DecimalInteger,
- "Set the width of tab characters.") do |value|
- @tab_width = value
+ opt.on("--merge", "-M",
+ "When creating ri output, merge previously",
+ "processed classes into previously",
+ "documented classes of the same name.") do |value|
+ @merge = value
end
opt.separator nil
-
- opt.on("--template=NAME", "-T",
- "Set the template used when generating",
- "output.") do |value|
- @template = value
- end
-
+ opt.separator "Generic Options:"
opt.separator nil
- opt.on("--threads=THREADS", Integer,
- "Number of threads to parse with.") do |threads|
- @threads = threads
+ opt.on("--debug", "-D",
+ "Displays lots on internal stuff.") do |value|
+ $DEBUG_RDOC = value
end
- opt.separator nil
-
- opt.on("--title=TITLE", "-t",
- "Set TITLE as the title for HTML output.") do |value|
- @title = value
+ opt.on("--quiet", "-q",
+ "Don't show progress as we parse.") do |value|
+ @verbosity = 0
end
- opt.separator nil
-
opt.on("--verbose", "-v",
"Display extra progress as we parse.") do |value|
@verbosity = 2
end
opt.separator nil
-
- opt.on("--webcvs=URL", "-W",
- "Specify a URL for linking to a web frontend",
- "to CVS. If the URL contains a '\%s', the",
- "name of the current file will be",
- "substituted; if the URL doesn't contain a",
- "'\%s', the filename will be appended to it.") do |value|
- @webcvs = value
- end
-
- opt.separator nil
-
opt.separator 'Deprecated options - these warn when set'
-
opt.separator nil
opt.on("--inline-source", "-S") do |value|
warn "--inline-source will be removed from RDoc on or after August 2009"
end
+
+ opt.on("--promiscuous", "-p") do |value|
+ warn "--promiscuous will be removed from RDoc on or after August 2009"
+ end
+
+ opt.separator nil
end
argv.insert(0, *ENV['RDOCOPT'].split) if ENV['RDOCOPT']
View
1 lib/rdoc/parser/c.rb
@@ -614,6 +614,7 @@ def handle_method(type, var_name, meth_name, meth_body, param_count,
if find_body(class_name, meth_body, meth_obj, body) and meth_obj.document_self then
class_obj.add_method meth_obj
@stats.add_method meth_obj
+ meth_obj.visibility = :private if 'private_method' == type
end
end
end
View
117 lib/rdoc/parser/ruby.rb
@@ -1889,7 +1889,7 @@ def parse_call_parameters(tk)
end
def parse_class(container, single, tk, comment)
- container, name_t = get_class_or_module(container)
+ container, name_t = get_class_or_module container
case name_t
when TkCONSTANT
@@ -1921,9 +1921,9 @@ def parse_class(container, single, tk, comment)
else
other = RDoc::TopLevel.find_class_named(name)
unless other
- # other = @top_level.add_class(NormalClass, name, nil)
- # other.record_location(@top_level)
- # other.comment = comment
+# other = @top_level.add_class(NormalClass, name, nil)
+# other.record_location(@top_level)
+# other.comment = comment
other = RDoc::NormalClass.new "Dummy", nil
end
@@ -1948,7 +1948,6 @@ def parse_constant(container, single, tk, comment)
return
end
-
nest = 0
get_tkread
@@ -1960,25 +1959,27 @@ def parse_constant(container, single, tk, comment)
end
loop do
- case tk
- when TkSEMICOLON
+ case tk
+ when TkSEMICOLON then
+ break
+ when TkLPAREN, TkfLPAREN, TkLBRACE, TkLBRACK, TkDO, TkIF, TkUNLESS,
+ TkCASE then
+ nest += 1
+ when TkRPAREN, TkRBRACE, TkRBRACK, TkEND then
+ nest -= 1
+ when TkCOMMENT then
+ if nest <= 0 && @scanner.lex_state == EXPR_END
+ unget_tk tk
break
- when TkLPAREN, TkfLPAREN, TkLBRACE, TkLBRACK, TkDO
- nest += 1
- when TkRPAREN, TkRBRACE, TkRBRACK, TkEND
- nest -= 1
- when TkCOMMENT
- if nest <= 0 && @scanner.lex_state == EXPR_END
- unget_tk(tk)
- break
- end
- when TkNL
- if (nest <= 0) && ((@scanner.lex_state == EXPR_END) || (!@scanner.continue))
- unget_tk(tk)
- break
- end
end
- tk = get_tk
+ when TkNL then
+ if nest <= 0 &&
+ (@scanner.lex_state == EXPR_END || !@scanner.continue) then
+ unget_tk tk
+ break
+ end
+ end
+ tk = get_tk
end
res = get_tkread.tr("\n", " ").strip
@@ -1987,9 +1988,7 @@ def parse_constant(container, single, tk, comment)
con = RDoc::Constant.new name, res, comment
read_documentation_modifiers con, RDoc::CONSTANT_MODIFIERS
- if con.document_self
- container.add_constant(con)
- end
+ container.add_constant con if con.document_self
end
##
@@ -2300,33 +2299,37 @@ def parse_method_or_yield_parameters(method = nil,
nest = 0
loop do
- case tk
- when TkSEMICOLON
- break
- when TkLBRACE
- nest += 1
- when TkRBRACE
- # we might have a.each {|i| yield i }
- unget_tk(tk) if nest.zero?
+ case tk
+ when TkSEMICOLON then
+ break
+ when TkLBRACE then
+ nest += 1
+ when TkRBRACE then
+ # we might have a.each {|i| yield i }
+ unget_tk(tk) if nest.zero?
+ nest -= 1
+ break if nest <= 0
+ when TkLPAREN, TkfLPAREN then
+ nest += 1
+ when end_token then
+ if end_token == TkRPAREN
nest -= 1
- break if nest <= 0
- when TkLPAREN, TkfLPAREN
- nest += 1
- when end_token
- if end_token == TkRPAREN
- nest -= 1
- break if @scanner.lex_state == EXPR_END and nest <= 0
- else
- break unless @scanner.continue
- end
- when method && method.block_params.nil? && TkCOMMENT
- unget_tk(tk)
- read_documentation_modifiers(method, modifiers)
+ break if @scanner.lex_state == EXPR_END and nest <= 0
+ else
+ break unless @scanner.continue
end
+ when method && method.block_params.nil? && TkCOMMENT then
+ unget_tk tk
+ read_documentation_modifiers method, modifiers
+ @read.pop
+ when TkCOMMENT then
+ @read.pop
+ end
tk = get_tk
end
- res = get_tkread.tr("\n", " ").strip
- res = "" if res == ";"
+
+ res = get_tkread.gsub(/\s+/, ' ').strip
+ res = '' if res == ';'
res
end
@@ -2339,10 +2342,12 @@ def parse_method_or_yield_parameters(method = nil,
# and add this as the block_params for the method
def parse_method_parameters(method)
- res = parse_method_or_yield_parameters(method)
- res = "(" + res + ")" unless res[0] == ?(
+ res = parse_method_or_yield_parameters method
+
+ res = "(#{res})" unless res =~ /\A\(/
method.params = res unless method.params
- if method.block_params.nil?
+
+ if method.block_params.nil? then
skip_tkspace(false)
read_documentation_modifiers method, RDoc::METHOD_MODIFIERS
end
@@ -2708,16 +2713,18 @@ def peek_tk
def read_directive(allowed)
tk = get_tk
result = nil
- if TkCOMMENT === tk
- if tk.text =~ /\s*:?(\w+):\s*(.*)/
+
+ if TkCOMMENT === tk then
+ if tk.text =~ /\s*:?(\w+):\s*(.*)/ then
directive = $1.downcase
- if allowed.include?(directive)
+ if allowed.include? directive then
result = [directive, $2]
end
end
else
- unget_tk(tk)
+ unget_tk tk
end
+
result
end
View
492 lib/rdoc/rdoc.rb
@@ -18,329 +18,343 @@
require 'time'
require 'thread'
-module RDoc
+##
+# Encapsulate the production of rdoc documentation. Basically you can use this
+# as you would invoke rdoc from the command line:
+#
+# rdoc = RDoc::RDoc.new
+# rdoc.document(args)
+#
+# Where +args+ is an array of strings, each corresponding to an argument you'd
+# give rdoc on the command line. See rdoc/rdoc.rb for details.
+
+class RDoc::RDoc
##
- # Encapsulate the production of rdoc documentation. Basically you can use
- # this as you would invoke rdoc from the command line:
- #
- # rdoc = RDoc::RDoc.new
- # rdoc.document(args)
- #
- # Where +args+ is an array of strings, each corresponding to an argument
- # you'd give rdoc on the command line. See rdoc/rdoc.rb for details.
+ # Generator instance used for creating output
- class RDoc
+ attr_accessor :generator
- ##
- # Generator instance used for creating output
+ ##
+ # RDoc options
- attr_accessor :generator
+ attr_reader :options
- ##
- # RDoc options
+ ##
+ # Accessor for statistics. Available after each call to parse_files
- attr_reader :options
+ attr_reader :stats
- ##
- # Accessor for statistics. Available after each call to parse_files
+ ##
+ # This is the list of supported output generators
- attr_reader :stats
+ GENERATORS = {}
- ##
- # This is the list of supported output generators
+ ##
+ # Add +klass+ that can generate output after parsing
- GENERATORS = {}
+ def self.add_generator(klass)
+ name = klass.name.sub(/^RDoc::Generator::/, '').downcase
+ GENERATORS[name] = klass
+ end
- ##
- # Add +klass+ that can generate output after parsing
+ ##
+ # Active RDoc::RDoc instance
- def self.add_generator(klass)
- name = klass.name.sub(/^RDoc::Generator::/, '').downcase
- GENERATORS[name] = klass
- end
+ def self.current
+ @current
+ end
- ##
- # Active RDoc::RDoc instance
+ ##
+ # Sets the active RDoc::RDoc instance
- def self.current
- @current
- end
+ def self.current=(rdoc)
+ @current = rdoc
+ end
- ##
- # Sets the active RDoc::RDoc instance
+ def initialize
+ @generator = nil
+ @options = nil
+ @stats = nil
+ end
- def self.current=(rdoc)
- @current = rdoc
- end
+ ##
+ # Report an error message and exit
- def initialize
- @generator = nil
- @options = nil
- @stats = nil
- end
+ def error(msg)
+ raise RDoc::Error, msg
+ end
- ##
- # Report an error message and exit
+ ##
+ # Turns RDoc from stdin into HTML
- def error(msg)
- raise ::RDoc::Error, msg
- end
+ def handle_pipe
+ @html = RDoc::Markup::ToHtml.new
- ##
- # Create an output dir if it doesn't exist. If it does exist, but doesn't
- # contain the flag file <tt>created.rid</tt> then we refuse to use it, as
- # we may clobber some manually generated documentation
+ out = @html.convert $stdin.read
- def setup_output_dir(op_dir, force)
- flag_file = output_flag_file op_dir
+ $stdout.write out
+ end
- if File.exist? op_dir then
- unless File.directory? op_dir then
- error "'#{op_dir}' exists, and is not a directory"
- end
- begin
- created = File.read(flag_file)
- rescue SystemCallError
- error "\nDirectory #{op_dir} already exists, but it looks like it\n" +
- "isn't an RDoc directory. Because RDoc doesn't want to risk\n" +
- "destroying any of your existing files, you'll need to\n" +
- "specify a different output directory name (using the\n" +
- "--op <dir> option).\n\n"
- else
- last = (Time.parse(created) unless force rescue nil)
- end
+ ##
+ # Create an output dir if it doesn't exist. If it does exist, but doesn't
+ # contain the flag file <tt>created.rid</tt> then we refuse to use it, as
+ # we may clobber some manually generated documentation
+
+ def setup_output_dir(op_dir, force)
+ flag_file = output_flag_file op_dir
+
+ if File.exist? op_dir then
+ unless File.directory? op_dir then
+ error "'#{op_dir}' exists, and is not a directory"
+ end
+ begin
+ created = File.read(flag_file)
+ rescue SystemCallError
+ error "\nDirectory #{op_dir} already exists, but it looks like it\n" +
+ "isn't an RDoc directory. Because RDoc doesn't want to risk\n" +
+ "destroying any of your existing files, you'll need to\n" +
+ "specify a different output directory name (using the\n" +
+ "--op <dir> option).\n\n"
else
- FileUtils.mkdir_p(op_dir)
+ last = (Time.parse(created) unless force rescue nil)
end
- last
+ else
+ FileUtils.mkdir_p(op_dir)
end
+ last
+ end
- ##
- # Update the flag file in an output directory.
+ ##
+ # Update the flag file in an output directory.
- def update_output_dir(op_dir, time)
- File.open(output_flag_file(op_dir), "w") { |f| f.puts time.rfc2822 }
- end
+ def update_output_dir(op_dir, time)
+ File.open(output_flag_file(op_dir), "w") { |f| f.puts time.rfc2822 }
+ end
+
+ ##
+ # Return the path name of the flag file in an output directory.
+
+ def output_flag_file(op_dir)
+ File.join op_dir, "created.rid"
+ end
- ##
- # Return the path name of the flag file in an output directory.
+ ##
+ # The .document file contains a list of file and directory name patterns,
+ # representing candidates for documentation. It may also contain comments
+ # (starting with '#')
+
+ def parse_dot_doc_file(in_dir, filename, options)
+ # read and strip comments
+ patterns = File.read(filename).gsub(/#.*/, '')
+
+ result = []
- def output_flag_file(op_dir)
- File.join op_dir, "created.rid"
+ patterns.split.each do |patt|
+ candidates = Dir.glob(File.join(in_dir, patt))
+ result.concat(normalized_file_list(options, candidates))
end
- ##
- # The .document file contains a list of file and directory name patterns,
- # representing candidates for documentation. It may also contain comments
- # (starting with '#')
+ result
+ end
- def parse_dot_doc_file(in_dir, filename, options)
- # read and strip comments
- patterns = File.read(filename).gsub(/#.*/, '')
+ ##
+ # Given a list of files and directories, create a list of all the Ruby
+ # files they contain.
+ #
+ # If +force_doc+ is true we always add the given files, if false, only
+ # add files that we guarantee we can parse. It is true when looking at
+ # files given on the command line, false when recursing through
+ # subdirectories.
+ #
+ # The effect of this is that if you want a file with a non-standard
+ # extension parsed, you must name it explicitly.
- result = []
+ def normalized_file_list(options, relative_files, force_doc = false,
+ exclude_pattern = nil)
+ file_list = []
- patterns.split.each do |patt|
- candidates = Dir.glob(File.join(in_dir, patt))
- result.concat(normalized_file_list(options, candidates))
- end
+ relative_files.each do |rel_file_name|
+ next if exclude_pattern && exclude_pattern =~ rel_file_name
+ stat = File.stat rel_file_name rescue next
- result
- end
+ case type = stat.ftype
+ when "file"
+ next if @last_created and stat.mtime < @last_created
- ##
- # Given a list of files and directories, create a list of all the Ruby
- # files they contain.
- #
- # If +force_doc+ is true we always add the given files, if false, only
- # add files that we guarantee we can parse. It is true when looking at
- # files given on the command line, false when recursing through
- # subdirectories.
- #
- # The effect of this is that if you want a file with a non-standard
- # extension parsed, you must name it explicitly.
-
- def normalized_file_list(options, relative_files, force_doc = false,
- exclude_pattern = nil)
- file_list = []
-
- relative_files.each do |rel_file_name|
- next if exclude_pattern && exclude_pattern =~ rel_file_name
- stat = File.stat rel_file_name rescue next
-
- case type = stat.ftype
- when "file"
- next if @last_created and stat.mtime < @last_created
-
- if force_doc or ::RDoc::Parser.can_parse(rel_file_name) then
- file_list << rel_file_name.sub(/^\.\//, '')
- end
- when "directory"
- next if rel_file_name == "CVS" || rel_file_name == ".svn"
- dot_doc = File.join(rel_file_name, DOT_DOC_FILENAME)
- if File.file?(dot_doc)
- file_list.concat(parse_dot_doc_file(rel_file_name, dot_doc, options))
- else
- file_list.concat(list_files_in_directory(rel_file_name, options))
- end
+ if force_doc or RDoc::Parser.can_parse(rel_file_name) then
+ file_list << rel_file_name.sub(/^\.\//, '')
+ end
+ when "directory"
+ next if rel_file_name == "CVS" || rel_file_name == ".svn"
+ dot_doc = File.join(rel_file_name, RDoc::DOT_DOC_FILENAME)
+ if File.file?(dot_doc)
+ file_list.concat(parse_dot_doc_file(rel_file_name, dot_doc, options))
else
- raise RDoc::Error, "I can't deal with a #{type} #{rel_file_name}"
+ file_list.concat(list_files_in_directory(rel_file_name, options))
end
+ else
+ raise RDoc::Error, "I can't deal with a #{type} #{rel_file_name}"
end
-
- file_list
end
- ##
- # Return a list of the files to be processed in a directory. We know that
- # this directory doesn't have a .document file, so we're looking for real
- # files. However we may well contain subdirectories which must be tested
- # for .document files.
+ file_list
+ end
+
+ ##
+ # Return a list of the files to be processed in a directory. We know that
+ # this directory doesn't have a .document file, so we're looking for real
+ # files. However we may well contain subdirectories which must be tested
+ # for .document files.
- def list_files_in_directory(dir, options)
- files = Dir.glob File.join(dir, "*")
+ def list_files_in_directory(dir, options)
+ files = Dir.glob File.join(dir, "*")
- normalized_file_list options, files, false, options.exclude
- end
+ normalized_file_list options, files, false, options.exclude
+ end
- ##
- # Parse each file on the command line, recursively entering directories.
+ ##
+ # Parse each file on the command line, recursively entering directories.
- def parse_files(options)
- files = options.files
- files = ["."] if files.empty?
+ def parse_files(options)
+ files = options.files
+ files = ["."] if files.empty?
- file_list = normalized_file_list(options, files, true, options.exclude)
+ file_list = normalized_file_list(options, files, true, options.exclude)
- return [] if file_list.empty?
+ return [] if file_list.empty?
- jobs = SizedQueue.new(@options.threads * 3)
- workers = []
- file_info = []
- file_info_lock = Mutex.new
+ jobs = SizedQueue.new(@options.threads * 3)
+ workers = []
+ file_info = []
+ file_info_lock = Mutex.new
- Thread.abort_on_exception = true
- @stats = Stats.new(file_list.size, options.verbosity)
- @stats.begin_adding @options.threads
+ Thread.abort_on_exception = true
+ @stats = RDoc::Stats.new(file_list.size, options.verbosity)
+ @stats.begin_adding @options.threads
- # Create worker threads.
- @options.threads.times do
- thread = Thread.new do
- while (filename = jobs.pop)
- @stats.add_file(filename)
- content = read_file_contents(filename)
- top_level = ::RDoc::TopLevel.new filename
+ # Create worker threads.
+ @options.threads.times do
+ thread = Thread.new do
+ while (filename = jobs.pop)
+ @stats.add_file(filename)
+ content = read_file_contents(filename)
+ top_level = RDoc::TopLevel.new filename
- parser = ::RDoc::Parser.for(top_level, filename, content, options,
- @stats)
- result = parser.scan
+ parser = RDoc::Parser.for(top_level, filename, content, options,
+ @stats)
+ result = parser.scan
- file_info_lock.synchronize do
- file_info << result
- end
+ file_info_lock.synchronize do
+ file_info << result
end
end
- workers << thread
end
+ workers << thread
+ end
- # Feed filenames to the parser worker threads...
- file_list.each do |filename|
- jobs << filename
- end
- workers.size.times do
- jobs << nil
- end
+ # Feed filenames to the parser worker threads...
+ file_list.each do |filename|
+ jobs << filename
+ end
+ workers.size.times do
+ jobs << nil
+ end
- # ...and wait until they're done.
- workers.each do |thread|
- thread.join
- end
+ # ...and wait until they're done.
+ workers.each do |thread|
+ thread.join
+ end
- @stats.done_adding
+ @stats.done_adding
- file_info
- end
+ file_info
+ end
- ##
- # Format up one or more files according to the given arguments.
- #
- # For simplicity, _argv_ is an array of strings, equivalent to the strings
- # that would be passed on the command line. (This isn't a coincidence, as
- # we _do_ pass in ARGV when running interactively). For a list of options,
- # see rdoc/rdoc.rb. By default, output will be stored in a directory
- # called +doc+ below the current directory, so make sure you're somewhere
- # writable before invoking.
- #
- # Throws: RDoc::Error on error
+ ##
+ # Format up one or more files according to the given arguments.
+ #
+ # For simplicity, _argv_ is an array of strings, equivalent to the strings
+ # that would be passed on the command line. (This isn't a coincidence, as
+ # we _do_ pass in ARGV when running interactively). For a list of options,
+ # see rdoc/rdoc.rb. By default, output will be stored in a directory
+ # called +doc+ below the current directory, so make sure you're somewhere
+ # writable before invoking.
+ #
+ # Throws: RDoc::Error on error
- def document(argv)
- TopLevel.reset
+ def document(argv)
+ RDoc::TopLevel.reset
- @options = Options.new
- @options.parse argv
+ @options = RDoc::Options.new
+ @options.parse argv
- @last_created = setup_output_dir @options.op_dir, @options.force_update
+ if @options.pipe then
+ handle_pipe
+ exit
+ end
- start_time = Time.now
+ @last_created = setup_output_dir @options.op_dir, @options.force_update
- file_info = parse_files @options
+ start_time = Time.now
- @options.title = "RDoc Documentation"
+ file_info = parse_files @options
- if file_info.empty?
- $stderr.puts "\nNo newer files." unless @options.quiet
- else
- gen_klass = @options.generator
+ @options.title = "RDoc Documentation"
- unless @options.quiet then
- $stderr.puts "\nGenerating #{gen_klass.name.sub(/^.*::/, '')}..."
- end
+ if file_info.empty?
+ $stderr.puts "\nNo newer files." unless @options.quiet
+ else
+ gen_klass = @options.generator
- @generator = gen_klass.for @options
+ unless @options.quiet then
+ $stderr.puts "\nGenerating #{gen_klass.name.sub(/^.*::/, '')}..."
+ end
- pwd = Dir.pwd
+ @generator = gen_klass.for @options
- Dir.chdir @options.op_dir
+ pwd = Dir.pwd
- begin
- self.class.current = self
+ Dir.chdir @options.op_dir
- Diagram.new(file_info, @options).draw if @options.diagram
- @generator.generate file_info
- update_output_dir ".", start_time
- ensure
- self.class.current = nil
- Dir.chdir pwd
- end
- end
+ begin
+ self.class.current = self
- unless @options.quiet or not @stats then
- puts
- @stats.print
+ RDoc::Diagram.new(file_info, @options).draw if @options.diagram
+ @generator.generate file_info
+ update_output_dir ".", start_time
+ ensure
+ self.class.current = nil
+ Dir.chdir pwd
end
end
- private
+ unless @options.quiet or not @stats then
+ puts
+ @stats.print
+ end
+ end
+
+ private
- def read_file_contents(filename)
- content = if RUBY_VERSION >= '1.9' then
- File.open(filename, "r:ascii-8bit") { |f| f.read }
- else
- File.read filename
- end
+ def read_file_contents(filename)
+ content = if RUBY_VERSION >= '1.9' then
+ File.open(filename, "r:ascii-8bit") { |f| f.read }
+ else
+ File.read filename
+ end
- if defined? Encoding then
- if /coding:\s*(\S+)/ =~ content[/\A(?:.*\n){0,2}/]
- if enc = ::Encoding.find($1)
- content.force_encoding(enc)
- end
+ if defined? Encoding then
+ if /coding:\s*(\S+)/ =~ content[/\A(?:.*\n){0,2}/]
+ if enc = ::Encoding.find($1)
+ content.force_encoding(enc)
end
end
-
- content
end
+
+ content
end
+
end
if Gem.respond_to? :find_files then
View
10 lib/rdoc/ri/driver.rb
@@ -550,8 +550,8 @@ def interactive
cache = load_cache_for klass
- methods += cache.keys.select do |name|
- name =~ /^#{klass}#{method_type}#{method}/
+ methods += cache.keys.select do |method_name|
+ method_name =~ /^#{klass}#{method_type}#{method}/
end
# TODO ancestor lookup
@@ -609,7 +609,7 @@ def expand_klass(klass)
expanded << '::' unless expanded.empty?
short = expanded << klass_part
- subset = class_cache.keys.select do |klass|
+ subset = class_cache.keys.select do |klass_name|
klass =~ /^#{expanded}[^:]*$/
end
@@ -673,8 +673,8 @@ def create_cache_for(klassname, path)
if system_file then
method["source_path"] = "Ruby #{RDoc::RI::Paths::VERSION}"
else
- gem = Gem.path.any? do |path|
- pattern = File.join Regexp.escape(path), 'doc', '(.*?)', ''
+ gem = Gem.path.any? do |gem_path|
+ pattern = File.join Regexp.escape(gem_path), 'doc', '(.*?)', ''
f =~ /^#{pattern}/
end
View
276 lib/rdoc/task.rb
@@ -0,0 +1,276 @@
+# Copyright (c) 2003, 2004 Jim Weirich, 2009 Eric Hodel
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be
+# included in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+require 'rubygems'
+begin
+ gem 'rdoc'
+rescue Gem::LoadError
+end
+
+begin
+ gem 'rake'
+rescue Gem::LoadError
+end
+
+require 'rdoc'
+require 'rake'
+require 'rake/tasklib'
+
+##
+# Create a documentation task that will generate the RDoc files for a project.
+#
+# The RDoc::Task will create the following targets:
+#
+# [<b><em>rdoc</em></b>]
+# Main task for this RDoc task.
+#
+# [<b>:clobber_<em>rdoc</em></b>]
+# Delete all the rdoc files. This target is automatically added to the main
+# clobber target.
+#
+# [<b>:re<em>rdoc</em></b>]
+# Rebuild the rdoc files from scratch, even if they are not out of date.
+#
+# Simple Example:
+#
+# RDoc::Task.new do |rd|
+# rd.main = "README.rdoc"
+# rd.rdoc_files.include("README.rdoc", "lib/**/*.rb")
+# end
+#
+# The +rd+ object passed to the block is an RDoc::Task object. See the
+# attributes list for the RDoc::Task class for available customization options.
+#
+# == Specifying different task names
+#
+# You may wish to give the task a different name, such as if you are
+# generating two sets of documentation. For instance, if you want to have a
+# development set of documentation including private methods:
+#
+# RDoc::Task.new :rdoc_dev do |rd|
+# rd.main = "README.doc"
+# rd.rdoc_files.include("README.rdoc", "lib/**/*.rb")
+# rd.options << "--all"
+# end
+#
+# The tasks would then be named :<em>rdoc_dev</em>,
+# :clobber_<em>rdoc_dev</em>, and :re<em>rdoc_dev</em>.
+#
+# If you wish to have completely different task names, then pass a Hash as
+# first argument. With the <tt>:rdoc</tt>, <tt>:clobber_rdoc</tt> and
+# <tt>:rerdoc</tt> options, you can customize the task names to your liking.
+#
+# For example:
+#
+# RDoc::Task.new(:rdoc => "rdoc", :clobber_rdoc => "rdoc:clean",
+# :rerdoc => "rdoc:force")
+#
+# This will create the tasks <tt>:rdoc</tt>, <tt>:rdoc_clean</tt> and
+# <tt>:rdoc:force</tt>.
+
+class RDoc::Task < Rake::TaskLib
+
+ ##
+ # Name of the main, top level task. (default is :rdoc)
+
+ attr_accessor :name
+
+ ##
+ # Name of directory to receive the html output files. (default is "html")
+
+ attr_accessor :rdoc_dir
+
+ ##
+ # Title of RDoc documentation. (defaults to rdoc's default)
+
+ attr_accessor :title
+
+ ##
+ # Name of file to be used as the main, top level file of the RDoc. (default
+ # is none)
+
+ attr_accessor :main
+
+ ##
+ # Name of template to be used by rdoc. (defaults to rdoc's default)
+
+ attr_accessor :template
+
+ ##
+ # List of files to be included in the rdoc generation. (default is [])
+
+ attr_accessor :rdoc_files
+
+ ##
+ # Additional list of options to be passed rdoc. (default is [])
+
+ attr_accessor :options
+
+ ##
+ # Whether to run the rdoc process as an external shell (default is false)
+
+ attr_accessor :external
+
+ ##
+ # Create an RDoc task with the given name. See the RDoc::Task class overview
+ # for documentation.
+
+ def initialize(name = :rdoc) # :yield: self
+ if name.is_a? Hash then
+ invalid_options = name.keys.map { |k| k.to_sym } -
+ [:rdoc, :clobber_rdoc, :rerdoc]
+
+ unless invalid_options.empty? then
+ raise ArgumentError, "invalid options: #{invalid_options.join(", ")}"
+ end
+ end
+
+ @name = name
+ @rdoc_files = Rake::FileList.new
+ @rdoc_dir = 'html'
+ @main = nil
+ @title = nil
+ @template = nil
+ @external = false
+ @options = []
+ yield self if block_given?
+ define
+ end
+
+ ##
+ # Create the tasks defined by this task lib.
+
+ def define
+ if rdoc_task_name != "rdoc" then
+ desc "Build the RDoc HTML Files"
+ else
+ desc "Build the #{rdoc_task_name} HTML Files"
+ end
+ task rdoc_task_name
+
+ desc "Force a rebuild of the RDoc files"
+ task rerdoc_task_name => [clobber_task_name, rdoc_task_name]
+
+ desc "Remove RDoc products"
+ task clobber_task_name do
+ rm_r rdoc_dir rescue nil
+ end
+
+ task :clobber => [clobber_task_name]
+
+ directory @rdoc_dir
+ task rdoc_task_name => [rdoc_target]
+ file rdoc_target => @rdoc_files + [Rake.application.rakefile] do
+ rm_r @rdoc_dir rescue nil
+ @before_running_rdoc.call if @before_running_rdoc
+ args = option_list + @rdoc_files
+
+ if @external then
+ argstring = args.join(' ')
+ sh %{ruby -Ivendor vendor/rd #{argstring}}
+ else
+ if Rake.application.options.trace then
+ $stderr.puts "rdoc #{args.join ' '}"
+ end
+ require 'rdoc/rdoc'
+ RDoc::RDoc.new.document(args)
+ end
+ end
+
+ self
+ end
+
+ def option_list
+ result = @options.dup
+ result << "-o" << @rdoc_dir
+ result << "--main" << quote(main) if main
+ result << "--title" << quote(title) if title
+ result << "-T" << quote(template) if template
+ result
+ end
+
+ def quote(str)
+ if @external
+ "'#{str}'"
+ else
+ str
+ end
+ end
+
+ def option_string
+ option_list.join(' ')
+ end
+
+ ##
+ # The block passed to this method will be called just before running the
+ # RDoc generator. It is allowed to modify RDoc::Task attributes inside the
+ # block.
+
+ def before_running_rdoc(&block)
+ @before_running_rdoc = block
+ end
+
+ private
+
+ def rdoc_target
+ "#{rdoc_dir}/index.html"
+ end
+
+ def rdoc_task_name
+ case name
+ when Hash
+ (name[:rdoc] || "rdoc").to_s
+ else
+ name.to_s
+ end
+ end
+
+ def clobber_task_name
+ case name
+ when Hash
+ (name[:clobber_rdoc] || "clobber_rdoc").to_s
+ else
+ "clobber_#{name}"
+ end
+ end
+
+ def rerdoc_task_name
+ case name
+ when Hash
+ (name[:rerdoc] || "rerdoc").to_s
+ else
+ "re#{name}"
+ end
+ end
+
+end
+
+# :stopdoc:
+module Rake
+
+ ##
+ # For backwards compatibility
+
+ RDocTask = RDoc::Task
+
+end
+# :startdoc:
+
View
10 lib/rdoc/top_level.rb
@@ -148,6 +148,16 @@ def initialize(file_name)
end
##
+ # Adds +method+ to Object instead of RDoc::TopLevel
+
+ def add_method(method)
+ object = self.class.find_class_named 'Object'
+ object = add_class RDoc::NormalClass, 'Object' unless object
+
+ object.add_method method
+ end
+
+ ##
# Base name of this file
def base_name
View
9 test/test_rdoc_markup_attribute_manager.rb
@@ -124,6 +124,10 @@ def test_bold
@am.flow("*\\bold*")
end
+ def test_bold_html_escaped
+ assert_equal ['cat <b>dog</b>'], @am.flow('cat \<b>dog</b>')
+ end
+
def test_combined
assert_equal(["cat ", @em_on, "and", @em_off, " ", @bold_on, "dog", @bold_off],
@am.flow("cat _and_ *dog*"))
@@ -229,6 +233,11 @@ def test_special
assert_equal(["cats' ", crossref("#fred")].flatten, @am.flow("cats' #fred"))
end
+ def test_tt_html
+ assert_equal [@tt_on, '"\n"', @tt_off],
+ @am.flow('<tt>"\n"</tt>')
+ end
+
end
MiniTest::Unit.autorun
View
1 test/test_rdoc_markup_to_html.rb
@@ -48,6 +48,7 @@ def test_list_verbatim
def test_tt_formatting
assert_equal "<p>\n<tt>--</tt> &#8212; <tt>cats'</tt> cats&#8217;\n</p>\n",
util_format("<tt>--</tt> -- <tt>cats'</tt> cats'")
+
assert_equal "<p>\n<b>&#8212;</b>\n</p>\n", util_format("<b>--</b>")
end
View
1 test/test_rdoc_markup_to_html_crossref.rb
@@ -136,6 +136,7 @@ def test_handle_special_CROSSREF_no_ref
refute_ref 'bogus', 'bogus'
refute_ref 'bogus', '\bogus'
+ refute_ref '\bogus', '\\\bogus'
refute_ref '#n', '\#n'
refute_ref '#n()', '\#n()'
View
28 test/test_rdoc_parser_c.rb
@@ -358,6 +358,34 @@ def test_define_method
assert_equal " Method Comment! \n", read_method.comment
end
+ def test_define_method_private
+ content = <<-EOF
+/*Method Comment! */
+static VALUE
+rb_io_s_read(argc, argv, io)
+ int argc;
+ VALUE *argv;
+ VALUE io;
+{
+}
+
+void
+Init_IO(void) {
+ /*
+ * a comment for class Foo on rb_define_class
+ */
+ VALUE rb_cIO = rb_define_class("IO", rb_cObject);
+ rb_define_private_method(rb_cIO, "read", rb_io_s_read, -1);
+}
+ EOF
+
+ klass = util_get_class content, 'rb_cIO'
+ read_method = klass.method_list.first
+ assert_equal 'IO#read', read_method.full_name
+ assert_equal :private, read_method.visibility
+ assert_equal " Method Comment! \n", read_method.comment
+ end
+
def util_get_class(content, name)
@parser = util_parser content
@parser.scan
View
92 test/test_rdoc_parser_ruby.rb
@@ -1,7 +1,7 @@
require 'stringio'
require 'tempfile'
require 'rubygems'
-require 'minitest/unit'
+require 'minitest/autorun'
require 'rdoc/options'
require 'rdoc/parser/ruby'
@@ -697,6 +697,95 @@ def test_parse_method_funky
assert klass.method_list.empty?
end
+ def test_parse_method_no_parens
+ klass = RDoc::NormalClass.new 'Foo'
+ klass.parent = @top_level
+
+ comment = "##\n# my method\n"
+
+ util_parser "def foo arg1, arg2\nend"
+
+ tk = @parser.get_tk
+
+ @parser.parse_method klass, RDoc::Parser::Ruby::NORMAL, tk, comment
+
+ foo = klass.method_list.first
+ assert_equal '(arg1, arg2)', foo.params
+ end
+
+ def test_parse_method_parameters_comment
+ klass = RDoc::NormalClass.new 'Foo'
+ klass.parent = @top_level
+
+ comment = "##\n# my method\n"
+
+ util_parser "def foo arg1, arg2 # some useful comment\nend"
+
+ tk = @parser.get_tk
+
+ @parser.parse_method klass, RDoc::Parser::Ruby::NORMAL, tk, comment
+
+ foo = klass.method_list.first
+ assert_equal '(arg1, arg2)', foo.params
+ end
+
+ def test_parse_method_parameters_comment_continue
+ klass = RDoc::NormalClass.new 'Foo'
+ klass.parent = @top_level
+
+ comment = "##\n# my method\n"
+
+ util_parser "def foo arg1, arg2, # some useful comment\narg3\nend"
+
+ tk = @parser.get_tk
+
+ @parser.parse_method klass, RDoc::Parser::Ruby::NORMAL, tk, comment
+
+ foo = klass.method_list.first
+ assert_equal '(arg1, arg2, arg3)', foo.params
+ end
+
+ def test_parse_method_toplevel
+ klass = @top_level
+
+ comment = "##\n# my method\n"
+
+ util_parser "def foo arg1, arg2\nend"
+
+ tk = @parser.get_tk
+
+ @parser.parse_method klass, RDoc::Parser::Ruby::NORMAL, tk, comment
+
+ object = RDoc::TopLevel.find_class_named 'Object'
+
+ foo = object.method_list.first
+ assert_equal 'Object#foo', foo.full_name
+ end
+
+ def test_parse_statements_class_if
+ comment = "##\n# my method\n"
+
+ util_parser <<-CODE
+module Foo
+ X = if TRUE then
+ ''
+ end
+
+ def blah
+ end
+end
+ CODE
+
+ @parser.parse_statements @top_level, RDoc::Parser::Ruby::NORMAL, nil, ''
+
+ foo = @top_level.modules.first
+ assert_equal 'Foo', foo.full_name, 'module Foo'
+
+ methods = foo.method_list
+ assert_equal 1, methods.length
+ assert_equal 'Foo#blah', methods.first.full_name
+ end
+
def test_parse_statements_class_nested
comment = "##\n# my method\n"
@@ -949,4 +1038,3 @@ def util_top_level
end
-MiniTest::Unit.autorun
View
64 test/test_rdoc_task.rb
@@ -0,0 +1,64 @@
+require 'rubygems'
+require 'minitest/autorun'
+require 'rdoc/task'
+
+class TestRDocTask < MiniTest::Unit::TestCase
+
+ def setup
+ Rake::Task.clear
+ end
+
+ def test_tasks_creation
+ RDoc::Task.new
+ assert Rake::Task[:rdoc]
+ assert Rake::Task[:clobber_rdoc]
+ assert Rake::Task[:rerdoc]
+ end
+
+ def test_tasks_creation_with_custom_name_symbol
+ rd = RDoc::Task.new(:rdoc_dev)
+ assert Rake::Task[:rdoc_dev]
+ assert Rake::Task[:clobber_rdoc_dev]
+ assert Rake::Task[:rerdoc_dev]
+ assert_equal :rdoc_dev, rd.name
+ end
+
+ def test_tasks_creation_with_custom_name_string
+ rd = RDoc::Task.new("rdoc_dev")
+ assert Rake::Task[:rdoc_dev]
+ assert Rake::Task[:clobber_rdoc_dev]
+ assert Rake::Task[:rerdoc_dev]
+ assert_equal "rdoc_dev", rd.name
+ end
+
+ def test_tasks_creation_with_custom_name_hash
+ options = { :rdoc => "rdoc", :clobber_rdoc => "rdoc:clean", :rerdoc => "rdoc:force" }
+ rd = RDoc::Task.new(options)
+ assert Rake::Task[:"rdoc"]
+ assert Rake::Task[:"rdoc:clean"]
+ assert Rake::Task[:"rdoc:force"]
+ assert_raises(RuntimeError) { Rake::Task[:clobber_rdoc] }
+ assert_equal options, rd.name
+ end
+
+ def test_tasks_creation_with_custom_name_hash_will_use_default_if_an_option_isnt_given
+ rd = RDoc::Task.new(:clobber_rdoc => "rdoc:clean")
+ assert Rake::Task[:rdoc]
+ assert Rake::Task[:"rdoc:clean"]
+ assert Rake::Task[:rerdoc]
+ end
+
+ def test_tasks_creation_with_custom_name_hash_raises_exception_if_invalid_option_given
+ assert_raises(ArgumentError) do
+ RDoc::Task.new(:foo => "bar")
+ end
+
+ begin
+ RDoc::Task.new(:foo => "bar")
+ rescue ArgumentError => e
+ assert_match(/foo/, e.message)
+ end
+ end
+
+end
+

0 comments on commit 9b7c6ca

Please sign in to comment.