From 84f0b051de55b80211eab0ad2438f500af45e4a5 Mon Sep 17 00:00:00 2001 From: dave Date: Thu, 18 Dec 2003 21:08:25 +0000 Subject: Annotate enum.c. Add pager support, and report on methods in included modules git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@5214 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- lib/rdoc/generators/ri_generator.rb | 39 +++++++++++++++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) (limited to 'lib/rdoc/generators/ri_generator.rb') 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 -- cgit v1.2.3