From 5be10c793650f98b69a13aa3d291b5e9b9fda3ea Mon Sep 17 00:00:00 2001 From: Robin Dupret Date: Tue, 31 Jan 2017 22:04:56 +0100 Subject: Properly nest core classes under a "Core Extensions" label Since Active Support is monkey patching a lot of core classes, let's rather document these changes under a new section so they are still documented but not encumbering the sidebar. We can safely remove the rescuing of the `LoadError` since as of cd7cc525, it's not possible to generate the API from an application. [ci skip] [Kasper Timm Hansen & Robin Dupret] --- railties/lib/rails/api/generator.rb | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 railties/lib/rails/api/generator.rb (limited to 'railties/lib/rails/api/generator.rb') diff --git a/railties/lib/rails/api/generator.rb b/railties/lib/rails/api/generator.rb new file mode 100644 index 0000000000..dcc491783c --- /dev/null +++ b/railties/lib/rails/api/generator.rb @@ -0,0 +1,28 @@ +require "sdoc" + +class RDoc::Generator::API < RDoc::Generator::SDoc # :nodoc: + RDoc::RDoc.add_generator self + + def generate_class_tree_level(classes, visited = {}) + # Only process core extensions on the first visit. + if visited.empty? + core_exts, classes = classes.partition { |klass| core_extension?(klass) } + + super.unshift([ "Core extensions", "", "", build_core_ext_subtree(core_exts, visited) ]) + else + super + end + end + + private + def build_core_ext_subtree(classes, visited) + classes.map do |klass| + [ klass.name, klass.document_self_or_methods ? klass.path : "", "", + generate_class_tree_level(klass.classes_and_modules, visited) ] + end + end + + def core_extension?(klass) + klass.name != "ActiveSupport" && klass.in_files.any? { |file| file.absolute_name.include?("core_ext") } + end +end -- cgit v1.2.3