#{li.label.gsub(/ /, ' ')} | }
+ end
+ else
+ fail "unknown list type"
+ end
+
+ @output.print "<#{list_type}>"
+ list.contents.each do |item|
+ if item.kind_of? RDoc::Markup::Flow::LI
+ prefix = prefixer.call(item)
+ @output.print prefix
+ display_flow_item(item, prefix)
+ else
+ display_flow_item(item)
+ end
+ end
+ @output.print "#{list_type}>"
+ end
+
+ def display_verbatim_flow_item(item, prefix=@indent)
+ @output.print("")
+ item.body.split(/\n/).each do |line|
+ @output.puts conv_html(line)
+ end
+ @output.puts(" ")
+ end
+
+ private
+
+ ATTR_MAP = {
+ BOLD => "b>",
+ ITALIC => "i>",
+ CODE => "tt>"
+ }
+
+ def update_attributes(current, wanted)
+ str = ""
+ # first turn off unwanted ones
+ off = current & ~wanted
+ for quality in [ BOLD, ITALIC, CODE]
+ if (off & quality) > 0
+ str << "" + ATTR_MAP[quality]
+ end
+ end
+
+ # now turn on wanted
+ for quality in [ BOLD, ITALIC, CODE]
+ unless (wanted & quality).zero?
+ str << "<" << ATTR_MAP[quality]
+ end
+ end
+ @output.print str
+ end
+
+ def tag(code)
+ @output.print("<#{code}>")
+ @output.print(yield)
+ @output.print("#{code}>")
+ end
+
+ def escape(str)
+ str = str.gsub(/&/n, '&')
+ str.gsub!(/\"/n, '"')
+ str.gsub!(/>/n, '>')
+ str.gsub!(//system/...
+# site:: $datadir/ri//site/...
+# user:: ~/.rdoc
+
+module RDoc::RI::Paths
+
+ #:stopdoc:
+ require 'rbconfig'
+
+ DOC_DIR = "doc/rdoc"
+
+ version = Config::CONFIG['ruby_version']
+# version = RbConfig::CONFIG['ruby_version'] # RbConfig is invalid in Ruby 1.8.2
+
+ base = File.join(Config::CONFIG['datadir'], "ri", version)
+# base = File.join(RbConfig::CONFIG['datadir'], "ri", version) # RbConfig is invalid in Ruby 1.8.2
+
+ SYSDIR = File.join(base, "system")
+ SITEDIR = File.join(base, "site")
+ homedir = ENV['HOME'] || ENV['USERPROFILE'] || ENV['HOMEPATH']
+
+ if homedir then
+ HOMEDIR = File.join(homedir, ".rdoc")
+ else
+ HOMEDIR = nil
+ end
+
+ # This is the search path for 'ri'
+ PATH = [ SYSDIR, SITEDIR, HOMEDIR ].find_all {|p| p && File.directory?(p)}
+
+ begin
+ require 'rubygems' unless defined?(Gem) and defined?(Gem::Enable) and
+ Gem::Enable
+
+ # HACK dup'd from Gem.latest_partials and friends
+ all_paths = []
+
+ all_paths = Gem.path.map do |dir|
+ Dir[File.join(dir, 'doc', '*', 'ri')]
+ end.flatten
+
+ ri_paths = {}
+
+ all_paths.each do |dir|
+ base = File.basename File.dirname(dir)
+ if base =~ /(.*)-((\d+\.)*\d+)/ then
+ name, version = $1, $2
+ ver = Gem::Version.new version
+ if ri_paths[name].nil? or ver > ri_paths[name][0] then
+ ri_paths[name] = [ver, dir]
+ end
+ end
+ end
+
+ GEMDIRS = ri_paths.map { |k,v| v.last }.sort
+ GEMDIRS.each { |dir| PATH << dir }
+ rescue LoadError
+ GEMDIRS = []
+ end
+
+ # Returns the selected documentation directories as an Array, or PATH if no
+ # overriding directories were given.
+
+ def self.path(use_system, use_site, use_home, use_gems, *extra_dirs)
+ path = raw_path(use_system, use_site, use_home, use_gems, *extra_dirs)
+ return path.select { |directory| File.directory? directory }
+ end
+
+ # Returns the selected documentation directories including nonexistent
+ # directories. Used to print out what paths were searched if no ri was
+ # found.
+
+ def self.raw_path(use_system, use_site, use_home, use_gems, *extra_dirs)
+ return PATH unless use_system or use_site or use_home or use_gems or
+ not extra_dirs.empty?
+
+ path = []
+ path << extra_dirs unless extra_dirs.empty?
+ path << SYSDIR if use_system
+ path << SITEDIR if use_site
+ path << HOMEDIR if use_home
+ path << GEMDIRS if use_gems
+
+ return path.flatten.compact
+ end
+
+end
+
diff -Nur --exclude=doc ruby-1.9.0/lib/rdoc/ri/reader.rb ../rdoc-f95-20080316/ri/reader.rb
--- ruby-1.9.0/lib/rdoc/ri/reader.rb 1970-01-01 09:00:00.000000000 +0900
+++ ../rdoc-f95-20080316/ri/reader.rb 2008-03-09 01:37:55.000000000 +0900
@@ -0,0 +1,106 @@
+require 'rdoc/ri'
+require 'rdoc/ri/descriptions'
+require 'rdoc/ri/writer'
+require 'rdoc/markup/to_flow'
+
+class RDoc::RI::Reader
+
+ def initialize(ri_cache)
+ @cache = ri_cache
+ end
+
+ def top_level_namespace
+ [ @cache.toplevel ]
+ end
+
+ def lookup_namespace_in(target, namespaces)
+ result = []
+ for n in namespaces
+ result.concat(n.contained_modules_matching(target))
+ end
+ 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|
+ result.concat ns.methods_matching(name, is_class_method)
+ end
+ result
+ end
+
+ ##
+ # Return the MethodDescription for a given MethodEntry by deserializing the
+ # YAML
+
+ def get_method(method_entry)
+ path = method_entry.path_name
+ File.open(path) { |f| RI::Description.deserialize(f) }
+ end
+
+ ##
+ # Return a class description
+
+ def get_class(class_entry)
+ result = nil
+ for path in class_entry.path_names
+ path = RiWriter.class_desc_path(path, class_entry)
+ desc = File.open(path) {|f| RI::Description.deserialize(f) }
+ if result
+ result.merge_in(desc)
+ else
+ result = desc
+ end
+ end
+ result
+ end
+
+ ##
+ # Return the names of all classes and modules
+
+ def full_class_names
+ res = []
+ find_classes_in(res, @cache.toplevel)
+ end
+
+ ##
+ # Return a list of all classes, modules, and methods
+
+ def all_names
+ res = []
+ find_names_in(res, @cache.toplevel)
+ end
+
+ private
+
+ def find_classes_in(res, klass)
+ classes = klass.classes_and_modules
+ for c in classes
+ res << c.full_name
+ find_classes_in(res, c)
+ end
+ res
+ end
+
+ def find_names_in(res, klass)
+ classes = klass.classes_and_modules
+ for c in classes
+ res << c.full_name
+ res.concat c.all_method_names
+ find_names_in(res, c)
+ end
+ res
+ end
+
+end
+
diff -Nur --exclude=doc ruby-1.9.0/lib/rdoc/ri/util.rb ../rdoc-f95-20080316/ri/util.rb
--- ruby-1.9.0/lib/rdoc/ri/util.rb 1970-01-01 09:00:00.000000000 +0900
+++ ../rdoc-f95-20080316/ri/util.rb 2008-03-09 01:37:55.000000000 +0900
@@ -0,0 +1,81 @@
+require 'rdoc/ri'
+
+class RDoc::RI::Error < RuntimeError; end
+
+##
+# Break argument into its constituent class or module names, an
+# optional method type, and a method name
+
+class RDoc::RI::NameDescriptor
+
+ attr_reader :class_names
+ attr_reader :method_name
+
+ ##
+ # true and false have the obvious meaning. nil means we don't care
+
+ attr_reader :is_class_method
+
+ ##
+ # +arg+ may be
+ #
+ # 1. A class or module name (optionally qualified with other class or module
+ # names (Kernel, File::Stat etc)
+ # 2. A method name
+ # 3. A method name qualified by a optionally fully qualified class or module
+ # name
+ #
+ # We're fairly casual about delimiters: folks can say Kernel::puts,
+ # Kernel.puts, or Kernel\#puts for example. There's one exception: if you
+ # say IO::read, we look for a class method, but if you say IO.read, we look
+ # for an instance method
+
+ def initialize(arg)
+ @class_names = []
+ separator = nil
+
+ tokens = arg.split(/(\.|::|#)/)
+
+ # Skip leading '::', '#' or '.', but remember it might
+ # be a method name qualifier
+ separator = tokens.shift if tokens[0] =~ /^(\.|::|#)/
+
+ # Skip leading '::', but remember we potentially have an inst
+
+ # leading stuff must be class names
+
+ while tokens[0] =~ /^[A-Z]/
+ @class_names << tokens.shift
+ unless tokens.empty?
+ separator = tokens.shift
+ break unless separator == "::"
+ end
+ end
+
+ # Now must have a single token, the method name, or an empty array
+ unless tokens.empty?
+ @method_name = tokens.shift
+ # We may now have a trailing !, ?, or = to roll into
+ # the method name
+ if !tokens.empty? && tokens[0] =~ /^[!?=]$/
+ @method_name << tokens.shift
+ end
+
+ if @method_name =~ /::|\.|#/ or !tokens.empty?
+ raise RiError.new("Bad argument: #{arg}")
+ end
+ if separator && separator != '.'
+ @is_class_method = separator == "::"
+ end
+ end
+ end
+
+ # Return the full class name (with '::' between the components) or "" if
+ # there's no class name
+
+ def full_class_name
+ @class_names.join("::")
+ end
+
+end
+
diff -Nur --exclude=doc ruby-1.9.0/lib/rdoc/ri/writer.rb ../rdoc-f95-20080316/ri/writer.rb
--- ruby-1.9.0/lib/rdoc/ri/writer.rb 1970-01-01 09:00:00.000000000 +0900
+++ ../rdoc-f95-20080316/ri/writer.rb 2008-03-09 01:37:55.000000000 +0900
@@ -0,0 +1,64 @@
+require 'fileutils'
+require 'rdoc/ri'
+
+class RDoc::RI::Writer
+
+ def self.class_desc_path(dir, class_desc)
+ File.join(dir, "cdesc-" + class_desc.name + ".yaml")
+ end
+
+ ##
+ # Convert a name from internal form (containing punctuation) to an external
+ # form (where punctuation is replaced by %xx)
+
+ def self.internal_to_external(name)
+ name.gsub(/\W/) { "%%%02x" % $&[0].ord }
+ end
+
+ ##
+ # And the reverse operation
+
+ def self.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
+
+ def remove_class(class_desc)
+ FileUtils.rm_rf(path_to_dir(class_desc.full_name))
+ end
+
+ def add_class(class_desc)
+ dir = path_to_dir(class_desc.full_name)
+ FileUtils.mkdir_p(dir)
+ class_file_name = self.class.class_desc_path(dir, class_desc)
+ File.open(class_file_name, "w") do |f|
+ f.write(class_desc.serialize)
+ end
+ end
+
+ def add_method(class_desc, method_desc)
+ dir = path_to_dir(class_desc.full_name)
+ file_name = self.class.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
+ meth_file_name += "-i.yaml"
+ end
+
+ File.open(meth_file_name, "w") do |f|
+ f.write(method_desc.serialize)
+ end
+ end
+
+ private
+
+ def path_to_dir(class_name)
+ File.join(@base_dir, *class_name.split('::'))
+ end
+
+end
+
diff -Nur --exclude=doc ruby-1.9.0/lib/rdoc/ri.rb ../rdoc-f95-20080316/ri.rb
--- ruby-1.9.0/lib/rdoc/ri.rb 1970-01-01 09:00:00.000000000 +0900
+++ ../rdoc-f95-20080316/ri.rb 2008-03-09 02:14:19.000000000 +0900
@@ -0,0 +1,2 @@
+module RDoc::RI; end
+
diff -Nur --exclude=doc ruby-1.9.0/lib/rdoc/stats.rb ../rdoc-f95-20080316/stats.rb
--- ruby-1.9.0/lib/rdoc/stats.rb 1970-01-01 09:00:00.000000000 +0900
+++ ../rdoc-f95-20080316/stats.rb 2008-03-09 03:43:55.000000000 +0900
@@ -0,0 +1,23 @@
+##
+# Simple stats collector
+
+class RDoc::Stats
+
+ attr_accessor :num_files, :num_classes, :num_modules, :num_methods
+
+ def initialize
+ @num_files = @num_classes = @num_modules = @num_methods = 0
+ @start = Time.now
+ end
+
+ def print
+ puts "Files: #@num_files"
+ puts "Classes: #@num_classes"
+ puts "Modules: #@num_modules"
+ puts "Methods: #@num_methods"
+ puts "Elapsed: " + sprintf("%0.3fs", Time.now - @start)
+ end
+
+end
+
+
diff -Nur --exclude=doc ruby-1.9.0/lib/rdoc/template.rb ../rdoc-f95-20080316/template.rb
--- ruby-1.9.0/lib/rdoc/template.rb 1970-01-01 09:00:00.000000000 +0900
+++ ../rdoc-f95-20080316/template.rb 2008-03-08 16:56:01.000000000 +0900
@@ -0,0 +1,64 @@
+require 'erb'
+
+##
+# An ERB wrapper.
+#
+# This TemplatePage operates similarly to RDoc 1.x's TemplatePage, but uses
+# ERB instead of a custom template language.
+#
+# Converting from a RDoc 1.x template to an RDoc 2.x template is fairly easy.
+#
+# * %blah% becomes <%= values["blah"] %>
+# * !INCLUDE! becomes <%= template_include %>
+# * HREF:aref:name becomes <%= href values["aref"], values["name"] %>
+# * IF:blah becomes <% if values["blah"] then %>
+# * IFNOT:blah becomes <% unless values["blah"] then %>
+# * ENDIF:blah becomes <% end %>
+# * START:blah becomes <% values["blah"].each do |blah| %>
+# * END:blah becomes <% end %>
+#
+# To make nested loops easier to convert, start by converting START statements
+# to:
+#
+# <% values["blah"].each do |blah| $stderr.puts blah.keys %>
+#
+# So you can see what is being used inside which loop.
+
+module RDoc
+end
+class RDoc::TemplatePage
+
+ ##
+ # Create a new TemplatePage that will use +templates+.
+
+ def initialize(*templates)
+ @templates = templates
+ end
+
+ ##
+ # Returns "#{name}"
+
+ def href(ref, name)
+ if ref then
+ "#{name}"
+ else
+ name
+ end
+ end
+
+ ##
+ # Process the template using +values+, writing the result to +io+.
+
+ def write_html_on(io, values)
+ b = binding
+ template_include = ""
+
+ @templates.reverse_each do |template|
+ template_include = ERB.new(template).result b
+ end
+
+ io.write template_include
+ end
+
+end
+
diff -Nur --exclude=doc ruby-1.9.0/lib/rdoc/tokenstream.rb ../rdoc-f95-20080316/tokenstream.rb
--- ruby-1.9.0/lib/rdoc/tokenstream.rb 1970-01-01 09:00:00.000000000 +0900
+++ ../rdoc-f95-20080316/tokenstream.rb 2008-03-08 16:56:01.000000000 +0900
@@ -0,0 +1,33 @@
+module RDoc; end
+
+##
+# A TokenStream is a list of tokens, gathered during the parse of some entity
+# (say a method). Entities populate these streams by being registered with the
+# lexer. Any class can collect tokens by including TokenStream. From the
+# outside, you use such an object by calling the start_collecting_tokens
+# method, followed by calls to add_token and pop_token.
+
+module RDoc::TokenStream
+
+ def token_stream
+ @token_stream
+ end
+
+ def start_collecting_tokens
+ @token_stream = []
+ end
+
+ def add_token(tk)
+ @token_stream << tk
+ end
+
+ def add_tokens(tks)
+ tks.each {|tk| add_token(tk)}
+ end
+
+ def pop_token
+ @token_stream.pop
+ end
+
+end
+
diff -Nur --exclude=doc ruby-1.9.0/lib/rdoc/usage.rb ../rdoc-f95-20080316/usage.rb
--- ruby-1.9.0/lib/rdoc/usage.rb 1970-01-01 09:00:00.000000000 +0900
+++ ../rdoc-f95-20080316/usage.rb 2005-09-22 16:49:18.000000000 +0900
@@ -0,0 +1,210 @@
+# = Synopsis
+#
+# This library allows command-line tools to encapsulate their usage
+# as a comment at the top of the main file. Calling RDoc::usage
+# then displays some or all of that comment, and optionally exits
+# the program with an exit status. We always look for the comment
+# in the main program file, so it is safe to call this method
+# from anywhere in the executing program.
+#
+# = Usage
+#
+# RDoc::usage( [ exit_status ], [ section, ...])
+# RDoc::usage_no_exit( [ section, ...])
+#
+# where:
+#
+# exit_status::
+# the integer exit code (default zero). RDoc::usage will exit
+# the calling program with this status.
+#
+# section::
+# an optional list of section names. If specified, only the
+# sections with the given names as headings will be output.
+# For example, this section is named 'Usage', and the next
+# section is named 'Examples'. The section names are case
+# insensitive.
+#
+# = Examples
+#
+# # Comment block describing usage
+# # with (optional) section headings
+# # . . .
+#
+# require 'rdoc/usage'
+#
+# # Display all usage and exit with a status of 0
+#
+# RDoc::usage
+#
+# # Display all usage and exit with a status of 99
+#
+# RDoc::usage(99)
+#
+# # Display usage in the 'Summary' section only, then
+# # exit with a status of 99
+#
+# RDoc::usage(99, 'Summary')
+#
+# # Display information in the Author and Copyright
+# # sections, then exit 0.
+#
+# RDoc::usage('Author', 'Copyright')
+#
+# # Display information in the Author and Copyright
+# # sections, but don't exit
+#
+# RDoc::usage_no_exit('Author', 'Copyright')
+#
+# = Author
+#
+# Dave Thomas, The Pragmatic Programmers, LLC
+#
+# = Copyright
+#
+# Copyright (c) 2004 Dave Thomas.
+# Licensed under the same terms as Ruby
+#
+
+require 'rdoc/markup/simple_markup'
+require 'rdoc/markup/simple_markup/to_flow'
+require 'rdoc/ri/ri_formatter'
+require 'rdoc/ri/ri_options'
+
+module RDoc
+
+ # Display usage information from the comment at the top of
+ # the file. String arguments identify specific sections of the
+ # comment to display. An optional integer first argument
+ # specifies the exit status (defaults to 0)
+
+ def RDoc.usage(*args)
+ exit_code = 0
+
+ if args.size > 0
+ status = args[0]
+ if status.respond_to?(:to_int)
+ exit_code = status.to_int
+ args.shift
+ end
+ end
+
+ # display the usage and exit with the given code
+ usage_no_exit(*args)
+ exit(exit_code)
+ end
+
+ # Display usage
+ def RDoc.usage_no_exit(*args)
+ main_program_file, = caller[-1].split(/:\d+/, 2)
+ comment = File.open(main_program_file) do |file|
+ find_comment(file)
+ end
+
+ comment = comment.gsub(/^\s*#/, '')
+
+ markup = SM::SimpleMarkup.new
+ flow_convertor = SM::ToFlow.new
+
+ flow = markup.convert(comment, flow_convertor)
+
+ format = "plain"
+
+ unless args.empty?
+ flow = extract_sections(flow, args)
+ end
+
+ options = RI::Options.instance
+ if args = ENV["RI"]
+ options.parse(args.split)
+ end
+ formatter = options.formatter.new(options, "")
+ formatter.display_flow(flow)
+ end
+
+ ######################################################################
+
+ private
+
+ # Find the first comment in the file (that isn't a shebang line)
+ # If the file doesn't start with a comment, report the fact
+ # and return empty string
+
+ def RDoc.gets(file)
+ if (line = file.gets) && (line =~ /^#!/) # shebang
+ throw :exit, find_comment(file)
+ else
+ line
+ end
+ end
+
+ def RDoc.find_comment(file)
+ catch(:exit) do
+ # skip leading blank lines
+ 0 while (line = gets(file)) && (line =~ /^\s*$/)
+
+ comment = []
+ while line && line =~ /^\s*#/
+ comment << line
+ line = gets(file)
+ end
+
+ 0 while line && (line = gets(file))
+ return no_comment if comment.empty?
+ return comment.join
+ end
+ end
+
+
+ #####
+ # Given an array of flow items and an array of section names, extract those
+ # sections from the flow which have headings corresponding to
+ # a section name in the list. Return them in the order
+ # of names in the +sections+ array.
+
+ def RDoc.extract_sections(flow, sections)
+ result = []
+ sections.each do |name|
+ name = name.downcase
+ copy_upto_level = nil
+
+ flow.each do |item|
+ case item
+ when SM::Flow::H
+ if copy_upto_level && item.level >= copy_upto_level
+ copy_upto_level = nil
+ else
+ if item.text.downcase == name
+ result << item
+ copy_upto_level = item.level
+ end
+ end
+ else
+ if copy_upto_level
+ result << item
+ end
+ end
+ end
+ end
+ if result.empty?
+ puts "Note to developer: requested section(s) [#{sections.join(', ')}] " +
+ "not found"
+ result = flow
+ end
+ result
+ end
+
+ #####
+ # Report the fact that no doc comment count be found
+ def RDoc.no_comment
+ $stderr.puts "No usage information available for this program"
+ ""
+ end
+end
+
+
+if $0 == __FILE__
+
+ RDoc::usage(*ARGV)
+
+end
|