From cc2a16d94d744d14d4a5eb06eca22137f8a9b79e Mon Sep 17 00:00:00 2001 From: drbrain Date: Wed, 2 Feb 2011 00:32:30 +0000 Subject: Import RDoc 3.5.1 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@30760 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- lib/rdoc/anon_class.rb | 2 + lib/rdoc/any_method.rb | 45 +++- lib/rdoc/class_module.rb | 4 +- lib/rdoc/code_object.rb | 18 ++ lib/rdoc/context.rb | 18 +- lib/rdoc/encoding.rb | 1 - lib/rdoc/generator.rb | 2 +- lib/rdoc/generator/markup.rb | 4 + .../generator/template/darkfish/classpage.rhtml | 2 +- lib/rdoc/generator/template/darkfish/rdoc.css | 26 +- lib/rdoc/markup.rb | 6 +- lib/rdoc/markup/attribute_manager.rb | 1 - lib/rdoc/markup/heading.rb | 2 +- lib/rdoc/markup/inline.rb | 2 +- lib/rdoc/markup/parser.rb | 2 +- lib/rdoc/markup/to_html.rb | 2 +- lib/rdoc/markup/to_html_crossref.rb | 6 +- lib/rdoc/markup/to_rdoc.rb | 2 +- lib/rdoc/normal_class.rb | 7 + lib/rdoc/normal_module.rb | 7 + lib/rdoc/options.rb | 67 +++-- lib/rdoc/parser.rb | 2 +- lib/rdoc/parser/c.rb | 194 ++++++++++---- lib/rdoc/parser/ruby.rb | 90 ++++++- lib/rdoc/rdoc.rb | 42 ++- lib/rdoc/ri/driver.rb | 40 ++- lib/rdoc/ruby_lex.rb | 8 +- lib/rdoc/single_class.rb | 9 + lib/rdoc/stats.rb | 290 +++++++++++++++------ lib/rdoc/task.rb | 76 ++++-- lib/rdoc/text.rb | 11 +- 31 files changed, 757 insertions(+), 231 deletions(-) (limited to 'lib/rdoc') diff --git a/lib/rdoc/anon_class.rb b/lib/rdoc/anon_class.rb index 0a684f2dfb..63c09e11f1 100644 --- a/lib/rdoc/anon_class.rb +++ b/lib/rdoc/anon_class.rb @@ -4,6 +4,8 @@ require 'rdoc/class_module' # An anonymous class like: # # c = Class.new do end +# +# AnonClass is currently not used. class RDoc::AnonClass < RDoc::ClassModule end diff --git a/lib/rdoc/any_method.rb b/lib/rdoc/any_method.rb index f993621f8b..5877ec9662 100644 --- a/lib/rdoc/any_method.rb +++ b/lib/rdoc/any_method.rb @@ -13,6 +13,11 @@ class RDoc::AnyMethod < RDoc::MethodAttr attr_accessor :dont_rename_initialize + ## + # The C function that implements this method (if it was defined in a C file) + + attr_accessor :c_function + ## # Different ways to call this method @@ -31,8 +36,9 @@ class RDoc::AnyMethod < RDoc::MethodAttr def initialize text, name super + @c_function = nil @dont_rename_initialize = false - @token_stream = nil + @token_stream = nil end ## @@ -140,12 +146,41 @@ class RDoc::AnyMethod < RDoc::MethodAttr end ## - # Pretty parameter list for this method + # A list of this method's method and yield parameters. +call-seq+ params + # are preferred over parsed method and block params. + + def param_list + if @call_seq then + params = @call_seq.split("\n").last + params = params.sub(/.*?\((.*)\)/, '\1') + params = params.sub(/(\{|do)\s*\|([^|]*)\|.*/, ',\2') + elsif @params then + params = @params.sub(/\((.*)\)/, '\1') + + params << ",#{@block_params}" if @block_params + elsif @block_params then + params = @block_params + else + return [] + end + + params.gsub(/\s+/, '').split ',' + end + + ## + # Pretty parameter list for this method. If the method's parameters were + # given by +call-seq+ it is preferred over the parsed values. def param_seq - params = @params.gsub(/\s*\#.*/, '') - params = params.tr("\n", " ").squeeze(" ") - params = "(#{params})" unless params[0] == ?( + if @call_seq then + params = @call_seq.split("\n").last + params = params.sub(/[^( ]+/, '') + params = params.sub(/(\|[^|]+\|)\s*\.\.\.\s*(end|\})/, '\1 \2') + else + params = @params.gsub(/\s*\#.*/, '') + params = params.tr("\n", " ").squeeze(" ") + params = "(#{params})" unless params[0] == ?( + end if @block_params then # If this method has explicit block parameters, remove any explicit diff --git a/lib/rdoc/class_module.rb b/lib/rdoc/class_module.rb index 64ccfdabd6..3f2d04488e 100644 --- a/lib/rdoc/class_module.rb +++ b/lib/rdoc/class_module.rb @@ -151,7 +151,7 @@ class RDoc::ClassModule < RDoc::Context end ## - # Finds a class or module with +name+ in this namespace or its descendents + # Finds a class or module with +name+ in this namespace or its descendants def find_class_named name return self if full_name == name @@ -308,7 +308,7 @@ class RDoc::ClassModule < RDoc::Context ## # Name to use to generate the url: # modules and classes that are aliases for another - # module or classe return the name of the latter. + # module or class return the name of the latter. def name_for_path is_alias_for ? is_alias_for.full_name : full_name diff --git a/lib/rdoc/code_object.rb b/lib/rdoc/code_object.rb index 02b2f2fcf6..3a8adfab67 100644 --- a/lib/rdoc/code_object.rb +++ b/lib/rdoc/code_object.rb @@ -60,11 +60,23 @@ class RDoc::CodeObject attr_reader :force_documentation + ## + # Line in #file where this CodeObject was defined + + attr_accessor :line + ## # Hash of arbitrary metadata for this CodeObject attr_reader :metadata + ## + # Offset in #file where this CodeObject was defined + #-- + # TODO character or byte? + + attr_accessor :offset + ## # Our parent CodeObject @@ -115,6 +127,12 @@ class RDoc::CodeObject if comment and not comment.empty? then normalize_comment comment else + # TODO is this sufficient? + # HACK correct fix is to have #initialize create @comment + # with the correct encoding + if Object.const_defined? :Encoding and @comment.empty? then + @comment.force_encoding comment.encoding + end @comment end end diff --git a/lib/rdoc/context.rb b/lib/rdoc/context.rb index c424ef1676..3c12d10058 100644 --- a/lib/rdoc/context.rb +++ b/lib/rdoc/context.rb @@ -188,7 +188,6 @@ class RDoc::Context < RDoc::CodeObject @in_files = [] @name ||= "unknown" - @comment ||= "" @parent = nil @visibility = :public @@ -440,10 +439,13 @@ class RDoc::Context < RDoc::CodeObject # HACK: avoid duplicate 'PI' & 'E' in math.c (1.8.7 source code) # (this is a #ifdef: should be handled by the C parser) known = @constants_hash[constant.name] - if known - #$stderr.puts "\nconstant #{constant.name} already registered" + + if known then known.comment = constant.comment if known.comment.empty? - known.value = constant.value if known.value.nil? or known.value.strip.empty? + + known.value = constant.value if + known.value.nil? or known.value.strip.empty? + known.is_alias_for ||= constant.is_alias_for else @constants_hash[constant.name] = constant @@ -495,9 +497,10 @@ class RDoc::Context < RDoc::CodeObject end ## - # Adds an alias from +from+ (a class or module) to +name+. + # Adds an alias from +from+ (a class or module) to +name+ which was defined + # in +file+. - def add_module_alias from, name + def add_module_alias from, name, file return from if @done_documenting to_name = child_name(name) @@ -519,7 +522,8 @@ class RDoc::Context < RDoc::CodeObject # HACK: register a constant for this alias: # constant value and comment will be updated after, # when the Ruby parser adds the constant - const = RDoc::Constant.new(name, nil, '') + const = RDoc::Constant.new name, nil, '' + const.record_location file const.is_alias_for = from add_constant const diff --git a/lib/rdoc/encoding.rb b/lib/rdoc/encoding.rb index 73ae505daf..8483aabbc6 100644 --- a/lib/rdoc/encoding.rb +++ b/lib/rdoc/encoding.rb @@ -78,4 +78,3 @@ module RDoc::Encoding end - diff --git a/lib/rdoc/generator.rb b/lib/rdoc/generator.rb index d02a7538c0..2fa891f533 100644 --- a/lib/rdoc/generator.rb +++ b/lib/rdoc/generator.rb @@ -22,7 +22,7 @@ require 'rdoc' # use RDoc::Options#option_parser to add command-line options to the +rdoc+ # tool. See OptionParser for details on how to add options. # -# You can extend the RDoc::Options instance with additional accesors for your +# You can extend the RDoc::Options instance with additional accessors for your # generator. # # = Generator Instantiation diff --git a/lib/rdoc/generator/markup.rb b/lib/rdoc/generator/markup.rb index 482fd2b2a3..dd7c73044d 100644 --- a/lib/rdoc/generator/markup.rb +++ b/lib/rdoc/generator/markup.rb @@ -1,7 +1,11 @@ +# This file is loaded by generators. It allows RDoc's CodeObject tree to +# avoid loading generator code to increase startup time (for ri). + require 'rdoc/text' require 'rdoc/code_objects' require 'rdoc/generator' require 'rdoc/markup/to_html_crossref' +require 'rdoc/ruby_token' ## # Handle common RDoc::Markup tasks for various CodeObjects diff --git a/lib/rdoc/generator/template/darkfish/classpage.rhtml b/lib/rdoc/generator/template/darkfish/classpage.rhtml index 7d0cad0eed..4a1bdcdea9 100644 --- a/lib/rdoc/generator/template/darkfish/classpage.rhtml +++ b/lib/rdoc/generator/template/darkfish/classpage.rhtml @@ -228,7 +228,7 @@ <% if method.call_seq %> <% method.call_seq.strip.split("\n").each_with_index do |call_seq, i| %>
- <%= call_seq.strip.gsub(/->/, '→').gsub( /^\w.+\./m, '') %> + <%= call_seq.strip.gsub(/->/, '→').gsub( /^\w+\./m, '') %> <% if i == 0 %> click to toggle source <% end %> diff --git a/lib/rdoc/generator/template/darkfish/rdoc.css b/lib/rdoc/generator/template/darkfish/rdoc.css index 231f9b7f04..59f568ae47 100644 --- a/lib/rdoc/generator/template/darkfish/rdoc.css +++ b/lib/rdoc/generator/template/darkfish/rdoc.css @@ -97,6 +97,11 @@ body.file p { margin: 1em 0; } +.indexpage ol, +.file #documentation ol { + line-height: 160%; +} + .indexpage ul, .file #documentation ul { line-height: 160%; @@ -110,6 +115,20 @@ body.file p { .indexpage li, .file #documentation li { padding-left: 20px; +} + +.indexpage ol, +.file #documentation ol { + margin-left: 20px; +} + +.indexpage ol > li, +.file #documentation ol > li { + padding-left: 0; +} + +.indexpage ul > li, +.file #documentation ul > li { background: url(images/bullet_black.png) no-repeat left 4px; } .indexpage li.module { @@ -389,9 +408,14 @@ ul.link-list .type { #documentation .method-description, #documentation .aliases { margin: 0 20px; - line-height: 1.2em; color: #666; } + +#documentation .method-description p, +#documentation .aliases p { + line-height: 1.2em; +} + #documentation .aliases { padding-top: 4px; font-style: italic; diff --git a/lib/rdoc/markup.rb b/lib/rdoc/markup.rb index c8914fea11..9a2e7f2ca8 100644 --- a/lib/rdoc/markup.rb +++ b/lib/rdoc/markup.rb @@ -483,7 +483,7 @@ require 'rdoc' # [+:include:+ _filename_] # Include the contents of the named file at this point. This directive # must appear alone on one line, possibly preceded by spaces. In this -# position, it can be escapd with a \ in front of the first colon. +# position, it can be escaped with a \ in front of the first colon. # # The file will be searched for in the directories listed by the +--include+ # option, or in the current directory by default. The contents of the file @@ -537,8 +537,8 @@ class RDoc::Markup # structure (paragraphs, lists, and so on). Invoke an event handler as we # identify significant chunks. - def initialize - @attribute_manager = RDoc::Markup::AttributeManager.new + def initialize attribute_manager = nil + @attribute_manager = attribute_manager || RDoc::Markup::AttributeManager.new @output = nil end diff --git a/lib/rdoc/markup/attribute_manager.rb b/lib/rdoc/markup/attribute_manager.rb index 2ee243ab0b..d2402f1b1d 100644 --- a/lib/rdoc/markup/attribute_manager.rb +++ b/lib/rdoc/markup/attribute_manager.rb @@ -74,7 +74,6 @@ class RDoc::Markup::AttributeManager add_html "code", :TT end - ## # Return an attribute object with the given turn_on and turn_off bits set diff --git a/lib/rdoc/markup/heading.rb b/lib/rdoc/markup/heading.rb index 081d637729..3bda77a1e1 100644 --- a/lib/rdoc/markup/heading.rb +++ b/lib/rdoc/markup/heading.rb @@ -4,7 +4,7 @@ class RDoc::Markup::Heading < Struct.new :level, :text ## - # Calls #accept_heading on +wisitor+ + # Calls #accept_heading on +visitor+ def accept visitor visitor.accept_heading self diff --git a/lib/rdoc/markup/inline.rb b/lib/rdoc/markup/inline.rb index f5bf98a071..932ed536b7 100644 --- a/lib/rdoc/markup/inline.rb +++ b/lib/rdoc/markup/inline.rb @@ -29,7 +29,7 @@ class RDoc::Markup end ## - # Returns a string reperesentation of +bitmap+ + # Returns a string representation of +bitmap+ def self.as_string(bitmap) return "none" if bitmap.zero? diff --git a/lib/rdoc/markup/parser.rb b/lib/rdoc/markup/parser.rb index ea02ee3c5b..c94b900154 100644 --- a/lib/rdoc/markup/parser.rb +++ b/lib/rdoc/markup/parser.rb @@ -321,7 +321,7 @@ class RDoc::Markup::Parser next end - # indentation change: break or verbattim + # indentation change: break or verbatim if column < indent then unget break diff --git a/lib/rdoc/markup/to_html.rb b/lib/rdoc/markup/to_html.rb index 66f5c1986d..d587a8abbc 100644 --- a/lib/rdoc/markup/to_html.rb +++ b/lib/rdoc/markup/to_html.rb @@ -130,7 +130,7 @@ class RDoc::Markup::ToHtml < RDoc::Markup::Formatter end ## - # Here's a hypedlink where the label is different to the URL + # Here's a hyperlink where the label is different to the URL #