Skip to content

Commit

Permalink
Merge pull request #351 from jonathanhefner/method-signature-call-seq…
Browse files Browse the repository at this point in the history
…-line-breaks

Fix multi-line `:call-seq:` method signatures
  • Loading branch information
jonathanhefner authored Dec 24, 2023
2 parents d6374a6 + 40bf829 commit b1153b4
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
5 changes: 5 additions & 0 deletions lib/rdoc/generator/template/rails/resources/css/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -772,6 +772,11 @@ html {
white-space: pre-wrap;
}

.method__signature code .returns {
font-family: var(--body-font);
font-size: 1.1em;
}

.target .method__signature code::before {
content: " ";

Expand Down
8 changes: 5 additions & 3 deletions lib/sdoc/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -207,14 +207,16 @@ def module_methods(rdoc_module)
end

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

"<code>#{signature}</code>"
end

def method_source_code_and_url(rdoc_method)
Expand Down
8 changes: 4 additions & 4 deletions spec/helpers_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -813,13 +813,13 @@ def qux(&block); end
RUBY

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

_(@helpers.method_signature(mod.find_method("qux", false))).must_equal <<~HTML.chomp
<code><b>qux</b>(&amp;block)</code> &rarr; <code>self</code>
<code><b>qux</b></code> &rarr; <code>Enumerator</code>
<code><b>qux</b>(&amp;block) <span class="returns">&rarr;</span> self
<b>qux</b> <span class="returns">&rarr;</span> Enumerator</code>
HTML
end
end
Expand Down

0 comments on commit b1153b4

Please sign in to comment.