summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/rdoc/README12
-rw-r--r--lib/rdoc/generators/ri_generator.rb39
-rw-r--r--lib/rdoc/options.rb9
-rw-r--r--lib/rdoc/parsers/parse_c.rb29
-rw-r--r--lib/rdoc/ri/ri_cache.rb16
-rw-r--r--lib/rdoc/ri/ri_descriptions.rb8
-rw-r--r--lib/rdoc/ri/ri_paths.rb12
-rw-r--r--lib/rdoc/ri/ri_reader.rb10
-rw-r--r--lib/rdoc/ri/ri_writer.rb16
9 files changed, 138 insertions, 13 deletions
diff --git a/lib/rdoc/README b/lib/rdoc/README
index 39ce8bb75b..1b8671182f 100644
--- a/lib/rdoc/README
+++ b/lib/rdoc/README
@@ -166,6 +166,11 @@ Options are:
[<tt>--main</tt> _name_]
set the class, module, or file to appear on the index page
+[<tt>--merge</tt>]
+ when generating _ri_ output, if classes being processed already
+ exist in the destination directory, merge in the current details
+ rather than overwrite them.
+
[<tt>--one-file</tt>]
place all the output into a single file
@@ -191,6 +196,13 @@ Options are:
[<tt>--quiet</tt>]
do not display progress messages
+[<tt>--ri</tt> _and_ <tt>--ri-site</tt>]
+ generate output than can be read by the _ri_ command-line tool.
+ By default --ri places its output in ~/.rdoc, and --ri-site in
+ $datadir/ri/<ver>/site. Both can be overridden with a subsequent
+ --op option. Both default directories are in ri's default search
+ path.
+
[<tt>--show-hash</tt>]
A name of the form #name in a comment is a possible hyperlink to
an instance method name. When displayed, the '#' is removed unless
diff --git a/lib/rdoc/generators/ri_generator.rb b/lib/rdoc/generators/ri_generator.rb
index 375c534923..c2b5269c3c 100644
--- a/lib/rdoc/generators/ri_generator.rb
+++ b/lib/rdoc/generators/ri_generator.rb
@@ -42,6 +42,8 @@ require 'rdoc/markup/simple_markup'
require 'rdoc/markup/simple_markup/to_flow'
require 'cgi'
+require 'rdoc/ri/ri_cache'
+require 'rdoc/ri/ri_reader'
require 'rdoc/ri/ri_writer'
require 'rdoc/ri/ri_descriptions'
@@ -121,8 +123,7 @@ module Generators
RI::MethodSummary.new(m.name)
end
- @ri_writer.remove_class(cls_desc)
- @ri_writer.add_class(cls_desc)
+ update_or_replace(cls_desc)
class_methods.each do |m|
generate_method_info(cls_desc, m)
@@ -219,5 +220,39 @@ module Generators
@markup.convert(content, @to_flow)
end
+
+ # By default we replace existing classes with the
+ # same name. If the --merge option was given, we instead
+ # merge this definition into an existing class. We add
+ # our methods, aliases, etc to that class, but do not
+ # change the class's description.
+
+ def update_or_replace(cls_desc)
+ old_cls = nil
+
+ if @options.merge
+ rdr = RI::RiReader.new(RI::RiCache.new(@options.op_dir))
+
+ namespace = rdr.top_level_namespace
+ namespace = rdr.lookup_namespace_in(cls_desc.name, namespace)
+ if namespace.empty?
+ raise RiError.new("Nothing known about #{arg}")
+ else
+ old_cls = namespace[0]
+ end
+ end
+
+ if old_cls.nil?
+ # no merge: simply overwrite
+ @ri_writer.remove_class(cls_desc)
+ @ri_writer.add_class(cls_desc)
+ else
+ # existing class: merge in
+ old_desc = rdr.get_class(old_cls)
+
+ old_desc.merge_in(cls_desc)
+ @ri_writer.add_class(old_desc)
+ end
+ end
end
end
diff --git a/lib/rdoc/options.rb b/lib/rdoc/options.rb
index 36b82eab7d..ab99c18b86 100644
--- a/lib/rdoc/options.rb
+++ b/lib/rdoc/options.rb
@@ -28,6 +28,9 @@ class Options
# the first file we encounter is used)
attr_accessor :main_page
+ # merge into classes of the name name when generating ri
+ attr_reader :merge
+
# Don't display progress as we process the files
attr_reader :quiet
@@ -160,6 +163,10 @@ class Options
[ "--main", "-m", "name",
"'name' will be the initial page displayed" ],
+ [ "--merge", "-M", nil,
+ "when creating ri output, merge processed classes\n" +
+ "into previously documented classes of the name name"],
+
[ "--one-file", "-1", nil,
"put all the output into a single file" ],
@@ -332,6 +339,7 @@ class Options
@op_name = nil
@show_all = false
@main_page = nil
+ @marge = false
@exclude = nil
@quiet = false
@generator_name = 'html'
@@ -376,6 +384,7 @@ class Options
when "--inline-source" then @inline_source = true
when "--line-numbers" then @include_line_numbers = true
when "--main" then @main_page = arg
+ when "--merge" then @merge = true
when "--one-file" then @all_one_file = true
when "--op" then @op_dir = arg
when "--opname" then @op_name = arg
diff --git a/lib/rdoc/parsers/parse_c.rb b/lib/rdoc/parsers/parse_c.rb
index 3e8b48da34..39d136089b 100644
--- a/lib/rdoc/parsers/parse_c.rb
+++ b/lib/rdoc/parsers/parse_c.rb
@@ -140,6 +140,7 @@ module RDoc
remove_commented_out_lines
do_classes
do_methods
+ do_includes
@top_level
end
@@ -237,7 +238,8 @@ module RDoc
next if meth_name == "initialize_copy"
class_name = @known_classes[var_name] || var_name
- class_obj = @classes[var_name]
+ class_obj = find_class(var_name, class_name)
+
if class_obj
if meth_name == "initialize"
meth_name = "new"
@@ -297,7 +299,18 @@ module RDoc
end
end
-
+
+ # Look for includes of the form
+ # rb_include_module(rb_cArray, rb_mEnumerable);
+ def do_includes
+ @body.scan(/rb_include_module\(\s*(\w+?),\s*(\w+?)\s*\)/) do |c,m|
+ if cls = @classes[c]
+ m = KNOWN_CLASSES[m] || m
+ cls.add_include(Include.new(m, ""))
+ end
+ end
+ end
+
# Remove the /*'s and leading asterisks from C comments
def mangle_comment(comment)
@@ -306,7 +319,17 @@ module RDoc
comment.gsub!(/^[ \t]*\*/m) { " " * $&.length }
comment
end
-
+
+ def find_class(raw_name, name)
+ unless @classes[name]
+ if raw_name =~ /^rb_m/
+ @classes[name] = @top_level.add_module(NormalModule, name)
+ else
+ @classes[name] = @top_level.add_class(NormalClass, name, nil)
+ end
+ end
+ @classes[name]
+ end
end
end
diff --git a/lib/rdoc/ri/ri_cache.rb b/lib/rdoc/ri/ri_cache.rb
index f2cdbf6f38..0a2fac184c 100644
--- a/lib/rdoc/ri/ri_cache.rb
+++ b/lib/rdoc/ri/ri_cache.rb
@@ -31,7 +31,7 @@ module RI
if name =~ /^(.*?)-(c|i).yaml$/
external_name = $1
is_class_method = $2 == "c"
- internal_name = external_name
+ internal_name = RiWriter.external_to_internal(external_name)
list = is_class_method ? @class_methods : @instance_methods
path = File.join(dir, name)
list << MethodEntry.new(path, internal_name, is_class_method, self)
@@ -53,6 +53,11 @@ module RI
@inferior_classes.find_all {|c| c.name[name]}
end
+ # Return an exact match to a particular name
+ def contained_class_named(name)
+ @inferior_classes.find {|c| c.name == name}
+ end
+
# return the list of local methods matching name
# We're split into two because we need distinct behavior
# when called from the toplevel
@@ -72,7 +77,7 @@ module RI
# Return our full name
- def full_name
+ def full_namep
res = @in_class.full_name
res << "::" unless res.empty?
res << @name
@@ -93,7 +98,7 @@ module RI
else fail "Unknown is_class_method"
end
- list.find_all {|m| m.name[name]}
+ list.find_all {|m| m.name; m.name[name]}
end
end
@@ -108,6 +113,11 @@ module RI
def full_name
""
end
+
+ def module_named(name)
+
+ end
+
end
class MethodEntry
diff --git a/lib/rdoc/ri/ri_descriptions.rb b/lib/rdoc/ri/ri_descriptions.rb
index f99905719b..47984cf41d 100644
--- a/lib/rdoc/ri/ri_descriptions.rb
+++ b/lib/rdoc/ri/ri_descriptions.rb
@@ -46,6 +46,14 @@ module RI
attr_accessor :superclass
attr_accessor :includes
+ # merge in another class desscription into this one
+ def merge_in(old)
+ @class_methods.concat(old.class_methods).sort!
+ @instance_methods.concat(old.instance_methods).sort!
+ @attributes.concat(old.attributes).sort!
+ @constants.concat(old.constants).sort!
+ @includes.concat(old.includes).sort!
+ end
end
class MethodDescription < Description
diff --git a/lib/rdoc/ri/ri_paths.rb b/lib/rdoc/ri/ri_paths.rb
index 14288d9a94..ff8257a546 100644
--- a/lib/rdoc/ri/ri_paths.rb
+++ b/lib/rdoc/ri/ri_paths.rb
@@ -15,8 +15,8 @@ module RI
#
# There's contention about all this, but for now:
#
- # system:: $prefix/lib/ruby/<version>/doc/rdoc
- # site:: $prefix/lib/ruby/site_dir/<version>/doc/rdoc
+ # system:: $datadir/ri/<ver>/system/...
+ # site:: $datadir/ri/<ver>/site/...
# user:: ~/.rdoc
module Paths
@@ -26,8 +26,11 @@ module RI
DOC_DIR = "doc/rdoc"
- SYSDIR = File.join(Config::CONFIG['rubylibdir'], DOC_DIR)
- SITEDIR = File.join(Config::CONFIG['sitelibdir'], DOC_DIR)
+ version = Config::CONFIG['ruby_version']
+
+ base = File.join(Config::CONFIG['datadir'], "ri", version)
+ SYSDIR = File.join(base, "system")
+ SITEDIR = File.join(base, "site")
homedir = ENV['HOME'] || ENV['USERPROFILE'] || ENV['HOMEPATH']
if homedir
@@ -36,6 +39,7 @@ module RI
HOMEDIR = nil
end
+ # This is the search path for 'ri'
PATH = [ SYSDIR, SITEDIR, HOMEDIR ].find_all {|p| p && File.directory?(p)}
end
end
diff --git a/lib/rdoc/ri/ri_reader.rb b/lib/rdoc/ri/ri_reader.rb
index eb56d654fb..dd647b3f89 100644
--- a/lib/rdoc/ri/ri_reader.rb
+++ b/lib/rdoc/ri/ri_reader.rb
@@ -21,6 +21,16 @@ module RI
result
end
+ def find_class_by_name(full_name)
+ names = full_name.split(/::/)
+ ns = @cache.toplevel
+ for name in names
+ ns = ns.contained_class_named(name)
+ return nil if ns.nil?
+ end
+ get_class(ns)
+ end
+
def find_methods(name, is_class_method, namespaces)
result = []
namespaces.each do |ns|
diff --git a/lib/rdoc/ri/ri_writer.rb b/lib/rdoc/ri/ri_writer.rb
index 70468cb1f5..78c68e8409 100644
--- a/lib/rdoc/ri/ri_writer.rb
+++ b/lib/rdoc/ri/ri_writer.rb
@@ -8,6 +8,19 @@ module RI
end
+ # Convert a name from internal form (containing punctuation)
+ # to an external form (where punctuation is replaced
+ # by %xx)
+
+ def RiWriter.internal_to_external(name)
+ name.gsub(/\W/) { sprintf("%%%02x", $&[0]) }
+ end
+
+ # And the reverse operation
+ def RiWriter.external_to_internal(name)
+ name.gsub(/%([0-9a-f]{2,2})/) { $1.to_i(16).chr }
+ end
+
def initialize(base_dir)
@base_dir = base_dir
end
@@ -27,7 +40,8 @@ module RI
def add_method(class_desc, method_desc)
dir = path_to_dir(class_desc.full_name)
- meth_file_name = File.join(dir, method_desc.name)
+ file_name = RiWriter.internal_to_external(method_desc.name)
+ meth_file_name = File.join(dir, file_name)
if method_desc.is_singleton
meth_file_name += "-c.yaml"
else