From 0daa0ba1966919080153aeb333662f8b156d99b4 Mon Sep 17 00:00:00 2001 From: Jonathan Hefner Date: Tue, 25 Mar 2025 10:54:41 -0500 Subject: [PATCH 1/2] Use `{class_module,file}_path_prefix` RDoc options Follow-up to #375. RDoc 6.13.1 has been released, and includes support for the `class_module_path_prefix` and `file_path_prefix` options (added in ruby/rdoc@3bc179ddfb74b46c52f697b9d1ce331264fcd84c), which serve as replacements for the `class_dir` and `file_dir` methods. This commit removes the RDoc monkey patch added in e2d849f48cb2ed3effe39a674ca79de7e8fb812b in favor of using those options. This means SDoc will be incompatible with RDoc 6.13.0 specifically, but that shouldn't be a significant issue (and compatibility with RDoc < 6.13.0 is preserved). --- lib/sdoc/generator.rb | 17 +++++++++++++++-- lib/sdoc/rdoc_monkey_patches.rb | 14 -------------- spec/spec_helper.rb | 2 +- 3 files changed, 16 insertions(+), 17 deletions(-) diff --git a/lib/sdoc/generator.rb b/lib/sdoc/generator.rb index 023d0667..b49a876a 100644 --- a/lib/sdoc/generator.rb +++ b/lib/sdoc/generator.rb @@ -25,6 +25,9 @@ class RDoc::Generator::SDoc DESCRIPTION = 'Searchable HTML documentation' + FILE_DIR = "files" + CLASS_DIR = "classes" + RESOURCES_DIR = File.join('resources', '.') attr_reader :options @@ -63,6 +66,14 @@ def self.setup_options(options) ENV["HORO_BADGE_VERSION"] || ENV["HORO_PROJECT_VERSION"], "API documentation" ].compact.join(" ") + + if options.respond_to?(:class_module_path_prefix) + options.class_module_path_prefix = CLASS_DIR + end + + if options.respond_to?(:file_path_prefix) + options.file_path_prefix = FILE_DIR + end end def initialize(store, options) @@ -90,12 +101,14 @@ def generate generate_class_files end + # For compatibility with RDoc < 6.13.0 def class_dir - nil + CLASS_DIR end + # For compatibility with RDoc < 6.13.0 def file_dir - nil + FILE_DIR 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 fac12978..c8ab7443 100644 --- a/lib/sdoc/rdoc_monkey_patches.rb +++ b/lib/sdoc/rdoc_monkey_patches.rb @@ -1,19 +1,5 @@ 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 diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index ada0ca7b..9ce56e99 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::Options.new) + $rdoc_for_specs.store = RDoc::Store.new($rdoc_for_specs.options) Dir.mktmpdir do |dir| path = "#{dir}/ruby_code.rb" From c1a079768ce70404a049a8b534557b38f7d8f5a3 Mon Sep 17 00:00:00 2001 From: Jonathan Hefner Date: Sun, 30 Mar 2025 12:53:26 -0500 Subject: [PATCH 2/2] Allow "Z" suffix in `og_modified_time` smoke test On machines configured to be in UTC (such as CI servers), git may format timestamps with a "Z" suffix rather than "+HH:MM". --- spec/helpers_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/helpers_spec.rb b/spec/helpers_spec.rb index 2d51b9ab..f80a5678 100644 --- a/spec/helpers_spec.rb +++ b/spec/helpers_spec.rb @@ -453,7 +453,7 @@ module Foo; module Bar; module Qux; end; end; end it "returns the commit time of the most recent commit in HEAD (smoke test)" do _(@helpers.og_modified_time). - must_match %r"\A\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}[-+]\d{2}:\d{2}\z" + must_match %r"\A\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:Z|[-+]\d{2}:\d{2})\z" end it "returns nil when git is not installed or project is not a git repository" do