diff --git a/lib/rdoc/generator/template/rails/_context.rhtml b/lib/rdoc/generator/template/rails/_context.rhtml index 994de3ab..748ba2c5 100644 --- a/lib/rdoc/generator/template/rails/_context.rhtml +++ b/lib/rdoc/generator/template/rails/_context.rhtml @@ -159,32 +159,25 @@ <% end %> <% source_code, source_url = method_source_code_and_url(method) %> - <% if source_code || source_url %> -
- Source:
-
- <% if source_code %>
- show
- <% end %>
-
- <% if source_code && source_url %> | <% end %>
-
+ <% if source_code %>
+
+ Source code
<% if source_url %>
- on GitHub
+ <%= link_to_external "GitHub", source_url %>
<% end %>
-
<%= source_code %>
- <%= source_code %>
+ <%= link_to_external "GitHub", source_url %>
+ <% end %> + + <% end %><%# methods.each %> + <% end %><%# visibilities.each %> <% end %><%# context.methods_by_type %> <% end %><%# context.each_section %> diff --git a/lib/rdoc/generator/template/rails/resources/css/main.css b/lib/rdoc/generator/template/rails/resources/css/main.css index 6c609713..2b3bb1d1 100644 --- a/lib/rdoc/generator/template/rails/resources/css/main.css +++ b/lib/rdoc/generator/template/rails/resources/css/main.css @@ -12,6 +12,10 @@ body { display: grid; grid-template-rows: min-content min-content auto min-content; grid-template-columns: 300px auto; + + --link-color: #CC0000; + --link-hover-color: #990000; + --icon-color: #777777; } body { @@ -61,12 +65,12 @@ body { } a:link, a:active, a:visited, a:hover { - color: #CC0000; + color: var(--link-color); text-decoration: none; } a:hover { - color: #990000; + color: var(--link-hover-color); text-decoration: underline; } @@ -78,6 +82,13 @@ h1 a, h2 a, .banner a { color: #fff; } +.external-link { + padding-left: 1.3em; + background-image: url('../i/external-link.svg'); + background-repeat: no-repeat; + background-size: 1.1em; +} + p { margin-bottom: 1em; } @@ -290,7 +301,6 @@ tt { } .dyn-source { - display: none; background: #fffde8; color: #000; border: #ffe0bb dotted 1px; @@ -343,19 +353,40 @@ tt { top: 0; } -.method .sourcecode p.source-link { - text-indent: 0em; - margin-top: 0.5em; -} - .method .aka { margin-left: 1.2em; font-style: italic; } -.method .source-link -{ - font-size: 0.85em; +.sourcecode { + width: fit-content; /* Reduce clickable area when collapsed */ +} + +.sourcecode[open] { + width: auto; +} + +.sourcecode summary { + cursor: pointer; +} + +.sourcecode summary::marker { + font-size: 1.25em; + color: var(--icon-color); +} + +.sourcecode summary .label { + margin-left: -0.4em; + font-weight: bold; + color: var(--link-color); +} + +.sourcecode summary .label:hover { + color: var(--link-hover-color); +} + +.sourcecode summary .external-link { + margin-left: 1em; } @keyframes spotlight { diff --git a/lib/rdoc/generator/template/rails/resources/i/external-link.svg b/lib/rdoc/generator/template/rails/resources/i/external-link.svg new file mode 100644 index 00000000..31c1df5b --- /dev/null +++ b/lib/rdoc/generator/template/rails/resources/i/external-link.svg @@ -0,0 +1 @@ + diff --git a/lib/rdoc/generator/template/rails/resources/js/main.js b/lib/rdoc/generator/template/rails/resources/js/main.js index 70ebbc0b..6bf81bff 100644 --- a/lib/rdoc/generator/template/rails/resources/js/main.js +++ b/lib/rdoc/generator/template/rails/resources/js/main.js @@ -1,9 +1,3 @@ -function toggleSource(id) { - var src = $('#' + id).toggle(); - var isVisible = src.is(':visible'); - $('#l_' + id).html(isVisible ? 'hide' : 'show'); -} - window.spotlight = function(url) { var hash = url.match(/#([^#]+)$/); if (hash) { diff --git a/lib/sdoc/helpers.rb b/lib/sdoc/helpers.rb index bf9934df..d47aab1a 100644 --- a/lib/sdoc/helpers.rb +++ b/lib/sdoc/helpers.rb @@ -33,6 +33,14 @@ def link_to(text, url, html_attributes = {}) %(#{h text}) end + def link_to_external(text, url, html_attributes = {}) + html_attributes = html_attributes.transform_keys(&:to_s) + html_attributes = { "target" => "_blank", "class" => nil }.merge(html_attributes) + html_attributes["class"] = [*html_attributes["class"], "external-link"].join(" ") + + link_to(text, url, html_attributes) + end + def base_tag_for_context(context) if context == :index %(