Skip to content

Commit c4d920b

Browse files
Redesign "Appears in" file list
The "Appears in" file list is collapsed by default to avoid overwhelming the user with very long file lists. For example, the `Rails` module appears in 125 files. However the vast majority of modules appear in only in their own file. And, out of all 1370 modules, only ~50 appear in 10 or more files: ```console $ grep -c '[.]rb</a>' doc/public/classes/**/*.html | head doc/rdoc/classes/AbstractController/ActionNotFound.html:1 doc/rdoc/classes/AbstractController/Base.html:1 doc/rdoc/classes/AbstractController/Caching/ClassMethods.html:1 doc/rdoc/classes/AbstractController/Caching/ConfigMethods.html:1 doc/rdoc/classes/AbstractController/Caching/Fragments/ClassMethods.html:1 doc/rdoc/classes/AbstractController/Caching/Fragments.html:1 doc/rdoc/classes/AbstractController/Caching.html:2 doc/rdoc/classes/AbstractController/Callbacks/ClassMethods.html:1 doc/rdoc/classes/AbstractController/Callbacks.html:1 doc/rdoc/classes/AbstractController/Collector.html:1 $ grep -c '[.]rb</a>' doc/public/classes/**/*.html | grep ':1$' | wc -l 1181 $ grep -c '[.]rb</a>' doc/public/classes/**/*.html | grep ':[1-5]$' | wc -l 1293 $ grep -c '[.]rb</a>' doc/public/classes/**/*.html | grep ':[1-9]$' | wc -l 1321 $ grep -c '[.]rb</a>' doc/public/classes/**/*.html | wc -l 1370 ``` This commit redesigns the "Appears in" file list to show a small number of files by default. If a module appears in 9 or fewer files, then all the files will be shown by default. Otherwise, the first 5 files will shown, and a "More" button is shown to reveal the remaining files.
1 parent 9eee87e commit c4d920b

File tree

4 files changed

+100
-42
lines changed

4 files changed

+100
-42
lines changed

lib/rdoc/generator/template/rails/class.rhtml

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -39,19 +39,9 @@
3939

4040
<main id="bodyContent">
4141
<%= include_template '_context.rhtml', {:context => klass} %>
42-
</main>
4342

44-
<footer>
45-
<div id="footerContent">
46-
<details>
47-
<summary class="sectiontitle">Appears in</summary>
48-
<ul class="files">
49-
<% klass.in_files.each do |file| %>
50-
<li><%= link_to file %></li>
51-
<% end %>
52-
</ul>
53-
</details>
54-
</div>
55-
</footer>
43+
<div class="sectiontitle">Definition files</div>
44+
<%= more_less_ul klass.in_files.map { |file| link_to file }, 5..9 %>
45+
</main>
5646
</body>
5747
</html>

lib/rdoc/generator/template/rails/resources/css/main.css

Lines changed: 44 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,19 @@ body {
1717
}
1818

1919
body {
20-
grid-template-rows: min-content min-content min-content;
20+
grid-template-rows: min-content min-content;
2121
grid-template-columns: 100%;
2222
}
2323

2424
@media (min-width: 600px) {
2525
body {
26-
grid-template-rows: min-content min-content min-content;
26+
grid-template-rows: min-content min-content;
2727
grid-template-columns: 300px auto;
2828
}
2929

3030
nav {
3131
grid-row-start: 1;
32-
grid-row-end: 3;
32+
grid-row-end: 2;
3333
grid-column-start: 1;
3434
grid-column-end: 1;
3535
}
@@ -48,18 +48,6 @@ body {
4848
grid-column-end: 2;
4949
min-width: 0;
5050
}
51-
52-
footer {
53-
grid-row-start: 3;
54-
grid-row-end: 3;
55-
grid-column-start: 2;
56-
grid-column-end: 2;
57-
}
58-
}
59-
60-
#footerContent {
61-
margin: 2em 3.5em;
62-
max-width: 980px;
6351
}
6452

6553
a:link, a:active, a:visited, a:hover {
@@ -232,12 +220,12 @@ pre
232220
display: inline;
233221
}
234222

235-
#content {
223+
#bodyContent {
236224
margin: 1em;
237225
}
238226

239227
@media (min-width: 600px) {
240-
#content {
228+
#bodyContent {
241229
max-width: 980px;
242230
margin: 2em 3.5em;
243231
}
@@ -262,18 +250,6 @@ pre
262250
font-weight: bold;
263251
}
264252

265-
#footerContent a {
266-
color: #999999;
267-
}
268-
269-
#footerContent summary {
270-
margin-bottom: 1.3em;
271-
}
272-
273-
#footerContent ul {
274-
font-size: 0.85em;
275-
}
276-
277253
.attr-rw {
278254
padding-right: 1em;
279255
text-align: center;
@@ -470,3 +446,42 @@ a.back-to-top {
470446
a.back-to-top.show {
471447
visibility: visible;
472448
}
449+
450+
451+
/*
452+
* More-Less widget
453+
*/
454+
455+
details.more-less {
456+
position: relative;
457+
}
458+
459+
details.more-less summary {
460+
position: absolute;
461+
padding-left: 1em;
462+
font-weight: bold;
463+
color: var(--icon-color);
464+
}
465+
466+
details.more-less summary:hover {
467+
cursor: pointer;
468+
color: inherit;
469+
}
470+
471+
details.more-less summary::marker {
472+
font-size: 1.15em;
473+
content: "+";
474+
}
475+
476+
details.more-less[open] summary {
477+
top: calc(100% + 0.5em);
478+
}
479+
480+
details.more-less[open] summary::marker {
481+
content: "-";
482+
}
483+
484+
details.more-less:not([open]) .more-less__less,
485+
details.more-less[open] .more-less__more {
486+
display: none;
487+
}

lib/sdoc/helpers.rb

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,26 @@ def group_by_first_letter(rdoc_objects)
9191
end
9292
end
9393

94+
def more_less_ul(items, limit)
95+
soft_limit, hard_limit = (limit.is_a?(Range) ? limit : [limit]).minmax
96+
items = items.map { |item| "<li>#{item}</li>" }
97+
98+
if items.length > hard_limit
99+
<<~HTML
100+
<ul>#{items[0...soft_limit].join}</ul>
101+
<details class="more-less">
102+
<summary>
103+
<span class="more-less__more">#{items.length - soft_limit} More</span>
104+
<span class="more-less__less">Less</span>
105+
</summary>
106+
<ul>#{items[soft_limit..].join}</ul>
107+
</details>
108+
HTML
109+
else
110+
"<ul>#{items.join}</ul>"
111+
end
112+
end
113+
94114
def method_source_code_and_url(rdoc_method)
95115
source_code = rdoc_method.markup_code if rdoc_method.token_stream
96116

spec/helpers_spec.rb

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,39 @@ def Qux; end
447447
end
448448
end
449449

450+
describe "#more_less_ul" do
451+
def ul(items)
452+
["<ul>", *items.map { |item| "<li>#{item}</li>" }, "</ul>"].join
453+
end
454+
455+
it "returns a single list when the number of items is <= hard limit" do
456+
_(@helpers.more_less_ul(1..7, 7)).must_equal ul(1..7)
457+
_(@helpers.more_less_ul(1..7, 8)).must_equal ul(1..7)
458+
459+
_(@helpers.more_less_ul(1..7, 6..7)).must_equal ul(1..7)
460+
_(@helpers.more_less_ul(1..7, 6..8)).must_equal ul(1..7)
461+
462+
_(@helpers.more_less_ul(1..7, 7..9)).must_equal ul(1..7)
463+
_(@helpers.more_less_ul(1..7, 8..9)).must_equal ul(1..7)
464+
end
465+
466+
it "returns split lists when the number of items is > hard limit" do
467+
_(@helpers.more_less_ul(1..7, 6)).must_match %r"#{ul 1..6}.*<details.+#{ul 7..7}.*</details>"m
468+
_(@helpers.more_less_ul(1..7, 5)).must_match %r"#{ul 1..5}.*<details.+#{ul 6..7}.*</details>"m
469+
470+
_(@helpers.more_less_ul(1..7, 5..6)).must_match %r"#{ul 1..5}.*<details.+#{ul 6..7}.*</details>"m
471+
_(@helpers.more_less_ul(1..7, 4..6)).must_match %r"#{ul 1..4}.*<details.+#{ul 5..7}.*</details>"m
472+
end
473+
474+
it "specifies the number of hidden items" do
475+
_(@helpers.more_less_ul(1..7, 4)).must_match %r"\b3 More\b"
476+
end
477+
478+
it "does not escape items" do
479+
_(@helpers.more_less_ul(["<a>link</a>"], 1)).must_include "<a>link</a>"
480+
end
481+
end
482+
450483
describe "#method_source_code_and_url" do
451484
before :each do
452485
@helpers.options.github = true

0 commit comments

Comments
 (0)