require 'rdoc/options' require 'rdoc/template' 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' module Generators class RIGenerator ## # Generators may need to return specific subclasses depending on the # options they are passed. Because of this we create them using a factory def RIGenerator.for(options) new(options) end class <\s*)[^\#]/ content = comment else content = comment.gsub(/^\s*(#+)/) { $1.tr('#',' ') } end @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? $stderr.puts "You asked me to merge this source into existing " $stderr.puts "documentation. This file references a class or " $stderr.puts "module called #{cls_desc.name} which I don't" $stderr.puts "have existing documentation for." $stderr.puts $stderr.puts "Perhaps you need to generate its documentation first" exit 1 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