summaryrefslogtreecommitdiff
path: root/lib/rdoc
diff options
context:
space:
mode:
Diffstat (limited to 'lib/rdoc')
-rw-r--r--lib/rdoc/code_object.rb6
-rw-r--r--lib/rdoc/code_object/class_module.rb40
-rw-r--r--lib/rdoc/generator/template/darkfish/class.rhtml18
-rw-r--r--lib/rdoc/generator/template/darkfish/css/rdoc.css7
-rw-r--r--lib/rdoc/options.rb19
5 files changed, 88 insertions, 2 deletions
diff --git a/lib/rdoc/code_object.rb b/lib/rdoc/code_object.rb
index aeb4b4762e..83997c2580 100644
--- a/lib/rdoc/code_object.rb
+++ b/lib/rdoc/code_object.rb
@@ -97,6 +97,11 @@ class RDoc::CodeObject
attr_accessor :viewer
##
+ # When mixed-in to a class, this points to the Context in which it was originally defined.
+
+ attr_accessor :mixin_from
+
+ ##
# Creates a new CodeObject that will document itself and its children
def initialize
@@ -111,6 +116,7 @@ class RDoc::CodeObject
@full_name = nil
@store = nil
@track_visibility = true
+ @mixin_from = nil
initialize_visibility
end
diff --git a/lib/rdoc/code_object/class_module.rb b/lib/rdoc/code_object/class_module.rb
index c69e14b5e4..a99acb8956 100644
--- a/lib/rdoc/code_object/class_module.rb
+++ b/lib/rdoc/code_object/class_module.rb
@@ -223,6 +223,7 @@ class RDoc::ClassModule < RDoc::Context
def complete min_visibility
update_aliases
remove_nodoc_children
+ embed_mixins
update_includes
remove_invisible min_visibility
end
@@ -798,4 +799,43 @@ class RDoc::ClassModule < RDoc::Context
extends.uniq!
end
+ def embed_mixins
+ return unless options.embed_mixins
+
+ includes.each do |include|
+ next if String === include.module
+ include.module.method_list.each do |code_object|
+ add_method(prepare_to_embed(code_object))
+ end
+ include.module.constants.each do |code_object|
+ add_constant(prepare_to_embed(code_object))
+ end
+ include.module.attributes.each do |code_object|
+ add_attribute(prepare_to_embed(code_object))
+ end
+ end
+
+ extends.each do |ext|
+ next if String === ext.module
+ ext.module.method_list.each do |code_object|
+ add_method(prepare_to_embed(code_object, true))
+ end
+ ext.module.attributes.each do |code_object|
+ add_attribute(prepare_to_embed(code_object, true))
+ end
+ end
+ end
+
+ private
+
+ def prepare_to_embed(code_object, singleton=false)
+ code_object = code_object.dup
+ code_object.mixin_from = code_object.parent
+ code_object.singleton = true if singleton
+ set_current_section(code_object.section.title, code_object.section.comment)
+ # add_method and add_attribute will reassign self's visibility back to the method/attribute
+ # so we need to sync self's visibility with the object's to properly retain that information
+ self.visibility = code_object.visibility
+ code_object
+ end
end
diff --git a/lib/rdoc/generator/template/darkfish/class.rhtml b/lib/rdoc/generator/template/darkfish/class.rhtml
index 85fb0c1c33..0bec9fc9ce 100644
--- a/lib/rdoc/generator/template/darkfish/class.rhtml
+++ b/lib/rdoc/generator/template/darkfish/class.rhtml
@@ -54,7 +54,13 @@
<%- constants.each do |const| -%>
<dt id="<%= const.name %>"><%= const.name %>
<%- if const.comment then -%>
- <dd><%= const.description.strip %>
+ <dd>
+ <%- if const.mixin_from then -%>
+ <div class="mixin-from">
+ Included from <a href="<%= klass.aref_to(const.mixin_from.path)%>"><%= const.mixin_from.full_name %></a>
+ </div>
+ <%- end -%>
+ <%= const.description.strip %>
<%- else -%>
<dd class="missing-docs">(Not documented)
<%- end -%>
@@ -79,6 +85,11 @@
</div>
<div class="method-description">
+ <%- if attrib.mixin_from then -%>
+ <div class="mixin-from">
+ <%= attrib.singleton ? "Extended" : "Included" %> from <a href="<%= klass.aref_to(attrib.mixin_from.path)%>"><%= attrib.mixin_from.full_name %></a>
+ </div>
+ <%- end -%>
<%- if attrib.comment then -%>
<%= attrib.description.strip %>
<%- else -%>
@@ -145,6 +156,11 @@
<pre><%= method.markup_code %></pre>
</div>
<%- end -%>
+ <%- if method.mixin_from then -%>
+ <div class="mixin-from">
+ <%= method.singleton ? "Extended" : "Included" %> from <a href="<%= klass.aref_to(method.mixin_from.path)%>"><%= method.mixin_from.full_name %></a>
+ </div>
+ <%- end -%>
<%- if method.comment then -%>
<%= method.description.strip %>
<%- else -%>
diff --git a/lib/rdoc/generator/template/darkfish/css/rdoc.css b/lib/rdoc/generator/template/darkfish/css/rdoc.css
index 49138c6292..a4e1ef188c 100644
--- a/lib/rdoc/generator/template/darkfish/css/rdoc.css
+++ b/lib/rdoc/generator/template/darkfish/css/rdoc.css
@@ -670,6 +670,13 @@ main .aliases {
font-style: italic;
cursor: default;
}
+
+main .mixin-from {
+ font-size: 80%;
+ font-style: italic;
+ margin-bottom: 0.75em;
+}
+
main .method-description ul {
margin-left: 1.5em;
}
diff --git a/lib/rdoc/options.rb b/lib/rdoc/options.rb
index 2631d57364..a607a76d56 100644
--- a/lib/rdoc/options.rb
+++ b/lib/rdoc/options.rb
@@ -344,6 +344,11 @@ class RDoc::Options
# Indicates if files of test suites should be skipped
attr_accessor :skip_tests
+ ##
+ # Embed mixin methods, attributes, and constants into class documentation. Set via
+ # +--[no-]embed-mixins+ (Default is +false+.)
+ attr_accessor :embed_mixins
+
def initialize loaded_options = nil # :nodoc:
init_ivars
override loaded_options if loaded_options
@@ -351,6 +356,7 @@ class RDoc::Options
def init_ivars # :nodoc:
@dry_run = false
+ @embed_mixins = false
@exclude = %w[
~\z \.orig\z \.rej\z \.bak\z
\.gemspec\z
@@ -401,6 +407,7 @@ class RDoc::Options
@encoding = encoding ? Encoding.find(encoding) : encoding
@charset = map['charset']
+ @embed_mixins = map['embed_mixins']
@exclude = map['exclude']
@generator_name = map['generator_name']
@hyperlink_all = map['hyperlink_all']
@@ -432,6 +439,7 @@ class RDoc::Options
end
@charset = map['charset'] if map.has_key?('charset')
+ @embed_mixins = map['embed_mixins'] if map.has_key?('embed_mixins')
@exclude = map['exclude'] if map.has_key?('exclude')
@generator_name = map['generator_name'] if map.has_key?('generator_name')
@hyperlink_all = map['hyperlink_all'] if map.has_key?('hyperlink_all')
@@ -460,11 +468,12 @@ class RDoc::Options
def == other # :nodoc:
self.class === other and
@encoding == other.encoding and
+ @embed_mixins == other.embed_mixins and
@generator_name == other.generator_name and
@hyperlink_all == other.hyperlink_all and
@line_numbers == other.line_numbers and
@locale == other.locale and
- @locale_dir == other.locale_dir and
+ @locale_dir == other.locale_dir and
@main_page == other.main_page and
@markup == other.markup and
@op_dir == other.op_dir and
@@ -842,6 +851,14 @@ Usage: #{opt.program_name} [options] [names...]
opt.separator nil
+ opt.on("--[no-]embed-mixins",
+ "Embed mixin methods, attributes, and constants",
+ "into class documentation. (default false)") do |value|
+ @embed_mixins = value
+ end
+
+ opt.separator nil
+
markup_formats = RDoc::Text::MARKUP_FORMAT.keys.sort
opt.on("--markup=MARKUP", markup_formats,