Skip to content

Commit 5a42bbc

Browse files
Style .method elements
1 parent 4a1b77a commit 5a42bbc

File tree

4 files changed

+76
-75
lines changed

4 files changed

+76
-75
lines changed

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

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@
131131
<h2 class="content__divider"><%= visibility.to_s.capitalize %> <%= type %> methods</h2>
132132
<% methods.each do |method| %>
133133
<div class="method">
134-
<h3 class="title method-title" id="<%= method.aref %>">
134+
<h3 class="method__signature" id="<%= method.aref %>">
135135
<% if method.call_seq %>
136136
<b><%= method.call_seq.gsub(/->/, '&rarr;').gsub(/\n(.)/, '<br />\1') %></b>
137137
<% else %>
@@ -141,15 +141,15 @@
141141
<%= link_to "Link", method, class: "permalink", name: method.aref %>
142142

143143
<% unless method.aliases.empty? %>
144-
<p class="aka">
144+
<p class="method__aka">
145145
Also aliased as:
146146
<%# Sometimes a parent cannot be determined. See ruby/rdoc@85ebfe13dc. %>
147147
<%= method.aliases.map { |aka| link_to_if aka.parent, short_name(aka), aka }.join(", ") %>.
148148
</p>
149149
<% end %>
150150

151151
<% if alias_for = method.is_alias_for then %>
152-
<p class="aka">
152+
<p class="method__aka">
153153
Alias for:
154154
<%= link_to short_name(alias_for), alias_for %>.
155155
</p>
@@ -163,20 +163,18 @@
163163

164164
<% source_code, source_url = method_source_code_and_url(method) %>
165165
<% if source_code %>
166-
<details class="sourcecode">
166+
<details class="method__source">
167167
<summary>
168168
<span class="label">Source code</span>
169169
<% if source_url %>
170170
<%= link_to_external "GitHub", source_url %>
171171
<% end %>
172172
</summary>
173173

174-
<div class="dyn-source">
175-
<pre><code class="ruby"><%= source_code %></code></pre>
176-
</div>
174+
<pre><code class="ruby"><%= source_code %></code></pre>
177175
</details>
178176
<% elsif source_url %>
179-
<p><%= link_to_external "GitHub", source_url %></p>
177+
<p class="method__source"><%= link_to_external "GitHub", source_url %></p>
180178
<% end %>
181179
</div>
182180
<% end %><%# methods.each %>

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

Lines changed: 65 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
--link-hover-color: #990000;
1313
--icon-color: #777777;
1414

15-
--body-bg: #fff;
16-
--code-bg: #eee;
17-
--source-code-bg: #fffde8;
15+
--body-bg: #ffffff;
16+
--code-bg: #f1f1f1;
17+
--source-code-bg: #f1f1e1;
1818
}
1919

2020
@media (prefers-color-scheme: dark) {
@@ -149,34 +149,20 @@ dt
149149
font-size: 1.15em;
150150
}
151151

152-
.dyn-source {
153-
background: var(--source-code-bg);
154-
color: #000;
155-
border: #ffe0bb dotted 1px;
156-
margin: 0.5em 2em 0.5em 0;
157-
padding: 0.5em;
158-
}
159-
160152
.description pre {
161153
padding: 1em 1.2em;
162154
background: var(--code-bg);
163155
border-radius: 10px;
164156
}
165157

166158
.description pre,
167-
.sourcecode pre {
159+
.method__source pre {
168160
overflow-x: auto;
169161
}
170162

171163
.method {
172-
margin-bottom: 2em;
173164
position: relative;
174165
}
175-
.method .description,
176-
.method .sourcecode
177-
{
178-
margin-left: 1.2em;
179-
}
180166
.method h4
181167
{
182168
border-bottom: 1px dotted #999;
@@ -185,14 +171,6 @@ dt
185171
font-size: 1.1em;
186172
color: var(--heading-color);
187173
}
188-
.method .method-title {
189-
border-bottom: 1px dotted #666;
190-
padding: 0 0 0.15em 0;
191-
margin: 0 0 0.5em 0;
192-
font-size: 1.2em;
193-
line-height: 1.25em;
194-
position: relative;
195-
}
196174

197175
.method a.permalink {
198176
position: absolute;
@@ -201,42 +179,6 @@ dt
201179
top: 0;
202180
}
203181

204-
.method .aka {
205-
margin-left: 1.2em;
206-
font-style: italic;
207-
}
208-
209-
.sourcecode {
210-
width: fit-content; /* Reduce clickable area when collapsed */
211-
}
212-
213-
.sourcecode[open] {
214-
width: auto;
215-
}
216-
217-
.sourcecode summary {
218-
cursor: pointer;
219-
}
220-
221-
.sourcecode summary::marker {
222-
font-size: 1.25em;
223-
color: var(--icon-color);
224-
}
225-
226-
.sourcecode summary .label {
227-
margin-left: -0.4em;
228-
font-weight: bold;
229-
color: var(--link-color);
230-
}
231-
232-
.sourcecode summary .label:hover {
233-
color: var(--link-hover-color);
234-
}
235-
236-
.sourcecode summary .external-link {
237-
margin-left: 1em;
238-
}
239-
240182
@keyframes spotlight {
241183
from { background-color: yellow; }
242184
to { background-color: white; }
@@ -529,6 +471,67 @@ html {
529471
}
530472

531473

474+
/*
475+
* Method
476+
*/
477+
478+
.method {
479+
margin-top: var(--space-xl);
480+
}
481+
482+
.content__divider + .method {
483+
margin-top: var(--space-lg);
484+
}
485+
486+
.method__signature {
487+
font-size: 1.1em;
488+
font-weight: normal;
489+
padding-bottom: var(--space-sm);
490+
border-bottom: 2px solid var(--code-bg);
491+
}
492+
493+
.method__aka {
494+
font-style: italic;
495+
}
496+
497+
.method__source {
498+
width: fit-content; /* Reduce clickable area when collapsed */
499+
}
500+
501+
.method__source[open] {
502+
width: auto;
503+
}
504+
505+
.method__source summary {
506+
cursor: pointer;
507+
}
508+
509+
.method__source summary::marker {
510+
color: var(--icon-color);
511+
}
512+
513+
.method__source summary .label {
514+
margin-left: -0.2em;
515+
color: var(--link-color);
516+
}
517+
518+
.method__source summary .label:hover {
519+
color: var(--link-hover-color);
520+
}
521+
522+
.method__source summary .external-link {
523+
margin-left: 1em;
524+
}
525+
526+
.method__source pre {
527+
margin-top: var(--space-sm);
528+
padding: 0.5em 1em;
529+
border-radius: 8px;
530+
531+
background: var(--source-code-bg);
532+
}
533+
534+
532535
/*
533536
* More-Less widget
534537
*/

lib/sdoc/postprocessor.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ def style_ref_links!(document)
8989
end
9090

9191
def highlight_code_blocks!(document)
92-
document.css(".description pre > code, .sourcecode pre > code").each do |element|
92+
document.css(".description pre > code, .method__source pre > code").each do |element|
9393
code = element.inner_text
9494
language = element.classes.include?("ruby") ? "ruby" : guess_code_language(code)
9595
element.inner_html = highlight_code(code, language)

spec/postprocessor_spec.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -148,21 +148,21 @@
148148

149149
it "highlights method source code" do
150150
rendered = <<~HTML
151-
<div class="sourcecode">
151+
<div class="method__source">
152152
<pre><code class="ruby"><span class="ruby-comment"># highlighted by RDoc</span></code></pre>
153153
</div>
154154
155-
<div class="sourcecode">
155+
<div class="method__source">
156156
<pre><code class="ruby">DELETE FROM 'tricky_ruby'</code></pre>
157157
</div>
158158
HTML
159159

160160
expected = <<~HTML
161-
<div class="sourcecode">
161+
<div class="method__source">
162162
<pre><code class="ruby highlight">#{SDoc::Postprocessor.highlight_code("# highlighted by RDoc", "ruby")}</code></pre>
163163
</div>
164164
165-
<div class="sourcecode">
165+
<div class="method__source">
166166
<pre><code class="ruby highlight">#{SDoc::Postprocessor.highlight_code("DELETE FROM 'tricky_ruby'", "ruby")}</code></pre>
167167
</div>
168168
HTML

0 commit comments

Comments
 (0)