diff --git a/doc/rdoc/markup_reference.rb b/doc/rdoc/markup_reference.rb
index 5b5cdfc706..ee585b2497 100644
--- a/doc/rdoc/markup_reference.rb
+++ b/doc/rdoc/markup_reference.rb
@@ -859,6 +859,15 @@ require 'rdoc'
# - On-page: DummyClass links to DummyClass.
# - Off-page: RDoc::Alias links to RDoc::Alias.
#
+# Note: For poeple want to mark up code (such as class, module,
+# constant, and method) as "+code+" (for interoperability
+# with other MarkDown parsers mainly), such word that refers a known
+# code object and is marked up entirely and separately as "monofont"
+# is also converted to a link.
+#
+# - +DummyClass+ links to DummyClass
+# - +DummyClass-object+ is not a link.
+#
# [Module]
#
# - On-page: DummyModule links to DummyModule.
@@ -987,8 +996,7 @@ require 'rdoc'
# and entire rdoc-ref: square-bracketed clause is removed
# from the resulting text.
#
-# - Nosuch[rdoc-ref:RDoc::Nosuch] generates
-# Nosuch[rdoc-ref:RDoc::Nosuch].
+# - Nosuch[rdoc-ref:RDoc::Nosuch] generates Nosuch.
#
#
# [rdoc-label Scheme]
diff --git a/lib/rdoc/code_object.rb b/lib/rdoc/code_object.rb
index 83997c2580..388863b06c 100644
--- a/lib/rdoc/code_object.rb
+++ b/lib/rdoc/code_object.rb
@@ -21,9 +21,10 @@
# * RDoc::MetaMethod
# * RDoc::Alias
# * RDoc::Constant
+# * RDoc::Require
# * RDoc::Mixin
-# * RDoc::Require
# * RDoc::Include
+# * RDoc::Extend
class RDoc::CodeObject
@@ -89,13 +90,6 @@ class RDoc::CodeObject
attr_reader :store
- ##
- # We are the model of the code, but we know that at some point we will be
- # worked on by viewers. By implementing the Viewable protocol, viewers can
- # associated themselves with these objects.
-
- attr_accessor :viewer
-
##
# When mixed-in to a class, this points to the Context in which it was originally defined.
@@ -141,7 +135,6 @@ class RDoc::CodeObject
def comment=(comment)
@comment = case comment
when NilClass then ''
- when RDoc::Markup::Document then comment
when RDoc::Comment then comment.normalize
else
if comment and not comment.empty? then
@@ -217,20 +210,6 @@ class RDoc::CodeObject
@document_children = @document_self
end
- ##
- # Yields each parent of this CodeObject. See also
- # RDoc::ClassModule#each_ancestor
-
- def each_parent
- code_object = self
-
- while code_object = code_object.parent do
- yield code_object
- end
-
- self
- end
-
##
# File name where this CodeObject was found.
#
@@ -257,7 +236,7 @@ class RDoc::CodeObject
#
# Set to +nil+ to clear RDoc's cached value
- def full_name= full_name
+ def full_name=(full_name)
@full_name = full_name
end
@@ -301,11 +280,7 @@ class RDoc::CodeObject
# This is used by Text#snippet
def options
- if @store and @store.rdoc then
- @store.rdoc.options
- else
- RDoc::Options.new
- end
+ @store&.options || RDoc::Options.new
end
##
@@ -331,13 +306,6 @@ class RDoc::CodeObject
end
end
- ##
- # File name of our parent
-
- def parent_file_name
- @parent ? @parent.base_name : '(unknown)'
- end
-
##
# Name of our parent
@@ -348,7 +316,7 @@ class RDoc::CodeObject
##
# Records the RDoc::TopLevel (file) where this code object was defined
- def record_location top_level
+ def record_location(top_level)
@ignored = false
@suppressed = false
@file = top_level
@@ -390,7 +358,7 @@ class RDoc::CodeObject
##
# Sets the +store+ that contains this CodeObject
- def store= store
+ def store=(store)
@store = store
return unless @track_visibility
diff --git a/lib/rdoc/code_object/alias.rb b/lib/rdoc/code_object/alias.rb
index 92df7e448f..bd5b3ec6b5 100644
--- a/lib/rdoc/code_object/alias.rb
+++ b/lib/rdoc/code_object/alias.rb
@@ -23,7 +23,7 @@ class RDoc::Alias < RDoc::CodeObject
##
# Is this an alias declared in a singleton context?
- attr_accessor :singleton
+ attr_reader :singleton
##
# Source file token stream
@@ -34,7 +34,7 @@ class RDoc::Alias < RDoc::CodeObject
# Creates a new Alias with a token stream of +text+ that aliases +old_name+
# to +new_name+, has +comment+ and is a +singleton+ context.
- def initialize(text, old_name, new_name, comment, singleton = false)
+ def initialize(text, old_name, new_name, comment, singleton: false)
super()
@text = text
@@ -59,13 +59,6 @@ class RDoc::Alias < RDoc::CodeObject
"#alias-#{type}-#{html_name}"
end
- ##
- # Full old name including namespace
-
- def full_old_name
- @full_name || "#{parent.name}#{pretty_old_name}"
- end
-
##
# HTML id-friendly version of +#new_name+.
diff --git a/lib/rdoc/code_object/any_method.rb b/lib/rdoc/code_object/any_method.rb
index 465c4a4fb2..b319f0d0dd 100644
--- a/lib/rdoc/code_object/any_method.rb
+++ b/lib/rdoc/code_object/any_method.rb
@@ -29,10 +29,6 @@ class RDoc::AnyMethod < RDoc::MethodAttr
# The section title of the method (if defined in a C file via +:category:+)
attr_accessor :section_title
- # Parameters for this method
-
- attr_accessor :params
-
##
# If true this method uses +super+ to call a superclass version
@@ -43,8 +39,8 @@ class RDoc::AnyMethod < RDoc::MethodAttr
##
# Creates a new AnyMethod with a token stream +text+ and +name+
- def initialize text, name
- super
+ def initialize(text, name, singleton: false)
+ super(text, name, singleton: singleton)
@c_function = nil
@dont_rename_initialize = false
@@ -56,11 +52,10 @@ class RDoc::AnyMethod < RDoc::MethodAttr
##
# Adds +an_alias+ as an alias for this method in +context+.
- def add_alias an_alias, context = nil
- method = self.class.new an_alias.text, an_alias.new_name
+ def add_alias(an_alias, context = nil)
+ method = self.class.new an_alias.text, an_alias.new_name, singleton: singleton
method.record_location an_alias.file
- method.singleton = self.singleton
method.params = self.params
method.visibility = self.visibility
method.comment = an_alias.comment
@@ -109,8 +104,8 @@ class RDoc::AnyMethod < RDoc::MethodAttr
#
# See also #param_seq
- def call_seq= call_seq
- return if call_seq.empty?
+ def call_seq=(call_seq)
+ return if call_seq.nil? || call_seq.empty?
@call_seq = call_seq
end
@@ -181,7 +176,7 @@ class RDoc::AnyMethod < RDoc::MethodAttr
# * #full_name
# * #parent_name
- def marshal_load array
+ def marshal_load(array)
initialize_visibility
@dont_rename_initialize = nil
@@ -198,7 +193,7 @@ class RDoc::AnyMethod < RDoc::MethodAttr
@full_name = array[2]
@singleton = array[3]
@visibility = array[4]
- @comment = array[5]
+ @comment = RDoc::Comment.from_document array[5]
@call_seq = array[6]
@block_params = array[7]
# 8 handled below
@@ -210,8 +205,8 @@ class RDoc::AnyMethod < RDoc::MethodAttr
@section_title = array[14]
@is_alias_for = array[15]
- array[8].each do |new_name, comment|
- add_alias RDoc::Alias.new(nil, @name, new_name, comment, @singleton)
+ array[8].each do |new_name, document|
+ add_alias RDoc::Alias.new(nil, @name, new_name, RDoc::Comment.from_document(document), singleton: @singleton)
end
@parent_name ||= if @full_name =~ /#/ then
@@ -314,7 +309,7 @@ class RDoc::AnyMethod < RDoc::MethodAttr
##
# Sets the store for this method and its referenced code objects.
- def store= store
+ def store=(store)
super
@file = @store.add_file @file.full_name if @file
diff --git a/lib/rdoc/code_object/attr.rb b/lib/rdoc/code_object/attr.rb
index a403235933..969b18346d 100644
--- a/lib/rdoc/code_object/attr.rb
+++ b/lib/rdoc/code_object/attr.rb
@@ -22,18 +22,17 @@ class RDoc::Attr < RDoc::MethodAttr
# Creates a new Attr with body +text+, +name+, read/write status +rw+ and
# +comment+. +singleton+ marks this as a class attribute.
- def initialize(text, name, rw, comment, singleton = false)
- super text, name
+ def initialize(text, name, rw, comment, singleton: false)
+ super(text, name, singleton: singleton)
@rw = rw
- @singleton = singleton
self.comment = comment
end
##
# Attributes are equal when their names, singleton and rw are identical
- def == other
+ def ==(other)
self.class == other.class and
self.name == other.name and
self.rw == other.rw and
@@ -44,9 +43,7 @@ class RDoc::Attr < RDoc::MethodAttr
# Add +an_alias+ as an attribute in +context+.
def add_alias(an_alias, context)
- new_attr = self.class.new(self.text, an_alias.new_name, self.rw,
- self.comment, self.singleton)
-
+ new_attr = self.class.new(text, an_alias.new_name, rw, comment, singleton: singleton)
new_attr.record_location an_alias.file
new_attr.visibility = self.visibility
new_attr.is_alias_for = self
@@ -121,7 +118,7 @@ class RDoc::Attr < RDoc::MethodAttr
# * #full_name
# * #parent_name
- def marshal_load array
+ def marshal_load(array)
initialize_visibility
@aliases = []
@@ -136,7 +133,7 @@ class RDoc::Attr < RDoc::MethodAttr
@full_name = array[2]
@rw = array[3]
@visibility = array[4]
- @comment = array[5]
+ @comment = RDoc::Comment.from_document array[5]
@singleton = array[6] || false # MARSHAL_VERSION == 0
# 7 handled below
@parent_name = array[8]
@@ -148,7 +145,7 @@ class RDoc::Attr < RDoc::MethodAttr
@parent_name ||= @full_name.split('#', 2).first
end
- def pretty_print q # :nodoc:
+ def pretty_print(q) # :nodoc:
q.group 2, "[#{self.class.name} #{full_name} #{rw} #{visibility}", "]" do
unless comment.empty? then
q.breakable
diff --git a/lib/rdoc/code_object/class_module.rb b/lib/rdoc/code_object/class_module.rb
index 33e71ab3f3..f6b0abb2f5 100644
--- a/lib/rdoc/code_object/class_module.rb
+++ b/lib/rdoc/code_object/class_module.rb
@@ -34,8 +34,6 @@ class RDoc::ClassModule < RDoc::Context
attr_accessor :comment_location
- attr_accessor :diagram # :nodoc:
-
##
# Class or module this constant is an alias for
@@ -47,7 +45,7 @@ class RDoc::ClassModule < RDoc::Context
#--
# TODO move to RDoc::NormalClass (I think)
- def self.from_module class_type, mod
+ def self.from_module(class_type, mod)
klass = class_type.new mod.name
mod.comment_location.each do |comment, location|
@@ -56,7 +54,6 @@ class RDoc::ClassModule < RDoc::Context
klass.parent = mod.parent
klass.section = mod.section
- klass.viewer = mod.viewer
klass.attributes.concat mod.attributes
klass.method_list.concat mod.method_list
@@ -110,7 +107,6 @@ class RDoc::ClassModule < RDoc::Context
def initialize(name, superclass = nil)
@constant_aliases = []
- @diagram = nil
@is_alias_for = nil
@name = name
@superclass = superclass
@@ -124,7 +120,7 @@ class RDoc::ClassModule < RDoc::Context
# method is preferred over #comment= since it allows ri data to be updated
# across multiple runs.
- def add_comment comment, location
+ def add_comment(comment, location)
return unless document_self
original = comment
@@ -145,7 +141,7 @@ class RDoc::ClassModule < RDoc::Context
self.comment = original
end
- def add_things my_things, other_things # :nodoc:
+ def add_things(my_things, other_things) # :nodoc:
other_things.each do |group, things|
my_things[group].each { |thing| yield false, thing } if
my_things.include? group
@@ -202,7 +198,7 @@ class RDoc::ClassModule < RDoc::Context
# Appends +comment+ to the current comment, but separated by a rule. Works
# more like +=.
- def comment= comment # :nodoc:
+ def comment=(comment) # :nodoc:
comment = case comment
when RDoc::Comment then
comment.normalize
@@ -220,11 +216,12 @@ class RDoc::ClassModule < RDoc::Context
#
# See RDoc::Store#complete
- def complete min_visibility
+ def complete(min_visibility)
update_aliases
remove_nodoc_children
embed_mixins
update_includes
+ update_extends
remove_invisible min_visibility
end
@@ -262,7 +259,7 @@ class RDoc::ClassModule < RDoc::Context
##
# Looks for a symbol in the #ancestors. See Context#find_local_symbol.
- def find_ancestor_local_symbol symbol
+ def find_ancestor_local_symbol(symbol)
each_ancestor do |m|
res = m.find_local_symbol(symbol)
return res if res
@@ -274,7 +271,7 @@ class RDoc::ClassModule < RDoc::Context
##
# Finds a class or module with +name+ in this namespace or its descendants
- def find_class_named name
+ def find_class_named(name)
return self if full_name == name
return self if @name == name
@@ -295,6 +292,25 @@ class RDoc::ClassModule < RDoc::Context
end
end
+ ##
+ # Return array of full_name splitted by +::+.
+
+ def nesting_namespaces
+ @namespaces ||= full_name.split("::").reject(&:empty?)
+ end
+
+ ##
+ # Return array of fully qualified nesting namespaces.
+ #
+ # For example, if full_name is +A::B::C+, this method returns ["A", "A::B", "A::B::C"]
+
+ def fully_qualified_nesting_namespaces
+ return nesting_namespaces if nesting_namespaces.length < 2
+ @fqns ||= nesting_namespaces.inject([]) do |list, n|
+ list << (list.empty? ? n : "#{list.last}::#{n}")
+ end
+ end
+
##
# TODO: filter included items by #display?
@@ -344,7 +360,7 @@ class RDoc::ClassModule < RDoc::Context
]
end
- def marshal_load array # :nodoc:
+ def marshal_load(array) # :nodoc:
initialize_visibility
initialize_methods_etc
@current_section = nil
@@ -359,37 +375,39 @@ class RDoc::ClassModule < RDoc::Context
@name = array[1]
@full_name = array[2]
@superclass = array[3]
- @comment = array[4]
+ document = array[4]
- @comment_location = if RDoc::Markup::Document === @comment.parts.first then
- @comment
+ @comment = RDoc::Comment.from_document document
+
+ @comment_location = if RDoc::Markup::Document === document.parts.first then
+ document
else
- RDoc::Markup::Document.new @comment
+ RDoc::Markup::Document.new document
end
array[5].each do |name, rw, visibility, singleton, file|
singleton ||= false
visibility ||= :public
- attr = RDoc::Attr.new nil, name, rw, nil, singleton
+ attr = RDoc::Attr.new nil, name, rw, nil, singleton: singleton
add_attribute attr
attr.visibility = visibility
attr.record_location RDoc::TopLevel.new file
end
- array[6].each do |constant, comment, file|
+ array[6].each do |constant, document, file|
case constant
when RDoc::Constant then
add_constant constant
else
- constant = add_constant RDoc::Constant.new(constant, nil, comment)
+ constant = add_constant RDoc::Constant.new(constant, nil, RDoc::Comment.from_document(document))
constant.record_location RDoc::TopLevel.new file
end
end
- array[7].each do |name, comment, file|
- incl = add_include RDoc::Include.new(name, comment)
+ array[7].each do |name, document, file|
+ incl = add_include RDoc::Include.new(name, RDoc::Comment.from_document(document))
incl.record_location RDoc::TopLevel.new file
end
@@ -398,16 +416,15 @@ class RDoc::ClassModule < RDoc::Context
@visibility = visibility
methods.each do |name, file|
- method = RDoc::AnyMethod.new nil, name
- method.singleton = true if type == 'class'
+ method = RDoc::AnyMethod.new nil, name, singleton: type == 'class'
method.record_location RDoc::TopLevel.new file
add_method method
end
end
end
- array[9].each do |name, comment, file|
- ext = add_extend RDoc::Extend.new(name, comment)
+ array[9].each do |name, document, file|
+ ext = add_extend RDoc::Extend.new(name, RDoc::Comment.from_document(document))
ext.record_location RDoc::TopLevel.new file
end if array[9] # Support Marshal version 1
@@ -433,7 +450,7 @@ class RDoc::ClassModule < RDoc::Context
#
# The data in +class_module+ is preferred over the receiver.
- def merge class_module
+ def merge(class_module)
@parent = class_module.parent
@parent_name = class_module.parent_name
@@ -444,7 +461,8 @@ class RDoc::ClassModule < RDoc::Context
document = document.merge other_document
- @comment = @comment_location = document
+ @comment = RDoc::Comment.from_document(document)
+ @comment_location = document
end
cm = class_module
@@ -517,7 +535,7 @@ class RDoc::ClassModule < RDoc::Context
# end
# end
- def merge_collections mine, other, other_files, &block # :nodoc:
+ def merge_collections(mine, other, other_files, &block) # :nodoc:
my_things = mine. group_by { |thing| thing.file }
other_things = other.group_by { |thing| thing.file }
@@ -529,7 +547,7 @@ class RDoc::ClassModule < RDoc::Context
# Merges the comments in this ClassModule with the comments in the other
# ClassModule +cm+.
- def merge_sections cm # :nodoc:
+ def merge_sections(cm) # :nodoc:
my_sections = sections.group_by { |section| section.title }
other_sections = cm.sections.group_by { |section| section.title }
@@ -577,7 +595,7 @@ class RDoc::ClassModule < RDoc::Context
#
# Used for modules and classes that are constant aliases.
- def name= new_name
+ def name=(new_name)
@name = new_name
end
@@ -585,7 +603,7 @@ class RDoc::ClassModule < RDoc::Context
# Parses +comment_location+ into an RDoc::Markup::Document composed of
# multiple RDoc::Markup::Documents with their file set.
- def parse comment_location
+ def parse(comment_location)
case comment_location
when String then
super
@@ -612,7 +630,9 @@ class RDoc::ClassModule < RDoc::Context
# Path to this class or module for use with HTML generator output.
def path
- http_url @store.rdoc.generator.class_dir
+ prefix = options.class_module_path_prefix
+ return http_url unless prefix
+ File.join(prefix, http_url)
end
##
@@ -655,7 +675,7 @@ class RDoc::ClassModule < RDoc::Context
end
end
- def remove_things my_things, other_files # :nodoc:
+ def remove_things(my_things, other_files) # :nodoc:
my_things.delete_if do |file, things|
next false unless other_files.include? file
@@ -685,7 +705,7 @@ class RDoc::ClassModule < RDoc::Context
##
# Sets the store for this class or module and its contained code objects.
- def store= store
+ def store=(store)
super
@attributes .each do |attr| attr.store = store end
diff --git a/lib/rdoc/code_object/constant.rb b/lib/rdoc/code_object/constant.rb
index 12b8be775c..d5f54edb67 100644
--- a/lib/rdoc/code_object/constant.rb
+++ b/lib/rdoc/code_object/constant.rb
@@ -44,7 +44,7 @@ class RDoc::Constant < RDoc::CodeObject
##
# Constants are ordered by name
- def <=> other
+ def <=>(other)
return unless self.class === other
[parent_name, name] <=> [other.parent_name, other.name]
@@ -53,7 +53,7 @@ class RDoc::Constant < RDoc::CodeObject
##
# Constants are equal when their #parent and #name is the same
- def == other
+ def ==(other)
self.class == other.class and
@parent == other.parent and
@name == other.name
@@ -132,8 +132,8 @@ class RDoc::Constant < RDoc::CodeObject
# * #full_name
# * #parent_name
- def marshal_load array
- initialize array[1], nil, array[5]
+ def marshal_load(array)
+ initialize array[1], nil, RDoc::Comment.from_document(array[5])
@full_name = array[2]
@visibility = array[3] || :public
@@ -154,7 +154,7 @@ class RDoc::Constant < RDoc::CodeObject
"#{@parent.path}##{@name}"
end
- def pretty_print q # :nodoc:
+ def pretty_print(q) # :nodoc:
q.group 2, "[#{self.class.name} #{full_name}", "]" do
unless comment.empty? then
q.breakable
@@ -168,7 +168,7 @@ class RDoc::Constant < RDoc::CodeObject
##
# Sets the store for this class or module and its contained code objects.
- def store= store
+ def store=(store)
super
@file = @store.add_file @file.full_name if @file
diff --git a/lib/rdoc/code_object/context.rb b/lib/rdoc/code_object/context.rb
index c688d562c3..3a4dd0ec68 100644
--- a/lib/rdoc/code_object/context.rb
+++ b/lib/rdoc/code_object/context.rb
@@ -180,7 +180,7 @@ class RDoc::Context < RDoc::CodeObject
#
# Currently only RDoc::Extend and RDoc::Include are supported.
- def add klass, name, comment
+ def add(klass, name, comment)
if RDoc::Extend == klass then
ext = RDoc::Extend.new name, comment
add_extend ext
@@ -195,7 +195,7 @@ class RDoc::Context < RDoc::CodeObject
##
# Adds +an_alias+ that is automatically resolved
- def add_alias an_alias
+ def add_alias(an_alias)
return an_alias unless @document_self
method_attr = find_method(an_alias.old_name, an_alias.singleton) ||
@@ -222,7 +222,7 @@ class RDoc::Context < RDoc::CodeObject
# if method +foo+ exists, but attr_accessor :foo will be registered
# if method +foo+ exists, but foo= does not.
- def add_attribute attribute
+ def add_attribute(attribute)
return attribute unless @document_self
# mainly to check for redefinition of an attribute as a method
@@ -285,7 +285,7 @@ class RDoc::Context < RDoc::CodeObject
# unless it later sees class Container. +add_class+ automatically
# upgrades +given_name+ to a class in this case.
- def add_class class_type, given_name, superclass = '::Object'
+ def add_class(class_type, given_name, superclass = '::Object')
# superclass +nil+ is passed by the C parser in the following cases:
# - registering Object in 1.8 (correct)
# - registering BasicObject in 1.9 (correct)
@@ -401,7 +401,7 @@ class RDoc::Context < RDoc::CodeObject
# unless #done_documenting is +true+. Sets the #parent of +mod+
# to +self+, and its #section to #current_section. Returns +mod+.
- def add_class_or_module mod, self_hash, all_hash
+ def add_class_or_module(mod, self_hash, all_hash)
mod.section = current_section # TODO declaring context? something is
# wrong here...
mod.parent = self
@@ -426,7 +426,7 @@ class RDoc::Context < RDoc::CodeObject
# Adds +constant+ if not already there. If it is, updates the comment,
# value and/or is_alias_for of the known constant if they were empty/nil.
- def add_constant constant
+ def add_constant(constant)
return constant unless @document_self
# HACK: avoid duplicate 'PI' & 'E' in math.c (1.8.7 source code)
@@ -451,7 +451,7 @@ class RDoc::Context < RDoc::CodeObject
##
# Adds included module +include+ which should be an RDoc::Include
- def add_include include
+ def add_include(include)
add_to @includes, include
include
@@ -460,7 +460,7 @@ class RDoc::Context < RDoc::CodeObject
##
# Adds extension module +ext+ which should be an RDoc::Extend
- def add_extend ext
+ def add_extend(ext)
add_to @extends, ext
ext
@@ -470,7 +470,7 @@ class RDoc::Context < RDoc::CodeObject
# Adds +method+ if not already there. If it is (as method or attribute),
# updates the comment if it was empty.
- def add_method method
+ def add_method(method)
return method unless @document_self
# HACK: avoid duplicate 'new' in io.c & struct.c (1.8.7 source code)
@@ -482,7 +482,7 @@ class RDoc::Context < RDoc::CodeObject
known.comment = method.comment if known.comment.empty?
previously = ", previously in #{known.file}" unless
method.file == known.file
- @store.rdoc.options.warn \
+ @store.options.warn \
"Duplicate method #{known.full_name} in #{method.file}#{previously}"
end
else
@@ -524,7 +524,7 @@ class RDoc::Context < RDoc::CodeObject
# Adds an alias from +from+ (a class or module) to +name+ which was defined
# in +file+.
- def add_module_alias from, from_name, to, file
+ def add_module_alias(from, from_name, to, file)
return from if @done_documenting
to_full_name = child_name to.name
@@ -583,7 +583,7 @@ class RDoc::Context < RDoc::CodeObject
#
# See also RDoc::Context::Section
- def add_section title, comment = nil
+ def add_section(title, comment = nil)
if section = @sections[title] then
section.add_comment comment if comment
else
@@ -597,7 +597,7 @@ class RDoc::Context < RDoc::CodeObject
##
# Adds +thing+ to the collection +array+
- def add_to array, thing
+ def add_to(array, thing)
array << thing if @document_self
thing.parent = self
@@ -629,7 +629,7 @@ class RDoc::Context < RDoc::CodeObject
##
# Creates the full name for a child with +name+
- def child_name name
+ def child_name(name)
if name =~ /^:+/
$' #'
elsif RDoc::TopLevel === self then
@@ -688,13 +688,6 @@ class RDoc::Context < RDoc::CodeObject
section
end
- ##
- # Is part of this thing was defined in +file+?
-
- def defined_in?(file)
- @in_files.include?(file)
- end
-
def display(method_attr) # :nodoc:
if method_attr.is_a? RDoc::Attr
"#{method_attr.definition} #{method_attr.pretty_name}"
@@ -713,13 +706,6 @@ class RDoc::Context < RDoc::CodeObject
def each_ancestor(&_) # :nodoc:
end
- ##
- # Iterator for attributes
-
- def each_attribute # :yields: attribute
- @attributes.each { |a| yield a }
- end
-
##
# Iterator for classes and modules
@@ -727,27 +713,6 @@ class RDoc::Context < RDoc::CodeObject
classes_and_modules.sort.each(&block)
end
- ##
- # Iterator for constants
-
- def each_constant # :yields: constant
- @constants.each {|c| yield c}
- end
-
- ##
- # Iterator for included modules
-
- def each_include # :yields: include
- @includes.each do |i| yield i end
- end
-
- ##
- # Iterator for extension modules
-
- def each_extend # :yields: extend
- @extends.each do |e| yield e end
- end
-
##
# Iterator for methods
@@ -847,13 +812,6 @@ class RDoc::Context < RDoc::CodeObject
end
end
- ##
- # Finds a file with +name+ in this context
-
- def find_file_named name
- @store.find_file_named name
- end
-
##
# Finds an instance method with +name+ in this context
@@ -871,7 +829,7 @@ class RDoc::Context < RDoc::CodeObject
find_attribute_named(symbol) or
find_external_alias_named(symbol) or
find_module_named(symbol) or
- find_file_named(symbol)
+ @store.find_file_named(symbol)
end
##
@@ -973,10 +931,10 @@ class RDoc::Context < RDoc::CodeObject
##
# URL for this with a +prefix+
- def http_url(prefix)
+ def http_url
path = name_for_path
path = path.gsub(/<<\s*(\w*)/, 'from-\1') if path =~ /<
- path = [prefix] + path.split('::')
+ path = path.split('::')
File.join(*path.compact) + '.html'
end
@@ -1012,7 +970,7 @@ class RDoc::Context < RDoc::CodeObject
# If +section+ is provided only methods in that RDoc::Context::Section will
# be returned.
- def methods_by_type section = nil
+ def methods_by_type(section = nil)
methods = {}
TYPES.each do |type|
@@ -1104,7 +1062,7 @@ class RDoc::Context < RDoc::CodeObject
#--
# TODO mark the visibility of attributes in the template (if not public?)
- def remove_invisible min_visibility
+ def remove_invisible(min_visibility)
return if [:private, :nodoc].include? min_visibility
remove_invisible_in @method_list, min_visibility
remove_invisible_in @attributes, min_visibility
@@ -1114,7 +1072,7 @@ class RDoc::Context < RDoc::CodeObject
##
# Only called when min_visibility == :public or :private
- def remove_invisible_in array, min_visibility # :nodoc:
+ def remove_invisible_in(array, min_visibility) # :nodoc:
if min_visibility == :public then
array.reject! { |e|
e.visibility != :public and not e.force_documentation
@@ -1130,7 +1088,7 @@ class RDoc::Context < RDoc::CodeObject
# Tries to resolve unmatched aliases when a method or attribute has just
# been added.
- def resolve_aliases added
+ def resolve_aliases(added)
# resolve any pending unmatched aliases
key = added.pretty_name
unmatched_alias_list = @unmatched_alias_lists[key]
@@ -1181,7 +1139,7 @@ class RDoc::Context < RDoc::CodeObject
##
# Sets the current section to a section with +title+. See also #add_section
- def set_current_section title, comment
+ def set_current_section(title, comment)
@current_section = add_section title, comment
end
@@ -1246,7 +1204,7 @@ class RDoc::Context < RDoc::CodeObject
##
# Upgrades NormalModule +mod+ in +enclosing+ to a +class_type+
- def upgrade_to_class mod, class_type, enclosing
+ def upgrade_to_class(mod, class_type, enclosing)
enclosing.modules_hash.delete mod.name
klass = RDoc::ClassModule.from_module class_type, mod
diff --git a/lib/rdoc/code_object/context/section.rb b/lib/rdoc/code_object/context/section.rb
index aecd4e0213..ff4d5a60d8 100644
--- a/lib/rdoc/code_object/context/section.rb
+++ b/lib/rdoc/code_object/context/section.rb
@@ -1,5 +1,5 @@
# frozen_string_literal: true
-require 'cgi/util'
+require 'cgi/escape'
##
# A section of documentation like:
@@ -39,7 +39,7 @@ class RDoc::Context::Section
##
# Creates a new section with +title+ and +comment+
- def initialize parent, title, comment
+ def initialize(parent, title, comment)
@parent = parent
@title = title ? title.strip : title
@@ -51,7 +51,7 @@ class RDoc::Context::Section
##
# Sections are equal when they have the same #title
- def == other
+ def ==(other)
self.class === other and @title == other.title
end
@@ -60,20 +60,11 @@ class RDoc::Context::Section
##
# Adds +comment+ to this section
- def add_comment comment
- comment = extract_comment comment
-
- return if comment.empty?
-
- case comment
- when RDoc::Comment then
- @comments << comment
- when RDoc::Markup::Document then
- @comments.concat comment.parts
- when Array then
- @comments.concat comment
- else
- raise TypeError, "unknown comment type: #{comment.inspect}"
+ def add_comment(comment)
+ comments = Array(comment)
+ comments.each do |c|
+ extracted_comment = extract_comment(c)
+ @comments << extracted_comment unless extracted_comment.empty?
end
end
@@ -95,12 +86,8 @@ class RDoc::Context::Section
# # :section: The title
# # The body
- def extract_comment comment
+ def extract_comment(comment)
case comment
- when Array then
- comment.map do |c|
- extract_comment c
- end
when nil
RDoc::Comment.new ''
when RDoc::Comment then
@@ -115,8 +102,6 @@ class RDoc::Context::Section
end
end
- comment
- when RDoc::Markup::Document then
comment
else
raise TypeError, "unknown comment #{comment.inspect}"
@@ -135,20 +120,7 @@ class RDoc::Context::Section
# The files comments in this section come from
def in_files
- return [] if @comments.empty?
-
- case @comments
- when Array then
- @comments.map do |comment|
- comment.file
- end
- when RDoc::Markup::Document then
- @comment.parts.map do |document|
- document.file
- end
- else
- raise RDoc::Error, "BUG: unknown comment class #{@comments.class}"
- end
+ @comments.map(&:file)
end
##
@@ -166,11 +138,11 @@ class RDoc::Context::Section
##
# De-serializes this Section. The section parent must be restored manually.
- def marshal_load array
+ def marshal_load(array)
@parent = nil
@title = array[1]
- @comments = array[2]
+ @comments = array[2].parts.map { |doc| RDoc::Comment.from_document(doc) }
end
##
@@ -178,26 +150,7 @@ class RDoc::Context::Section
# multiple RDoc::Markup::Documents with their file set.
def parse
- case @comments
- when String then
- super
- when Array then
- docs = @comments.map do |comment, location|
- doc = super comment
- doc.file = location if location
- doc
- end
-
- RDoc::Markup::Document.new(*docs)
- when RDoc::Comment then
- doc = super @comments.text, comments.format
- doc.file = @comments.location
- doc
- when RDoc::Markup::Document then
- return @comments
- else
- raise ArgumentError, "unknown comment class #{comments.class}"
- end
+ RDoc::Markup::Document.new(*@comments.map(&:parse))
end
##
@@ -213,20 +166,9 @@ class RDoc::Context::Section
# Removes a comment from this section if it is from the same file as
# +comment+
- def remove_comment comment
- return if @comments.empty?
-
- case @comments
- when Array then
- @comments.delete_if do |my_comment|
- my_comment.file == comment.file
- end
- when RDoc::Markup::Document then
- @comments.parts.delete_if do |document|
- document.file == comment.file.name
- end
- else
- raise RDoc::Error, "BUG: unknown comment class #{@comments.class}"
+ def remove_comment(target_comment)
+ @comments.delete_if do |stored_comment|
+ stored_comment.file == target_comment.file
end
end
diff --git a/lib/rdoc/code_object/method_attr.rb b/lib/rdoc/code_object/method_attr.rb
index 263780f7c7..3dd60719d0 100644
--- a/lib/rdoc/code_object/method_attr.rb
+++ b/lib/rdoc/code_object/method_attr.rb
@@ -63,19 +63,13 @@ class RDoc::MethodAttr < RDoc::CodeObject
attr_reader :arglists
- ##
- # Pretty parameter list for this method
-
- attr_reader :param_seq
-
-
##
# Creates a new MethodAttr from token stream +text+ and method or attribute
# name +name+.
#
# Usually this is called by super from a subclass.
- def initialize text, name
+ def initialize(text, name, singleton: false)
super()
@text = text
@@ -84,21 +78,20 @@ class RDoc::MethodAttr < RDoc::CodeObject
@aliases = []
@is_alias_for = nil
@parent_name = nil
- @singleton = nil
+ @singleton = singleton
@visibility = :public
@see = false
@arglists = nil
@block_params = nil
@call_seq = nil
- @param_seq = nil
@params = nil
end
##
# Resets cached data for the object so it can be rebuilt by accessor methods
- def initialize_copy other # :nodoc:
+ def initialize_copy(other) # :nodoc:
@full_name = nil
end
@@ -118,7 +111,7 @@ class RDoc::MethodAttr < RDoc::CodeObject
[other.singleton ? 0 : 1, other.name_ord_range, other.name]
end
- def == other # :nodoc:
+ def ==(other) # :nodoc:
equal?(other) or self.class == other.class and full_name == other.full_name
end
@@ -157,7 +150,7 @@ class RDoc::MethodAttr < RDoc::CodeObject
##
# Sets the store for this class or module and its contained code objects.
- def store= store
+ def store=(store)
super
@file = @store.add_file @file.full_name if @file
@@ -175,7 +168,7 @@ class RDoc::MethodAttr < RDoc::CodeObject
return find_method_or_attribute name[0..-2]
end
- def find_method_or_attribute name # :nodoc:
+ def find_method_or_attribute(name) # :nodoc:
return nil unless parent.respond_to? :ancestors
searched = parent.ancestors
@@ -289,7 +282,7 @@ class RDoc::MethodAttr < RDoc::CodeObject
# HTML id-friendly method/attribute name
def html_name
- require 'cgi/util'
+ require 'cgi/escape'
CGI.escape(@name.gsub('-', '-2D')).gsub('%', '-').sub(/^-/, '')
end
@@ -320,19 +313,6 @@ class RDoc::MethodAttr < RDoc::CodeObject
@singleton ? '::' : '#'
end
- ##
- # Name for output to HTML. For class methods the full name with a "." is
- # used like +SomeClass.method_name+. For instance methods the class name is
- # used if +context+ does not match the parent.
- #
- # This is to help prevent people from using :: to call class methods.
-
- def output_name context
- return "#{name_prefix}#{@name}" if context == parent
-
- "#{parent_name}#{@singleton ? '.' : '#'}#{@name}"
- end
-
##
# Method/attribute name with class/instance indicator
@@ -361,7 +341,7 @@ class RDoc::MethodAttr < RDoc::CodeObject
@parent_name || super
end
- def pretty_print q # :nodoc:
+ def pretty_print(q) # :nodoc:
alias_for =
if @is_alias_for.respond_to? :name then
"alias for #{@is_alias_for.name}"
diff --git a/lib/rdoc/code_object/mixin.rb b/lib/rdoc/code_object/mixin.rb
index fa8faefc15..9b425efd2e 100644
--- a/lib/rdoc/code_object/mixin.rb
+++ b/lib/rdoc/code_object/mixin.rb
@@ -23,13 +23,13 @@ class RDoc::Mixin < RDoc::CodeObject
##
# Mixins are sorted by name
- def <=> other
+ def <=>(other)
return unless self.class === other
name <=> other.name
end
- def == other # :nodoc:
+ def ==(other) # :nodoc:
self.class === other and @name == other.name
end
@@ -107,7 +107,7 @@ class RDoc::Mixin < RDoc::CodeObject
##
# Sets the store for this class or module and its contained code objects.
- def store= store
+ def store=(store)
super
@file = @store.add_file @file.full_name if @file
diff --git a/lib/rdoc/code_object/normal_class.rb b/lib/rdoc/code_object/normal_class.rb
index aa340b5d15..6b68d6db56 100644
--- a/lib/rdoc/code_object/normal_class.rb
+++ b/lib/rdoc/code_object/normal_class.rb
@@ -53,7 +53,7 @@ class RDoc::NormalClass < RDoc::ClassModule
display
end
- def pretty_print q # :nodoc:
+ def pretty_print(q) # :nodoc:
superclass = @superclass ? " < #{@superclass}" : nil
q.group 2, "[class #{full_name}#{superclass}", "]" do
diff --git a/lib/rdoc/code_object/normal_module.rb b/lib/rdoc/code_object/normal_module.rb
index 498ec4dde2..677a9dc3bd 100644
--- a/lib/rdoc/code_object/normal_module.rb
+++ b/lib/rdoc/code_object/normal_module.rb
@@ -29,7 +29,7 @@ class RDoc::NormalModule < RDoc::ClassModule
true
end
- def pretty_print q # :nodoc:
+ def pretty_print(q) # :nodoc:
q.group 2, "[module #{full_name}:", "]" do
q.breakable
q.text "includes:"
diff --git a/lib/rdoc/code_object/require.rb b/lib/rdoc/code_object/require.rb
index 05e26b84b0..f47e3b1534 100644
--- a/lib/rdoc/code_object/require.rb
+++ b/lib/rdoc/code_object/require.rb
@@ -24,7 +24,7 @@ class RDoc::Require < RDoc::CodeObject
self.class,
object_id,
@name,
- parent_file_name,
+ @parent ? @parent.base_name : '(unknown)'
]
end
diff --git a/lib/rdoc/code_object/single_class.rb b/lib/rdoc/code_object/single_class.rb
index dd16529648..88a93a0c5f 100644
--- a/lib/rdoc/code_object/single_class.rb
+++ b/lib/rdoc/code_object/single_class.rb
@@ -22,7 +22,7 @@ class RDoc::SingleClass < RDoc::ClassModule
"class << #{full_name}"
end
- def pretty_print q # :nodoc:
+ def pretty_print(q) # :nodoc:
q.group 2, "[class << #{full_name}", "]" do
next
end
diff --git a/lib/rdoc/code_object/top_level.rb b/lib/rdoc/code_object/top_level.rb
index b93e3802fc..eeeff026a1 100644
--- a/lib/rdoc/code_object/top_level.rb
+++ b/lib/rdoc/code_object/top_level.rb
@@ -6,11 +6,6 @@ class RDoc::TopLevel < RDoc::Context
MARSHAL_VERSION = 0 # :nodoc:
- ##
- # This TopLevel's File::Stat struct
-
- attr_accessor :file_stat
-
##
# Relative name of this file
@@ -28,8 +23,6 @@ class RDoc::TopLevel < RDoc::Context
attr_reader :classes_or_modules
- attr_accessor :diagram # :nodoc:
-
##
# The parser class that processed this file
@@ -40,13 +33,11 @@ class RDoc::TopLevel < RDoc::Context
# is being generated outside the source dir +relative_name+ is relative to
# the source directory.
- def initialize absolute_name, relative_name = absolute_name
+ def initialize(absolute_name, relative_name = absolute_name)
super()
@name = nil
@absolute_name = absolute_name
@relative_name = relative_name
- @file_stat = File.stat(absolute_name) rescue nil # HACK for testing
- @diagram = nil
@parser = nil
@classes_or_modules = []
@@ -64,7 +55,7 @@ class RDoc::TopLevel < RDoc::Context
##
# An RDoc::TopLevel is equal to another with the same relative_name
- def == other
+ def ==(other)
self.class === other and @relative_name == other.relative_name
end
@@ -82,7 +73,7 @@ class RDoc::TopLevel < RDoc::Context
##
# Adds +constant+ to +Object+ instead of +self+.
- def add_constant constant
+ def add_constant(constant)
object_class.record_location self
return constant unless @document_self
object_class.add_constant constant
@@ -110,7 +101,7 @@ class RDoc::TopLevel < RDoc::Context
# Adds class or module +mod+. Used in the building phase
# by the Ruby parser.
- def add_to_classes_or_modules mod
+ def add_to_classes_or_modules(mod)
@classes_or_modules << mod
end
@@ -137,7 +128,7 @@ class RDoc::TopLevel < RDoc::Context
# TODO Why do we search through all classes/modules found, not just the
# ones of this instance?
- def find_class_or_module name
+ def find_class_or_module(name)
@store.find_class_or_module name
end
@@ -173,10 +164,8 @@ class RDoc::TopLevel < RDoc::Context
##
# URL for this with a +prefix+
- def http_url(prefix)
- path = [prefix, @relative_name.tr('.', '_')]
-
- File.join(*path.compact) + '.html'
+ def http_url
+ @relative_name.tr('.', '_') + '.html'
end
def inspect # :nodoc:
@@ -188,13 +177,6 @@ class RDoc::TopLevel < RDoc::Context
]
end
- ##
- # Time this file was last modified, if known
-
- def last_modified
- @file_stat ? file_stat.mtime : nil
- end
-
##
# Dumps this TopLevel for use by ri. See also #marshal_load
@@ -210,13 +192,11 @@ class RDoc::TopLevel < RDoc::Context
##
# Loads this TopLevel from +array+.
- def marshal_load array # :nodoc:
+ def marshal_load(array) # :nodoc:
initialize array[1]
@parser = array[2]
- @comment = array[3]
-
- @file_stat = nil
+ @comment = RDoc::Comment.from_document array[3]
end
##
@@ -246,10 +226,12 @@ class RDoc::TopLevel < RDoc::Context
# Path to this file for use with HTML generator output.
def path
- http_url @store.rdoc.generator.file_dir
+ prefix = options.file_path_prefix
+ return http_url unless prefix
+ File.join(prefix, http_url)
end
- def pretty_print q # :nodoc:
+ def pretty_print(q) # :nodoc:
q.group 2, "[#{self.class}: ", "]" do
q.text "base name: #{base_name.inspect}"
q.breakable
diff --git a/lib/rdoc/comment.rb b/lib/rdoc/comment.rb
index 04ec226436..b269ec4845 100644
--- a/lib/rdoc/comment.rb
+++ b/lib/rdoc/comment.rb
@@ -53,7 +53,7 @@ class RDoc::Comment
# Creates a new comment with +text+ that is found in the RDoc::TopLevel
# +location+.
- def initialize text = nil, location = nil, language = nil
+ def initialize(text = nil, location = nil, language = nil)
@location = location
@text = text.nil? ? nil : text.dup
@language = language
@@ -67,11 +67,11 @@ class RDoc::Comment
#--
# TODO deep copy @document
- def initialize_copy copy # :nodoc:
+ def initialize_copy(copy) # :nodoc:
@text = copy.text.dup
end
- def == other # :nodoc:
+ def ==(other) # :nodoc:
self.class === other and
other.text == @text and other.location == @location
end
@@ -92,7 +92,7 @@ class RDoc::Comment
# # ARGF.to_a(limit) -> array
# # ARGF.to_a(sep, limit) -> array
- def extract_call_seq method
+ def extract_call_seq
# we must handle situations like the above followed by an unindented first
# comment. The difficulty is to make sure not to match lines starting
# with ARGF at the same indent, but that are after the first description
@@ -116,23 +116,20 @@ class RDoc::Comment
@text.slice! all_start...all_stop
seq.gsub!(/^\s*/, '')
- method.call_seq = seq
end
-
- method
end
##
# A comment is empty if its text String is empty.
def empty?
- @text.empty?
+ @text.empty? && (@document.nil? || @document.empty?)
end
##
# HACK dubious
- def encode! encoding
+ def encode!(encoding)
@text = String.new @text, encoding: encoding
self
end
@@ -140,7 +137,7 @@ class RDoc::Comment
##
# Sets the format of this comment and resets any parsed document
- def format= format
+ def format=(format)
@format = format
@document = nil
end
@@ -211,7 +208,7 @@ class RDoc::Comment
#
# An error is raised if the comment contains a document but no text.
- def text= text
+ def text=(text)
raise RDoc::Error, 'replacing document-only comment is not allowed' if
@text.nil? and @document
@@ -226,4 +223,14 @@ class RDoc::Comment
@format == 'tomdoc'
end
+ ##
+ # Create a new parsed comment from a document
+
+ def self.from_document(document) # :nodoc:
+ comment = RDoc::Comment.new('')
+ comment.document = document
+ comment.location = RDoc::TopLevel.new(document.file) if document.file
+ comment
+ end
+
end
diff --git a/lib/rdoc/cross_reference.rb b/lib/rdoc/cross_reference.rb
index 4e011219e8..a942d33c96 100644
--- a/lib/rdoc/cross_reference.rb
+++ b/lib/rdoc/cross_reference.rb
@@ -124,7 +124,7 @@ class RDoc::CrossReference
# Allows cross-references to be created based on the given +context+
# (RDoc::Context).
- def initialize context
+ def initialize(context)
@context = context
@store = context.store
@@ -134,7 +134,7 @@ class RDoc::CrossReference
##
# Returns a method reference to +name+.
- def resolve_method name
+ def resolve_method(name)
ref = nil
if /#{CLASS_REGEXP_STR}([.#]|::)#{METHOD_REGEXP_STR}/o =~ name then
@@ -187,7 +187,7 @@ class RDoc::CrossReference
# returned. If +name+ is escaped +name+ is returned. If +name+ is not
# found +text+ is returned.
- def resolve name, text
+ def resolve(name, text)
return @seen[name] if @seen.include? name
ref = case name
diff --git a/lib/rdoc/encoding.rb b/lib/rdoc/encoding.rb
index 67e190f782..78dbe87d0c 100644
--- a/lib/rdoc/encoding.rb
+++ b/lib/rdoc/encoding.rb
@@ -29,7 +29,7 @@ module RDoc::Encoding
# If +force_transcode+ is true the document will be transcoded and any
# unknown character in the target encoding will be replaced with '?'
- def self.read_file filename, encoding, force_transcode = false
+ def self.read_file(filename, encoding, force_transcode = false)
content = File.open filename, "rb" do |f| f.read end
content.gsub!("\r\n", "\n") if RUBY_PLATFORM =~ /mswin|mingw/
@@ -89,7 +89,7 @@ module RDoc::Encoding
##
# Detects the encoding of +string+ based on the magic comment
- def self.detect_encoding string
+ def self.detect_encoding(string)
result = HEADER_REGEXP.match string
name = result && result[:name]
@@ -99,7 +99,7 @@ module RDoc::Encoding
##
# Removes magic comments and shebang
- def self.remove_magic_comment string
+ def self.remove_magic_comment(string)
string.sub HEADER_REGEXP do |s|
s.gsub(/[^\n]/, '')
end
@@ -109,7 +109,7 @@ module RDoc::Encoding
# Changes encoding based on +encoding+ without converting and returns new
# string
- def self.change_encoding text, encoding
+ def self.change_encoding(text, encoding)
if text.kind_of? RDoc::Comment
text.encode! encoding
else
diff --git a/lib/rdoc/erb_partial.rb b/lib/rdoc/erb_partial.rb
index 043d763db1..bad02ea706 100644
--- a/lib/rdoc/erb_partial.rb
+++ b/lib/rdoc/erb_partial.rb
@@ -9,7 +9,7 @@ class RDoc::ERBPartial < ERB
# Overrides +compiler+ startup to set the +eoutvar+ to an empty string only
# if it isn't already set.
- def set_eoutvar compiler, eoutvar = '_erbout'
+ def set_eoutvar(compiler, eoutvar = '_erbout')
super
compiler.pre_cmd = ["#{eoutvar} ||= +''"]
diff --git a/lib/rdoc/erbio.rb b/lib/rdoc/erbio.rb
index 0f98eaedee..e955eed811 100644
--- a/lib/rdoc/erbio.rb
+++ b/lib/rdoc/erbio.rb
@@ -20,14 +20,14 @@ class RDoc::ERBIO < ERB
##
# Defaults +eoutvar+ to 'io', otherwise is identical to ERB's initialize
- def initialize str, trim_mode: nil, eoutvar: 'io'
+ def initialize(str, trim_mode: nil, eoutvar: 'io')
super(str, trim_mode: trim_mode, eoutvar: eoutvar)
end
##
# Instructs +compiler+ how to write to +io_variable+
- def set_eoutvar compiler, io_variable
+ def set_eoutvar(compiler, io_variable)
compiler.put_cmd = "#{io_variable}.write"
compiler.insert_cmd = "#{io_variable}.write"
compiler.pre_cmd = []
diff --git a/lib/rdoc/generator/darkfish.rb b/lib/rdoc/generator/darkfish.rb
index 08f2b85e3b..7fec36500f 100644
--- a/lib/rdoc/generator/darkfish.rb
+++ b/lib/rdoc/generator/darkfish.rb
@@ -73,12 +73,6 @@ class RDoc::Generator::Darkfish
css/rdoc.css
]
- ##
- # Path to this file's parent directory. Used to find templates and other
- # resources.
-
- GENERATOR_DIR = File.join 'rdoc', 'generator'
-
##
# Release Version
@@ -156,7 +150,7 @@ class RDoc::Generator::Darkfish
##
# Initialize a few instance variables before we start
- def initialize store, options
+ def initialize(store, options)
@store = store
@options = options
@@ -184,22 +178,6 @@ class RDoc::Generator::Darkfish
$stderr.puts(*msg)
end
- ##
- # Directory where generated class HTML files live relative to the output
- # dir.
-
- def class_dir
- nil
- end
-
- ##
- # Directory where generated class HTML files live relative to the output
- # dir.
-
- def file_dir
- nil
- end
-
##
# Create the directories the generated docs will live in if they don't
# already exist.
@@ -291,7 +269,7 @@ class RDoc::Generator::Darkfish
# Return a list of the documented modules sorted by salience first, then
# by name.
- def get_sorted_module_list classes
+ def get_sorted_module_list(classes)
classes.select do |klass|
klass.display?
end.sort
@@ -301,8 +279,6 @@ class RDoc::Generator::Darkfish
# Generate an index page which lists all the classes which are documented.
def generate_index
- setup
-
template_file = @template_dir + 'index.rhtml'
return unless template_file.exist?
@@ -316,11 +292,14 @@ class RDoc::Generator::Darkfish
asset_rel_prefix = rel_prefix + @asset_rel_path
@title = @options.title
+ @main_page = @files.find { |f| f.full_name == @options.main_page }
render_template template_file, out_file do |io|
here = binding
# suppress 1.9.3 warning
here.local_variable_set(:asset_rel_prefix, asset_rel_prefix)
+ # some partials rely on the presence of current variable to render
+ here.local_variable_set(:current, @main_page) if @main_page
here
end
rescue => e
@@ -334,9 +313,7 @@ class RDoc::Generator::Darkfish
##
# Generates a class file for +klass+
- def generate_class klass, template_file = nil
- setup
-
+ def generate_class(klass, template_file = nil)
current = klass
template_file ||= @template_dir + 'class.rhtml'
@@ -348,7 +325,9 @@ class RDoc::Generator::Darkfish
search_index_rel_prefix += @asset_rel_path if @file_output
asset_rel_prefix = rel_prefix + @asset_rel_path
- svninfo = get_svninfo(current)
+
+ breadcrumb = # used in templates
+ breadcrumb = generate_nesting_namespaces_breadcrumb(current, rel_prefix)
@title = "#{klass.type} #{klass.full_name} - #{@options.title}"
@@ -357,7 +336,6 @@ class RDoc::Generator::Darkfish
here = binding
# suppress 1.9.3 warning
here.local_variable_set(:asset_rel_prefix, asset_rel_prefix)
- here.local_variable_set(:svninfo, svninfo)
here
end
end
@@ -366,8 +344,6 @@ class RDoc::Generator::Darkfish
# Generate a documentation file for each class and module
def generate_class_files
- setup
-
template_file = @template_dir + 'class.rhtml'
template_file = @template_dir + 'classpage.rhtml' unless
template_file.exist?
@@ -393,8 +369,6 @@ class RDoc::Generator::Darkfish
# Generate a documentation file for each file
def generate_file_files
- setup
-
page_file = @template_dir + 'page.rhtml'
fileinfo_file = @template_dir + 'fileinfo.rhtml'
@@ -461,9 +435,7 @@ class RDoc::Generator::Darkfish
##
# Generate a page file for +file+
- def generate_page file
- setup
-
+ def generate_page(file)
template_file = @template_dir + 'page.rhtml'
out_file = @outputdir + file.path
@@ -490,9 +462,7 @@ class RDoc::Generator::Darkfish
##
# Generates the 404 page for the RDoc servlet
- def generate_servlet_not_found message
- setup
-
+ def generate_servlet_not_found(message)
template_file = @template_dir + 'servlet_not_found.rhtml'
return unless template_file.exist?
@@ -523,9 +493,7 @@ class RDoc::Generator::Darkfish
##
# Generates the servlet root page for the RDoc servlet
- def generate_servlet_root installed
- setup
-
+ def generate_servlet_root(installed)
template_file = @template_dir + 'servlet_root.rhtml'
return unless template_file.exist?
@@ -551,8 +519,6 @@ class RDoc::Generator::Darkfish
# Generate an index page which lists all the classes which are documented.
def generate_table_of_contents
- setup
-
template_file = @template_dir + 'table_of_contents.rhtml'
return unless template_file.exist?
@@ -581,7 +547,7 @@ class RDoc::Generator::Darkfish
raise error
end
- def install_rdoc_static_file source, destination, options # :nodoc:
+ def install_rdoc_static_file(source, destination, options) # :nodoc:
return unless source.exist?
begin
@@ -614,65 +580,13 @@ class RDoc::Generator::Darkfish
@modsort = get_sorted_module_list @classes
end
- ##
- # Return a string describing the amount of time in the given number of
- # seconds in terms a human can understand easily.
-
- def time_delta_string seconds
- return 'less than a minute' if seconds < 60
- return "#{seconds / 60} minute#{seconds / 60 == 1 ? '' : 's'}" if
- seconds < 3000 # 50 minutes
- return 'about one hour' if seconds < 5400 # 90 minutes
- return "#{seconds / 3600} hours" if seconds < 64800 # 18 hours
- return 'one day' if seconds < 86400 # 1 day
- return 'about one day' if seconds < 172800 # 2 days
- return "#{seconds / 86400} days" if seconds < 604800 # 1 week
- return 'about one week' if seconds < 1209600 # 2 week
- return "#{seconds / 604800} weeks" if seconds < 7257600 # 3 months
- return "#{seconds / 2419200} months" if seconds < 31536000 # 1 year
- return "#{seconds / 31536000} years"
- end
-
- # %q$Id: darkfish.rb 52 2009-01-07 02:08:11Z deveiant $"
- SVNID_PATTERN = /
- \$Id:\s
- (\S+)\s # filename
- (\d+)\s # rev
- (\d{4}-\d{2}-\d{2})\s # Date (YYYY-MM-DD)
- (\d{2}:\d{2}:\d{2}Z)\s # Time (HH:MM:SSZ)
- (\w+)\s # committer
- \$$
- /x
-
- ##
- # Try to extract Subversion information out of the first constant whose
- # value looks like a subversion Id tag. If no matching constant is found,
- # and empty hash is returned.
-
- def get_svninfo klass
- constants = klass.constants or return {}
-
- constants.find { |c| c.value =~ SVNID_PATTERN } or return {}
-
- filename, rev, date, time, committer = $~.captures
- commitdate = Time.parse "#{date} #{time}"
-
- return {
- :filename => filename,
- :rev => Integer(rev),
- :commitdate => commitdate,
- :commitdelta => time_delta_string(Time.now - commitdate),
- :committer => committer,
- }
- end
-
##
# Creates a template from its components and the +body_file+.
#
# For backwards compatibility, if +body_file+ contains "
-
+
#{klass.name}
)
+ else
+ %(#{klass.name}
)
+ end
+ end
+
+ def generate_class_index_content(classes, rel_prefix)
+ grouped_classes = group_classes_by_namespace_for_sidebar(classes)
+ return '' unless top = grouped_classes[nil]
+
+ solo = top.one? { |klass| klass.display? }
+ traverse_classes(top, grouped_classes, rel_prefix, solo)
+ end
+
+ def traverse_classes(klasses, grouped_classes, rel_prefix, solo = false)
+ content = +'