diff options
author | drbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2013-09-18 23:33:36 +0000 |
---|---|---|
committer | drbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2013-09-18 23:33:36 +0000 |
commit | df7dac9174a31e71b58be6184e23bfe6b742a494 (patch) | |
tree | 885edf624f0e8f37014b0d937340ac1c372a0066 /lib/rdoc/ri | |
parent | fed428007c015ac3b7f4586f2491517fafffa030 (diff) |
* lib/rdoc: Update to RDoc 4.1.0.preview.1
RDoc 4.1.0 contains a number of enhancements including a new default
style and accessibility support. You can see the changelog here:
https://github.com/rdoc/rdoc/blob/v4.1.0.preview.1/History.rdoc
* test/rdoc: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42971 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/rdoc/ri')
-rw-r--r-- | lib/rdoc/ri/driver.rb | 281 |
1 files changed, 177 insertions, 104 deletions
diff --git a/lib/rdoc/ri/driver.rb b/lib/rdoc/ri/driver.rb index 88d87f8084..39064c1384 100644 --- a/lib/rdoc/ri/driver.rb +++ b/lib/rdoc/ri/driver.rb @@ -197,7 +197,7 @@ The ri pager can be set with the 'RI_PAGER' environment variable or the opt.separator nil - opt.on("--[no-]pager", "-T", + opt.on("--[no-]pager", "Send output directly to stdout,", "rather than to a pager.") do |use_pager| options[:use_stdout] = !use_pager @@ -205,6 +205,13 @@ The ri pager can be set with the 'RI_PAGER' environment variable or the opt.separator nil + opt.on("-T", + "Synonym for --no-pager") do + options[:use_stdout] = true + end + + opt.separator nil + opt.on("--width=WIDTH", "-w", OptionParser::DecimalInteger, "Set the width of the output.") do |width| options[:width] = width @@ -459,38 +466,51 @@ The ri pager can be set with the 'RI_PAGER' environment variable or the extensions.each do |modules, store| if modules.length == 1 then - include = modules.first - name = include.name - path = store.friendly_path - out << RDoc::Markup::Paragraph.new("#{name} (from #{path})") - - if include.comment then - out << RDoc::Markup::BlankLine.new - out << include.comment - end + add_extension_modules_single out, store, modules.first else - out << RDoc::Markup::Paragraph.new("(from #{store.friendly_path})") + add_extension_modules_multiple out, store, modules + end + end + end - wout, with = modules.partition { |incl| incl.comment.empty? } + ## + # Renders multiple included +modules+ from +store+ to +out+. - out << RDoc::Markup::BlankLine.new unless with.empty? + def add_extension_modules_multiple out, store, modules # :nodoc: + out << RDoc::Markup::Paragraph.new("(from #{store.friendly_path})") - with.each do |incl| - out << RDoc::Markup::Paragraph.new(incl.name) - out << RDoc::Markup::BlankLine.new - out << incl.comment - end + wout, with = modules.partition { |incl| incl.comment.empty? } - unless wout.empty? then - verb = RDoc::Markup::Verbatim.new + out << RDoc::Markup::BlankLine.new unless with.empty? - wout.each do |incl| - verb.push incl.name, "\n" - end + with.each do |incl| + out << RDoc::Markup::Paragraph.new(incl.name) + out << RDoc::Markup::BlankLine.new + out << incl.comment + end - out << verb - end + unless wout.empty? then + verb = RDoc::Markup::Verbatim.new + + wout.each do |incl| + verb.push incl.name, "\n" end + + out << verb + end + end + + ## + # Adds a single extension module +include+ from +store+ to +out+ + + def add_extension_modules_single out, store, include # :nodoc: + name = include.name + path = store.friendly_path + out << RDoc::Markup::Paragraph.new("#{name} (from #{path})") + + if include.comment then + out << RDoc::Markup::BlankLine.new + out << include.comment end end @@ -596,68 +616,56 @@ The ri pager can be set with the 'RI_PAGER' environment variable or the add_extends out, extends found.each do |store, klass| - comment = klass.comment - # TODO the store's cache should always return an empty Array - class_methods = store.class_methods[klass.full_name] || [] - instance_methods = store.instance_methods[klass.full_name] || [] - attributes = store.attributes[klass.full_name] || [] - - if comment.empty? and - instance_methods.empty? and class_methods.empty? then - also_in << store - next - end - - add_from out, store + render_class out, store, klass, also_in + end - unless comment.empty? then - out << RDoc::Markup::Rule.new(1) + add_also_in out, also_in - if comment.merged? then - parts = comment.parts - parts = parts.zip [RDoc::Markup::BlankLine.new] * parts.length - parts.flatten! - parts.pop + out + end - out.concat parts - else - out << comment - end - end + ## + # Adds the class +comment+ to +out+. - if class_methods or instance_methods or not klass.constants.empty? then - out << RDoc::Markup::Rule.new(1) - end + def class_document_comment out, comment # :nodoc: + unless comment.empty? then + out << RDoc::Markup::Rule.new(1) - unless klass.constants.empty? then - out << RDoc::Markup::Heading.new(1, "Constants:") - out << RDoc::Markup::BlankLine.new - list = RDoc::Markup::List.new :NOTE + if comment.merged? then + parts = comment.parts + parts = parts.zip [RDoc::Markup::BlankLine.new] * parts.length + parts.flatten! + parts.pop - constants = klass.constants.sort_by { |constant| constant.name } + out.concat parts + else + out << comment + end + end + end - list.items.concat constants.map { |constant| - parts = constant.comment.parts if constant.comment - parts << RDoc::Markup::Paragraph.new('[not documented]') if - parts.empty? + ## + # Adds the constants from +klass+ to the Document +out+. - RDoc::Markup::ListItem.new(constant.name, *parts) - } + def class_document_constants out, klass # :nodoc: + return if klass.constants.empty? - out << list - out << RDoc::Markup::BlankLine.new - end + out << RDoc::Markup::Heading.new(1, "Constants:") + out << RDoc::Markup::BlankLine.new + list = RDoc::Markup::List.new :NOTE - add_method_list out, class_methods, 'Class methods' - add_method_list out, instance_methods, 'Instance methods' - add_method_list out, attributes, 'Attributes' + constants = klass.constants.sort_by { |constant| constant.name } - add_method_documentation out, klass if @show_all - end + list.items.concat constants.map { |constant| + parts = constant.comment.parts if constant.comment + parts << RDoc::Markup::Paragraph.new('[not documented]') if + parts.empty? - add_also_in out, also_in + RDoc::Markup::ListItem.new(constant.name, *parts) + } - out + out << list + out << RDoc::Markup::BlankLine.new end ## @@ -709,16 +717,24 @@ The ri pager can be set with the 'RI_PAGER' environment variable or the # Completes +name+ based on the caches. For Readline def complete name - klasses = classes.keys completions = [] klass, selector, method = parse_name name + complete_klass name, klass, selector, method, completions + complete_method name, klass, selector, completions + + completions.sort.uniq + end + + def complete_klass name, klass, selector, method, completions # :nodoc: + klasses = classes.keys + # may need to include Foo when given Foo:: klass_name = method ? name : klass if name !~ /#|\./ then - completions = klasses.grep(/^#{Regexp.escape klass_name}[^:]*$/) + completions.replace klasses.grep(/^#{Regexp.escape klass_name}[^:]*$/) completions.concat klasses.grep(/^#{Regexp.escape name}[^:]*$/) if name =~ /::$/ @@ -728,7 +744,9 @@ The ri pager can be set with the 'RI_PAGER' environment variable or the elsif classes.key? klass_name then completions << klass_name end + end + def complete_method name, klass, selector, completions # :nodoc: if completions.include? klass and name =~ /#|\.|::/ then methods = list_methods_matching name @@ -743,8 +761,6 @@ The ri pager can be set with the 'RI_PAGER' environment variable or the completions.concat methods end - - completions.sort.uniq end ## @@ -804,7 +820,7 @@ The ri pager can be set with the 'RI_PAGER' environment variable or the true rescue NotFoundError matches = list_methods_matching name if name =~ /::|#|\./ - matches = classes.keys.grep(/^#{name}/) if matches.empty? + matches = classes.keys.grep(/^#{Regexp.escape name}/) if matches.empty? raise if matches.empty? @@ -1183,6 +1199,12 @@ The ri pager can be set with the 'RI_PAGER' environment variable or the return unless method store.load_method klass, "#{type}#{method}" + rescue RDoc::Store::MissingFileError => e + comment = RDoc::Comment.new("missing documentation at #{e.file}").parse + + method = RDoc::AnyMethod.new nil, name + method.comment = comment + method end ## @@ -1228,30 +1250,7 @@ The ri pager can be set with the 'RI_PAGER' environment variable or the filtered.each do |store, methods| methods.each do |method| - out << RDoc::Markup::Paragraph.new("(from #{store.friendly_path})") - - unless name =~ /^#{Regexp.escape method.parent_name}/ then - out << RDoc::Markup::Heading.new(3, "Implementation from #{method.parent_name}") - end - - out << RDoc::Markup::Rule.new(1) - - if method.arglists then - arglists = method.arglists.chomp.split "\n" - arglists = arglists.map { |line| line + "\n" } - out << RDoc::Markup::Verbatim.new(*arglists) - out << RDoc::Markup::Rule.new(1) - end - - if method.respond_to?(:superclass_method) and method.superclass_method - out << RDoc::Markup::BlankLine.new - out << RDoc::Markup::Heading.new(4, "(Uses superclass method #{method.superclass_method})") - out << RDoc::Markup::Rule.new(1) - end - - out << RDoc::Markup::BlankLine.new - out << method.comment - out << RDoc::Markup::BlankLine.new + render_method out, store, method, name end end @@ -1346,6 +1345,78 @@ The ri pager can be set with the 'RI_PAGER' environment variable or the end ## + # Renders the +klass+ from +store+ to +out+. If the klass has no + # documentable items the class is added to +also_in+ instead. + + def render_class out, store, klass, also_in # :nodoc: + comment = klass.comment + # TODO the store's cache should always return an empty Array + class_methods = store.class_methods[klass.full_name] || [] + instance_methods = store.instance_methods[klass.full_name] || [] + attributes = store.attributes[klass.full_name] || [] + + if comment.empty? and + instance_methods.empty? and class_methods.empty? then + also_in << store + return + end + + add_from out, store + + class_document_comment out, comment + + if class_methods or instance_methods or not klass.constants.empty? then + out << RDoc::Markup::Rule.new(1) + end + + class_document_constants out, klass + + add_method_list out, class_methods, 'Class methods' + add_method_list out, instance_methods, 'Instance methods' + add_method_list out, attributes, 'Attributes' + + add_method_documentation out, klass if @show_all + end + + def render_method out, store, method, name # :nodoc: + out << RDoc::Markup::Paragraph.new("(from #{store.friendly_path})") + + unless name =~ /^#{Regexp.escape method.parent_name}/ then + out << RDoc::Markup::Heading.new(3, "Implementation from #{method.parent_name}") + end + + out << RDoc::Markup::Rule.new(1) + + render_method_arguments out, method.arglists + render_method_superclass out, method + render_method_comment out, method + end + + def render_method_arguments out, arglists # :nodoc: + return unless arglists + + arglists = arglists.chomp.split "\n" + arglists = arglists.map { |line| line + "\n" } + out << RDoc::Markup::Verbatim.new(*arglists) + out << RDoc::Markup::Rule.new(1) + end + + def render_method_comment out, method # :nodoc: + out << RDoc::Markup::BlankLine.new + out << method.comment + out << RDoc::Markup::BlankLine.new + end + + def render_method_superclass out, method # :nodoc: + return unless + method.respond_to?(:superclass_method) and method.superclass_method + + out << RDoc::Markup::BlankLine.new + out << RDoc::Markup::Heading.new(4, "(Uses superclass method #{method.superclass_method})") + out << RDoc::Markup::Rule.new(1) + end + + ## # Looks up and displays ri data according to the options given. def run @@ -1412,7 +1483,9 @@ The ri pager can be set with the 'RI_PAGER' environment variable or the server = WEBrick::HTTPServer.new :Port => @server - server.mount '/', RDoc::Servlet + extra_doc_dirs = @stores.map {|s| s.type == :extra ? s.path : nil}.compact + + server.mount '/', RDoc::Servlet, nil, extra_doc_dirs trap 'INT' do server.shutdown end trap 'TERM' do server.shutdown end |