Skip to content

Commit b1153b4

Browse files
Merge pull request #351 from jonathanhefner/method-signature-call-seq-line-breaks
Fix multi-line `:call-seq:` method signatures
2 parents d6374a6 + 40bf829 commit b1153b4

File tree

3 files changed

+14
-7
lines changed

3 files changed

+14
-7
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -772,6 +772,11 @@ html {
772772
white-space: pre-wrap;
773773
}
774774

775+
.method__signature code .returns {
776+
font-family: var(--body-font);
777+
font-size: 1.1em;
778+
}
779+
775780
.target .method__signature code::before {
776781
content: " ";
777782

lib/sdoc/helpers.rb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -207,14 +207,16 @@ def module_methods(rdoc_module)
207207
end
208208

209209
def method_signature(rdoc_method)
210-
if rdoc_method.call_seq
210+
signature = if rdoc_method.call_seq
211211
# Support specifying a call-seq like `to_s -> string`
212212
rdoc_method.call_seq.gsub(/^\s*([^(\s]+)(.*?)(?: -> (.+))?$/) do
213-
"<code><b>#{h $1}</b>#{h $2}</code>#{" &rarr; <code>#{h $3}</code>" if $3}"
213+
"<b>#{h $1}</b>#{h $2}#{" <span class=\"returns\">&rarr;</span> #{h $3}" if $3}"
214214
end
215215
else
216-
"<code><b>#{h rdoc_method.name}</b>#{h rdoc_method.params}</code>"
216+
"<b>#{h rdoc_method.name}</b>#{h rdoc_method.params}"
217217
end
218+
219+
"<code>#{signature}</code>"
218220
end
219221

220222
def method_source_code_and_url(rdoc_method)

spec/helpers_spec.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -813,13 +813,13 @@ def qux(&block); end
813813
RUBY
814814

815815
_(@helpers.method_signature(mod.find_method("bar", false))).must_equal <<~HTML.chomp
816-
<code><b>bar</b>(op = :&lt;)</code>
817-
<code><b>bar</b>(&amp;block)</code>
816+
<code><b>bar</b>(op = :&lt;)
817+
<b>bar</b>(&amp;block)</code>
818818
HTML
819819

820820
_(@helpers.method_signature(mod.find_method("qux", false))).must_equal <<~HTML.chomp
821-
<code><b>qux</b>(&amp;block)</code> &rarr; <code>self</code>
822-
<code><b>qux</b></code> &rarr; <code>Enumerator</code>
821+
<code><b>qux</b>(&amp;block) <span class="returns">&rarr;</span> self
822+
<b>qux</b> <span class="returns">&rarr;</span> Enumerator</code>
823823
HTML
824824
end
825825
end

0 commit comments

Comments
 (0)