From e2d849f48cb2ed3effe39a674ca79de7e8fb812b Mon Sep 17 00:00:00 2001 From: Jonathan Hefner Date: Mon, 24 Mar 2025 13:31:47 -0500 Subject: [PATCH 1/2] Fix URL paths for RDoc 6.13.0 ruby/rdoc@694987be2bc244ceb4686ee75a1272cc9e27313c removed support for `file_dir` and `class_dir`, which we used to prefix URL paths with `files/` or `classes/` (for example, in the URLs for https://api.rubyonrails.org/files/activerecord/lib/active_record/base_rb.html and https://api.rubyonrails.org/classes/ActiveRecord/Base.html). Note that RDoc < 6.13.0 _requires_ these methods when implementing a custom generator. Omitting them will cause RDoc to raise a `NoMethodError`. This commit monkey patches `RDoc::TopLevel` and `RDoc::ClassModule` to restore the behavior in way that is also compatible with RDoc < 6.13.0. --- lib/sdoc/generator.rb | 7 ++----- lib/sdoc/rdoc_monkey_patches.rb | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/lib/sdoc/generator.rb b/lib/sdoc/generator.rb index 861b760d..023d0667 100644 --- a/lib/sdoc/generator.rb +++ b/lib/sdoc/generator.rb @@ -25,9 +25,6 @@ class RDoc::Generator::SDoc DESCRIPTION = 'Searchable HTML documentation' - FILE_DIR = 'files' - CLASS_DIR = 'classes' - RESOURCES_DIR = File.join('resources', '.') attr_reader :options @@ -94,11 +91,11 @@ def generate end def class_dir - CLASS_DIR + nil end def file_dir - FILE_DIR + nil end ### Determines index page based on @options.main_page (or lack thereof) diff --git a/lib/sdoc/rdoc_monkey_patches.rb b/lib/sdoc/rdoc_monkey_patches.rb index c8ab7443..fac12978 100644 --- a/lib/sdoc/rdoc_monkey_patches.rb +++ b/lib/sdoc/rdoc_monkey_patches.rb @@ -1,5 +1,19 @@ require "rdoc" +RDoc::TopLevel.prepend(Module.new do + def path + File.join("files", super) + end +end) + + +RDoc::ClassModule.prepend(Module.new do + def path + File.join("classes", super) + end +end) + + RDoc::TopLevel.prepend(Module.new do attr_writer :path From df9e83eef33c4be52690eb07e164b70be778689b Mon Sep 17 00:00:00 2001 From: Jonathan Hefner Date: Mon, 24 Mar 2025 14:12:55 -0500 Subject: [PATCH 2/2] Fix `rdoc_top_level_for` for RDoc 6.13.0 ruby/rdoc@f517b028c6e5957fb546aa619559dca3abf05993 changed the signature of `RDoc::Store#initialize` from: ```ruby def initialize(path = nil, type = nil) ``` to: ```ruby def initialize(options, path: nil, type: nil) ``` which is a breaking change. This commit modifies `rdoc_top_level_for` to use the new signature. Because the issue only affects our testing code, this commit ignores compatibility with RDoc < 6.13.0. --- spec/spec_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index f5e25e00..ada0ca7b 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -28,7 +28,7 @@ def rdoc_top_level_for(ruby_code) # foolproof way to initialize it is by simply running it with a dummy file. $rdoc_for_specs ||= rdoc_dry_run("--files", __FILE__) - $rdoc_for_specs.store = RDoc::Store.new + $rdoc_for_specs.store = RDoc::Store.new(RDoc::Options.new) Dir.mktmpdir do |dir| path = "#{dir}/ruby_code.rb"