From 5617fb7dc933a0aa77fe62b2a15420d1b46d7e50 Mon Sep 17 00:00:00 2001 From: Jonathan Hefner Date: Tue, 2 Jan 2024 11:55:51 -0600 Subject: [PATCH] Support permalinking constants This adds a permalink next to each constant's name, similar to methods. This also adds a "Constants" navigation section in the sidebar, similar to the "Methods" navigation section. The permalinks are implemented by monkeypatching `RDoc::Constant` to provide an `aref` method, just as `RDoc::ClassModule` and `RDoc::MethodAttr` already do. --- CHANGELOG.md | 1 + .../generator/template/rails/_context.rhtml | 10 ++- .../template/rails/_module_nav.rhtml | 9 +++ .../template/rails/resources/css/main.css | 73 +++++++++++-------- lib/sdoc/rdoc_monkey_patches.rb | 15 ++++ spec/rdoc_monkey_patches_spec.rb | 22 ++++++ 6 files changed, 96 insertions(+), 34 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a6a457f1..242f3538 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -37,6 +37,7 @@ Main (3.0.0.alpha) * [#323](https://github.com/rails/sdoc/pull/323) Update favicon [@jonathanhefner](https://github.com/jonathanhefner) * [#345](https://github.com/rails/sdoc/pull/345) Version explicit links to `api.rubyonrails.org` [@jonathanhefner](https://github.com/jonathanhefner) * [#356](https://github.com/rails/sdoc/pull/356) Redesign "Constants" section [@jonathanhefner](https://github.com/jonathanhefner) +* [#357](https://github.com/rails/sdoc/pull/357) Support permalinking constants [@jonathanhefner](https://github.com/jonathanhefner) 2.6.1 ===== diff --git a/lib/rdoc/generator/template/rails/_context.rhtml b/lib/rdoc/generator/template/rails/_context.rhtml index b0412dd2..cc0dc73c 100644 --- a/lib/rdoc/generator/template/rails/_context.rhtml +++ b/lib/rdoc/generator/template/rails/_context.rhtml @@ -58,9 +58,11 @@ <% unless constants.empty? %>

Constants

<% constants.each do |constant| %> -
-
+
+ <%= description_for constant %>
@@ -97,10 +99,10 @@

<%= visibility.to_s.capitalize %> <%= type %> methods

<% methods.each do |method| %>
-
+ <% unless method.aliases.empty? %> diff --git a/lib/rdoc/generator/template/rails/_module_nav.rhtml b/lib/rdoc/generator/template/rails/_module_nav.rhtml index df6b063d..dc4aee9d 100644 --- a/lib/rdoc/generator/template/rails/_module_nav.rhtml +++ b/lib/rdoc/generator/template/rails/_module_nav.rhtml @@ -10,6 +10,15 @@
<% end %> +<% unless (constants = @context.constants).empty? %> + + +<% end %> + <% unless (methods = module_methods(@context)).empty? %>