From fee9e2c7ab44f79c3b7a066b1f66bd1092835468 Mon Sep 17 00:00:00 2001 From: Petrik Date: Sat, 31 May 2025 11:50:33 +0200 Subject: [PATCH] Add version selector To make it easier to switch to documentation of other versions, add a select box to select other versions. For example, the versions can be defined in `.rdoc_options`: ```yaml version_roots: latest: https://docs.ruby-lang.org/en/ master: https://docs.ruby-lang.org/en/master/ 3.4: https://docs.ruby-lang.org/en/3.4/ ``` --- lib/rdoc/generator/markup.rb | 16 +++++++++ .../darkfish/_sidebar_navigation.rhtml | 8 +++++ .../template/darkfish/js/darkfish.js | 8 +++++ lib/rdoc/options.rb | 7 ++++ test/rdoc/rdoc_generator_darkfish_test.rb | 33 +++++++++++++++++++ test/rdoc/rdoc_options_test.rb | 1 + 6 files changed, 73 insertions(+) diff --git a/lib/rdoc/generator/markup.rb b/lib/rdoc/generator/markup.rb index 1c39687040..5bb97c6176 100644 --- a/lib/rdoc/generator/markup.rb +++ b/lib/rdoc/generator/markup.rb @@ -67,6 +67,22 @@ def canonical_url end end + ## + # URL's to other versions for this object. + + def version_urls + options = @store.options + if options.version_roots + options.version_roots.map do |version, root| + if path + url = File.join(root, path.to_s) + [version, url] + else + [version, root] + end + end + end + end end class RDoc::CodeObject diff --git a/lib/rdoc/generator/template/darkfish/_sidebar_navigation.rhtml b/lib/rdoc/generator/template/darkfish/_sidebar_navigation.rhtml index d7f330840a..5964835bea 100644 --- a/lib/rdoc/generator/template/darkfish/_sidebar_navigation.rhtml +++ b/lib/rdoc/generator/template/darkfish/_sidebar_navigation.rhtml @@ -1,6 +1,14 @@