2010-04-01 03:45:16 -04:00
|
|
|
require 'rdoc'
|
|
|
|
require 'rdoc/text'
|
|
|
|
|
|
|
|
##
|
|
|
|
# Base class for the RDoc code tree.
|
|
|
|
#
|
|
|
|
# We contain the common stuff for contexts (which are containers) and other
|
|
|
|
# elements (methods, attributes and so on)
|
2010-04-19 01:08:28 -04:00
|
|
|
#
|
|
|
|
# Here's the tree of the CodeObject subclasses:
|
|
|
|
#
|
|
|
|
# * RDoc::Context
|
|
|
|
# * RDoc::TopLevel
|
|
|
|
# * RDoc::ClassModule
|
2010-12-19 22:22:49 -05:00
|
|
|
# * RDoc::AnonClass (never used so far)
|
2010-04-19 01:08:28 -04:00
|
|
|
# * RDoc::NormalClass
|
|
|
|
# * RDoc::NormalModule
|
|
|
|
# * RDoc::SingleClass
|
2010-12-19 22:22:49 -05:00
|
|
|
# * RDoc::MethodAttr
|
|
|
|
# * RDoc::Attr
|
|
|
|
# * RDoc::AnyMethod
|
|
|
|
# * RDoc::GhostMethod
|
|
|
|
# * RDoc::MetaMethod
|
2010-04-19 01:08:28 -04:00
|
|
|
# * RDoc::Alias
|
|
|
|
# * RDoc::Constant
|
|
|
|
# * RDoc::Require
|
|
|
|
# * RDoc::Include
|
2010-04-01 03:45:16 -04:00
|
|
|
|
|
|
|
class RDoc::CodeObject
|
|
|
|
|
|
|
|
include RDoc::Text
|
|
|
|
|
|
|
|
##
|
|
|
|
# Our comment
|
|
|
|
|
|
|
|
attr_reader :comment
|
|
|
|
|
|
|
|
##
|
|
|
|
# Do we document our children?
|
|
|
|
|
|
|
|
attr_reader :document_children
|
|
|
|
|
|
|
|
##
|
|
|
|
# Do we document ourselves?
|
|
|
|
|
|
|
|
attr_reader :document_self
|
|
|
|
|
|
|
|
##
|
|
|
|
# Are we done documenting (ie, did we come across a :enddoc:)?
|
|
|
|
|
2010-12-19 22:22:49 -05:00
|
|
|
attr_reader :done_documenting
|
|
|
|
|
|
|
|
##
|
|
|
|
# Which file this code object was defined in
|
|
|
|
|
|
|
|
attr_reader :file
|
2010-04-01 03:45:16 -04:00
|
|
|
|
|
|
|
##
|
|
|
|
# Force documentation of this CodeObject
|
|
|
|
|
2010-12-19 22:22:49 -05:00
|
|
|
attr_reader :force_documentation
|
2010-04-01 03:45:16 -04:00
|
|
|
|
2010-04-22 22:32:20 -04:00
|
|
|
##
|
|
|
|
# Hash of arbitrary metadata for this CodeObject
|
|
|
|
|
|
|
|
attr_reader :metadata
|
|
|
|
|
2010-04-01 03:45:16 -04:00
|
|
|
##
|
|
|
|
# Our parent CodeObject
|
|
|
|
|
|
|
|
attr_accessor :parent
|
|
|
|
|
2010-12-19 22:22:49 -05:00
|
|
|
##
|
|
|
|
# Did we ever receive a +:nodoc:+ directive?
|
|
|
|
|
|
|
|
attr_reader :received_nodoc
|
|
|
|
|
2010-04-01 03:45:16 -04:00
|
|
|
##
|
|
|
|
# Which section are we in
|
|
|
|
|
|
|
|
attr_accessor :section
|
|
|
|
|
|
|
|
##
|
|
|
|
# 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
|
|
|
|
|
|
|
|
##
|
|
|
|
# Creates a new CodeObject that will document itself and its children
|
|
|
|
|
|
|
|
def initialize
|
2010-12-19 22:22:49 -05:00
|
|
|
@metadata = {}
|
|
|
|
@comment = ''
|
|
|
|
@parent = nil
|
|
|
|
@file = nil
|
|
|
|
@full_name = nil
|
2010-04-01 03:45:16 -04:00
|
|
|
|
|
|
|
@document_children = true
|
|
|
|
@document_self = true
|
|
|
|
@done_documenting = false
|
|
|
|
@force_documentation = false
|
2010-12-19 22:22:49 -05:00
|
|
|
@received_nodoc = false
|
2010-04-01 03:45:16 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
##
|
|
|
|
# Replaces our comment with +comment+, unless it is empty.
|
|
|
|
|
|
|
|
def comment=(comment)
|
|
|
|
@comment = case comment
|
|
|
|
when NilClass then ''
|
|
|
|
when RDoc::Markup::Document then comment
|
|
|
|
else
|
|
|
|
if comment and not comment.empty? then
|
|
|
|
normalize_comment comment
|
|
|
|
else
|
|
|
|
@comment
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
##
|
2010-12-19 22:22:49 -05:00
|
|
|
# Enables or disables documentation of this CodeObject's children unless it
|
|
|
|
# has been turned off by :enddoc:
|
2010-04-01 03:45:16 -04:00
|
|
|
|
|
|
|
def document_children=(document_children)
|
2010-12-19 22:22:49 -05:00
|
|
|
@document_children = document_children unless @done_documenting
|
2010-04-01 03:45:16 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
##
|
2010-12-19 22:22:49 -05:00
|
|
|
# Enables or disables documentation of this CodeObject unless it has been
|
|
|
|
# turned off by :enddoc:. If the argument is +nil+ it means the
|
|
|
|
# documentation is turned off by +:nodoc:+.
|
2010-04-01 03:45:16 -04:00
|
|
|
|
|
|
|
def document_self=(document_self)
|
2010-12-19 22:22:49 -05:00
|
|
|
return if @done_documenting
|
|
|
|
|
2010-04-01 03:45:16 -04:00
|
|
|
@document_self = document_self
|
2010-12-19 22:22:49 -05:00
|
|
|
@received_nodoc = true if document_self.nil?
|
2010-04-01 03:45:16 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
##
|
2010-12-19 22:22:49 -05:00
|
|
|
# Does this object have a comment with content or is #received_nodoc true?
|
2010-04-01 03:45:16 -04:00
|
|
|
|
|
|
|
def documented?
|
2010-12-19 22:22:49 -05:00
|
|
|
@received_nodoc or !@comment.empty?
|
|
|
|
end
|
|
|
|
|
|
|
|
##
|
|
|
|
# Turns documentation on/off, and turns on/off #document_self
|
|
|
|
# and #document_children.
|
|
|
|
#
|
|
|
|
# Once documentation has been turned off (by +:enddoc:+),
|
|
|
|
# the object will refuse to turn #document_self or
|
|
|
|
# #document_children on, so +:doc:+ and +:start_doc:+ directives
|
|
|
|
# will have no effect in the current file.
|
|
|
|
|
|
|
|
def done_documenting=(value)
|
|
|
|
@done_documenting = value
|
|
|
|
@document_self = !value
|
|
|
|
@document_children = @document_self
|
|
|
|
end
|
|
|
|
|
|
|
|
##
|
|
|
|
# Force the documentation of this object unless documentation
|
|
|
|
# has been turned off by :endoc:
|
|
|
|
#--
|
|
|
|
# HACK untested, was assigning to an ivar
|
|
|
|
|
|
|
|
def force_documentation=(value)
|
|
|
|
@force_documentation = value unless @done_documenting
|
|
|
|
end
|
|
|
|
|
|
|
|
##
|
|
|
|
# Sets the full_name overriding any computed full name.
|
|
|
|
#
|
|
|
|
# Set to +nil+ to clear RDoc's cached value
|
|
|
|
|
|
|
|
def full_name= full_name
|
|
|
|
@full_name = full_name
|
2010-04-01 03:45:16 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
##
|
|
|
|
# File name of our parent
|
|
|
|
|
|
|
|
def parent_file_name
|
|
|
|
@parent ? @parent.base_name : '(unknown)'
|
|
|
|
end
|
|
|
|
|
|
|
|
##
|
|
|
|
# Name of our parent
|
|
|
|
|
|
|
|
def parent_name
|
|
|
|
@parent ? @parent.full_name : '(unknown)'
|
|
|
|
end
|
|
|
|
|
|
|
|
##
|
2010-12-19 22:22:49 -05:00
|
|
|
# Records the RDoc::TopLevel (file) where this code object was defined
|
2010-04-01 03:45:16 -04:00
|
|
|
|
2010-12-19 22:22:49 -05:00
|
|
|
def record_location top_level
|
|
|
|
@file = top_level
|
2010-04-01 03:45:16 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
##
|
2010-12-19 22:22:49 -05:00
|
|
|
# Enable capture of documentation unless documentation has been
|
|
|
|
# turned off by :endoc:
|
2010-04-01 03:45:16 -04:00
|
|
|
|
|
|
|
def start_doc
|
2010-12-19 22:22:49 -05:00
|
|
|
return if @done_documenting
|
|
|
|
|
2010-04-01 03:45:16 -04:00
|
|
|
@document_self = true
|
|
|
|
@document_children = true
|
|
|
|
end
|
|
|
|
|
|
|
|
##
|
|
|
|
# Disable capture of documentation
|
|
|
|
|
|
|
|
def stop_doc
|
|
|
|
@document_self = false
|
|
|
|
@document_children = false
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|