lib/rdoc/servlet.rb in rdoc-4.0.0 vs lib/rdoc/servlet.rb in rdoc-4.0.1

- old
+ new

@@ -51,18 +51,21 @@ ## # Creates a new WEBrick servlet. # # Use +mount_path+ when mounting the servlet somewhere other than /. # + # Use +extra_doc_dirs+ for additional documentation directories. + # # +server+ is provided automatically by WEBrick when mounting. +stores+ and # +cache+ are provided automatically by the servlet. - def initialize server, stores, cache, mount_path = nil + def initialize server, stores, cache, mount_path = nil, extra_doc_dirs = [] super server @cache = cache @mount_path = mount_path + @extra_doc_dirs = extra_doc_dirs @stores = stores @options = RDoc::Options.new @options.op_dir = '.' @@ -268,10 +271,11 @@ # Documentation', etc.), the path relative to the mount point, whether the # documentation exists, the type of documentation (See RDoc::RI::Paths#each) # and the filesystem to the RDoc::Store for the documentation. def installed_docs + extra_counter = 0 ri_paths.map do |path, type| store = RDoc::Store.new path, type exists = File.exist? store.cache_path case type @@ -282,10 +286,15 @@ ['Ruby Documentation', 'ruby/', exists, type, path] when :site then ['Site Documentation', 'site/', exists, type, path] when :home then ['Home Documentation', 'home/', exists, type, path] + when :extra then + extra_counter += 1 + store.load_cache if exists + title = store.title || "Extra Documentation" + [title, "extra-#{extra_counter}/", exists, type, path] end end end ## @@ -298,11 +307,11 @@ ## # Enumerates the ri paths. See RDoc::RI::Paths#each def ri_paths &block - RDoc::RI::Paths.each true, true, true, :all, &block + RDoc::RI::Paths.each true, true, true, :all, *@extra_doc_dirs, &block #TODO: pass extra_dirs end ## # Generates the root page on +res+. +req+ is ignored. @@ -342,10 +351,12 @@ path = 'site' comment = 'Documentation for non-gem libraries' when :home then path = 'home' comment = 'Documentation from your home directory' + when :extra + comment = name end info << [name, '', path, '', comment] end @@ -395,9 +406,13 @@ RDoc::Store.new RDoc::RI::Paths.home_dir, :home when 'ruby' then RDoc::Store.new RDoc::RI::Paths.system_dir, :system when 'site' then RDoc::Store.new RDoc::RI::Paths.site_dir, :site + when /^extra-(\d+)$/ then + index = $1.to_i - 1 + ri_dir = installed_docs[index][4] + RDoc::Store.new ri_dir, :extra else ri_dir, type = ri_paths.find do |dir, dir_type| next unless dir_type == :gem source_name == dir[%r%/([^/]*)/ri$%, 1]