Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve CSS for "toggle source" hovering over one more method signatures #1020

Merged
merged 1 commit into from
Jul 5, 2023

Conversation

ybiquitous
Copy link
Contributor

@ybiquitous ybiquitous commented Jun 12, 2023

This PR improves the behavior of showing the "toggle source" element on mouseover.

For example, when a method has one more signatures by using :call-seq:,

# :call-seq:
#   foo {|element| ... } -> self
#   foo -> new_enumeration
def foo
end

The current CSS doesn't show "toggle source" even when hovering the second signature foo -> new_enumeration.
But this change will show "toggle source" always when hovering over any signature.

For details about the .method-header element, see lib/rdoc/generator/template/darkfish/class.rhtml:

<div class="method-header">
<%- if (call_seq = method.call_seq) then -%>
<%- call_seq.strip.split("\n").each_with_index do |call_seq, i| -%>
<div class="method-heading">
<span class="method-callseq">
<%= h(call_seq.strip.
gsub( /^\w+\./m, '')).
gsub(/(.*)[-=]&gt;/, '\1&rarr;') %>
</span>
<%- if i == 0 and method.token_stream then -%>
<span class="method-click-advice">click to toggle source</span>
<%- end -%>
</div>
<%- end -%>
<%- else -%>
<div class="method-heading">
<span class="method-name"><%= h method.name %></span><span
class="method-args"><%= h method.param_seq %></span>
<%- if method.token_stream then -%>
<span class="method-click-advice">click to toggle source</span>
<%- end -%>
</div>
<%- end -%>
</div>

For example, see https://docs.ruby-lang.org/en/3.2/Array.html#method-i-delete

Test locally

  1. Add :call-seq: temporarily like this:
--- a/lib/rdoc.rb
+++ b/lib/rdoc.rb
@@ -198,4 +198,9 @@ module RDoc
   autoload :Extend,         "#{__dir__}/rdoc/extend"
   autoload :Require,        "#{__dir__}/rdoc/require"
 
+  # :call-seq:
+  #   foo {|element| ... } -> self
+  #   foo -> new_enumeration
+  def foo
+  end
 end
  1. Run bundle exec rake rerdoc to build
  2. Run open _site/RDoc.html
    • image

This commit improves the behavior of showing the "toggle source" element on mouseover.

For example, when a method has one more signatures by using `:call-seq:`,

```ruby
# :call-seq:
#   foo {|element| ... } -> self
#   foo -> new_enumeration
def foo
end
```

The current CSS doesn't show "toggle source" even when hovering the second signature `foo -> new_enumeration`.
But this change will show "toggle source" always when hovering over any signature.

For details about the `.method-header` element, see `lib/rdoc/generator/template/darkfish/class.rhtml`:
https://github.com/ruby/rdoc/blob/0e060c69f51ec4a877e5cde69b31d47eaeb2a2b9/lib/rdoc/generator/template/darkfish/class.rhtml#L101-L124

For example, see https://docs.ruby-lang.org/en/3.2/Array.html#method-i-delete
@nobu nobu merged commit e8f22ce into ruby:master Jul 5, 2023
21 checks passed
@ybiquitous ybiquitous deleted the improve-css-for-toggle-source branch July 5, 2023 04:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants