diff options
Diffstat (limited to 'lib/rdoc/generator')
-rw-r--r-- | lib/rdoc/generator/darkfish.rb | 8 | ||||
-rw-r--r-- | lib/rdoc/generator/json_index.rb | 4 | ||||
-rw-r--r-- | lib/rdoc/generator/markup.rb | 3 | ||||
-rw-r--r-- | lib/rdoc/generator/pot.rb | 1 | ||||
-rw-r--r-- | lib/rdoc/generator/ri.rb | 1 | ||||
-rw-r--r-- | lib/rdoc/generator/template/darkfish/_head.rhtml | 20 | ||||
-rw-r--r-- | lib/rdoc/generator/template/darkfish/_sidebar_pages.rhtml | 6 | ||||
-rw-r--r-- | lib/rdoc/generator/template/darkfish/_sidebar_search.rhtml | 2 | ||||
-rw-r--r-- | lib/rdoc/generator/template/darkfish/_sidebar_table_of_contents.rhtml | 29 | ||||
-rw-r--r-- | lib/rdoc/generator/template/darkfish/class.rhtml | 48 | ||||
-rw-r--r-- | lib/rdoc/generator/template/darkfish/css/rdoc.css | 51 | ||||
-rw-r--r-- | lib/rdoc/generator/template/darkfish/index.rhtml | 2 | ||||
-rw-r--r-- | lib/rdoc/generator/template/darkfish/js/darkfish.js | 15 | ||||
-rw-r--r-- | lib/rdoc/generator/template/darkfish/js/search.js | 8 | ||||
-rw-r--r-- | lib/rdoc/generator/template/darkfish/table_of_contents.rhtml | 13 | ||||
-rw-r--r-- | lib/rdoc/generator/template/json_index/js/navigation.js | 16 |
16 files changed, 145 insertions, 82 deletions
diff --git a/lib/rdoc/generator/darkfish.rb b/lib/rdoc/generator/darkfish.rb index 60e0265e8c..1b408a6f8e 100644 --- a/lib/rdoc/generator/darkfish.rb +++ b/lib/rdoc/generator/darkfish.rb @@ -610,7 +610,7 @@ class RDoc::Generator::Darkfish @classes = @store.all_classes_and_modules.sort @files = @store.all_files.sort - @methods = @classes.map { |m| m.method_list }.flatten.sort + @methods = @classes.flat_map { |m| m.method_list }.sort @modsort = get_sorted_module_list @classes end @@ -778,11 +778,7 @@ class RDoc::Generator::Darkfish erbout = "_erbout_#{file_var}" end - if RUBY_VERSION >= '2.6' - template = klass.new template, trim_mode: '-', eoutvar: erbout - else - template = klass.new template, nil, '-', erbout - end + template = klass.new template, trim_mode: '-', eoutvar: erbout @template_cache[file] = template template end diff --git a/lib/rdoc/generator/json_index.rb b/lib/rdoc/generator/json_index.rb index 3a1000033d..c454910d5c 100644 --- a/lib/rdoc/generator/json_index.rb +++ b/lib/rdoc/generator/json_index.rb @@ -230,9 +230,9 @@ class RDoc::Generator::JsonIndex def index_methods debug_msg " generating method search index" - list = @classes.uniq.map do |klass| + list = @classes.uniq.flat_map do |klass| klass.method_list - end.flatten.sort_by do |method| + end.sort_by do |method| [method.name, method.parent.full_name] end diff --git a/lib/rdoc/generator/markup.rb b/lib/rdoc/generator/markup.rb index 41e132450d..76b7d458aa 100644 --- a/lib/rdoc/generator/markup.rb +++ b/lib/rdoc/generator/markup.rb @@ -109,7 +109,7 @@ class RDoc::MethodAttr lines.shift if src =~ /\A.*#\ *File/i # remove '# File' comment lines.each do |line| if line =~ /^ *(?=\S)/ - n = $&.length + n = $~.end(0) indent = n if n < indent break if n == 0 end @@ -157,4 +157,3 @@ class RDoc::TopLevel end end - diff --git a/lib/rdoc/generator/pot.rb b/lib/rdoc/generator/pot.rb index bee1133b07..b0b7c07179 100644 --- a/lib/rdoc/generator/pot.rb +++ b/lib/rdoc/generator/pot.rb @@ -81,6 +81,7 @@ class RDoc::Generator::POT end end + # :nodoc: def class_dir nil end diff --git a/lib/rdoc/generator/ri.rb b/lib/rdoc/generator/ri.rb index 0eef1d03f5..1c2f018f97 100644 --- a/lib/rdoc/generator/ri.rb +++ b/lib/rdoc/generator/ri.rb @@ -28,4 +28,3 @@ class RDoc::Generator::RI end end - diff --git a/lib/rdoc/generator/template/darkfish/_head.rhtml b/lib/rdoc/generator/template/darkfish/_head.rhtml index 4f331245c3..d5aed3e9ef 100644 --- a/lib/rdoc/generator/template/darkfish/_head.rhtml +++ b/lib/rdoc/generator/template/darkfish/_head.rhtml @@ -3,18 +3,18 @@ <title><%= h @title %></title> <script type="text/javascript"> - var rdoc_rel_prefix = "<%= asset_rel_prefix %>/"; - var index_rel_prefix = "<%= rel_prefix %>/"; + var rdoc_rel_prefix = "<%= h asset_rel_prefix %>/"; + var index_rel_prefix = "<%= h rel_prefix %>/"; </script> -<script src="<%= asset_rel_prefix %>/js/navigation.js" defer></script> -<script src="<%= asset_rel_prefix %>/js/search.js" defer></script> -<script src="<%= asset_rel_prefix %>/js/search_index.js" defer></script> -<script src="<%= asset_rel_prefix %>/js/searcher.js" defer></script> -<script src="<%= asset_rel_prefix %>/js/darkfish.js" defer></script> +<script src="<%= h asset_rel_prefix %>/js/navigation.js" defer></script> +<script src="<%= h asset_rel_prefix %>/js/search.js" defer></script> +<script src="<%= h asset_rel_prefix %>/js/search_index.js" defer></script> +<script src="<%= h asset_rel_prefix %>/js/searcher.js" defer></script> +<script src="<%= h asset_rel_prefix %>/js/darkfish.js" defer></script> -<link href="<%= asset_rel_prefix %>/css/fonts.css" rel="stylesheet"> -<link href="<%= asset_rel_prefix %>/css/rdoc.css" rel="stylesheet"> +<link href="<%= h asset_rel_prefix %>/css/fonts.css" rel="stylesheet"> +<link href="<%= h asset_rel_prefix %>/css/rdoc.css" rel="stylesheet"> <%- @options.template_stylesheets.each do |stylesheet| -%> -<link href="<%= asset_rel_prefix %>/<%= File.basename stylesheet %>" rel="stylesheet"> +<link href="<%= h asset_rel_prefix %>/<%= File.basename stylesheet %>" rel="stylesheet"> <%- end -%> diff --git a/lib/rdoc/generator/template/darkfish/_sidebar_pages.rhtml b/lib/rdoc/generator/template/darkfish/_sidebar_pages.rhtml index 0ed683ca14..3f68f0c0dc 100644 --- a/lib/rdoc/generator/template/darkfish/_sidebar_pages.rhtml +++ b/lib/rdoc/generator/template/darkfish/_sidebar_pages.rhtml @@ -12,18 +12,18 @@ <%- end.each do |n, files| -%> <%- f = files.shift -%> <%- if files.empty? -%> - <li><a href="<%= rel_prefix %>/<%= f.path %>"><%= h f.page_name %></a> + <li><a href="<%= rel_prefix %>/<%= h f.path %>"><%= h f.page_name %></a> <%- next -%> <%- end -%> <li><details<% if dir == n %> open<% end %>><summary><% if n == f.page_name - %><a href="<%= rel_prefix %>/<%= f.path %>"><%= h n %></a><% + %><a href="<%= rel_prefix %>/<%= h f.path %>"><%= h n %></a><% else %><%= h n %><% files.unshift(f) end %></summary> <ul class="link-list"> <%- files.each do |f| -%> - <li><a href="<%= rel_prefix %>/<%= f.path %>"><%= h f.page_name %></a> + <li><a href="<%= rel_prefix %>/<%= h f.path %>"><%= h f.page_name %></a> <%- end -%> </ul></details> <%- end -%> diff --git a/lib/rdoc/generator/template/darkfish/_sidebar_search.rhtml b/lib/rdoc/generator/template/darkfish/_sidebar_search.rhtml index 9c49b31376..afc7f7b88d 100644 --- a/lib/rdoc/generator/template/darkfish/_sidebar_search.rhtml +++ b/lib/rdoc/generator/template/darkfish/_sidebar_search.rhtml @@ -3,7 +3,7 @@ <div id="search-field-wrapper"> <input id="search-field" role="combobox" aria-label="Search" aria-autocomplete="list" aria-controls="search-results" - type="text" name="search" placeholder="Search" spellcheck="false" + type="text" name="search" placeholder="Search (/) for a class, method, ..." spellcheck="false" title="Type to search, Up and Down to navigate, Enter to load"> </div> diff --git a/lib/rdoc/generator/template/darkfish/_sidebar_table_of_contents.rhtml b/lib/rdoc/generator/template/darkfish/_sidebar_table_of_contents.rhtml index bf70819f64..b1e047b5f7 100644 --- a/lib/rdoc/generator/template/darkfish/_sidebar_table_of_contents.rhtml +++ b/lib/rdoc/generator/template/darkfish/_sidebar_table_of_contents.rhtml @@ -3,16 +3,37 @@ else current.comment end - table = current.parse(comment).table_of_contents + table = current.parse(comment).table_of_contents.dup if table.length > 1 then %> <div class="nav-section"> <h3>Table of Contents</h3> + <%- display_link = proc do |heading| -%> + <a href="#<%= heading.label current %>"><%= heading.plain_html %></a> + <%- end -%> + + <%- list_siblings = proc do -%> + <%- level = table.first&.level -%> + <%- while table.first && table.first.level >= level -%> + <%- heading = table.shift -%> + <%- if table.first.nil? || table.first.level <= heading.level -%> + <li><% display_link.call heading -%> + <%- else -%> + <li> + <details open> + <summary><%- display_link.call heading -%></summary> + <ul class="link-list" role="directory"> + <% list_siblings.call %> + </ul> + </details> + </li> + <%- end -%> + <%- end -%> + <%- end -%> + <ul class="link-list" role="directory"> -<%- table.each do |heading| -%> - <li><a href="#<%= heading.label current %>"><%= heading.plain_html %></a> -<%- end -%> + <% list_siblings.call %> </ul> </div> <%- end -%> diff --git a/lib/rdoc/generator/template/darkfish/class.rhtml b/lib/rdoc/generator/template/darkfish/class.rhtml index 5d7b6a1b80..d6510336df 100644 --- a/lib/rdoc/generator/template/darkfish/class.rhtml +++ b/lib/rdoc/generator/template/darkfish/class.rhtml @@ -98,29 +98,36 @@ <%- methods.each do |method| -%> <div id="<%= method.aref %>" class="method-detail <%= method.is_alias_for ? "method-alias" : '' %>"> - <%- 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(/(.*)[-=]>/, '\1→') %> - </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> + <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(/(.*)[-=]>/, '\1→') %> + </span> + <%- if i == 0 and method.token_stream then -%> + <span class="method-click-advice">click to toggle source</span> + <%- end -%> + </div> + <%- end -%> + <%- elsif method.has_call_seq? then -%> + <div class="method-heading"> + <span class="method-name"><%= h method.name %></span> + </div> + <%- 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> - <%- end -%> + <%- unless method.skip_description? then -%> <div class="method-description"> <%- if method.comment then -%> <%= method.description.strip %> @@ -143,6 +150,7 @@ </div> <%- end -%> </div> + <%- end -%> <%- unless method.aliases.empty? then -%> <div class="aliases"> diff --git a/lib/rdoc/generator/template/darkfish/css/rdoc.css b/lib/rdoc/generator/template/darkfish/css/rdoc.css index 1be815f503..2cc55e03b1 100644 --- a/lib/rdoc/generator/template/darkfish/css/rdoc.css +++ b/lib/rdoc/generator/template/darkfish/css/rdoc.css @@ -17,6 +17,14 @@ body { background: #fafafa; font-family: Lato, sans-serif; font-weight: 300; + + /* Layout */ + display: grid; + grid-template-columns: auto 1fr; +} + +body > :last-child { + grid-column: 1 / 3; } h1 span, @@ -79,6 +87,17 @@ pre { border-radius: 0.2em; } +em { + text-decoration-color: rgba(52, 48, 64, 0.25); + text-decoration-line: underline; + text-decoration-style: dotted; +} + +strong, +em { + background-color: rgba(158, 178, 255, 0.1); +} + table { margin: 0; border-spacing: 0; @@ -181,21 +200,25 @@ table tr:nth-child(even) td { /* @group Top-Level Structure */ nav { - float: left; - width: 260px; font-family: Helvetica, sans-serif; font-size: 14px; border-right: 1px solid #ccc; position: sticky; top: 0; overflow: auto; + + /* Layout */ + width: 260px; /* fallback */ + width: max(50px, 20vw); + min-width: 50px; + max-width: 80vw; height: calc(100vh - 100px); /* reduce the footer height */ + resize: horizontal; } main { display: block; - margin: 0 2em 5em 260px; - padding-left: 20px; + margin: 1em; min-width: 340px; font-size: 16px; } @@ -214,7 +237,6 @@ main h6 { } #validator-badges { - clear: both; margin: 1em 1em 2em; font-size: smaller; } @@ -309,23 +331,26 @@ dl.note-list dt { background: url(../images/arrow_up.png) no-repeat right center; } -.nav-section details summary { +.nav-section details > summary { display: block; } -.nav-section details summary::-webkit-details-marker { +.nav-section details > summary::-webkit-details-marker { display: none; } -.nav-section details summary:before { +.nav-section details > summary::before { content: ""; } -.nav-section details summary:after { - content: " \25B6"; /* BLACK RIGHT-POINTING TRIANGLE */ +.nav-section details > summary::after { + content: "\25B6"; /* BLACK RIGHT-POINTING TRIANGLE */ + font-size: 0.8em; + margin-left: 0.4em; } -.nav-section details[open] > summary:after { - content: " \25BD"; /* WHITE DOWN-POINTING TRIANGLE */ + +.nav-section details[open] > summary::after { + content: "\25BD"; /* WHITE DOWN-POINTING TRIANGLE */ } /* @end */ @@ -553,7 +578,7 @@ main .method-click-advice { line-height: 20px; background: url(../images/zoom.png) no-repeat right top; } -main .method-heading:hover .method-click-advice { +main .method-header:hover .method-click-advice { visibility: visible; } diff --git a/lib/rdoc/generator/template/darkfish/index.rhtml b/lib/rdoc/generator/template/darkfish/index.rhtml index 13fa3dcc7f..423e225b68 100644 --- a/lib/rdoc/generator/template/darkfish/index.rhtml +++ b/lib/rdoc/generator/template/darkfish/index.rhtml @@ -17,6 +17,6 @@ main_page = @files.find { |f| f.full_name == @options.main_page } then %> <%= main_page.description %> <%- else -%> -<p>This is the API documentation for <%= @title %>. +<p>This is the API documentation for <%= h @title %>. <%- end -%> </main> diff --git a/lib/rdoc/generator/template/darkfish/js/darkfish.js b/lib/rdoc/generator/template/darkfish/js/darkfish.js index 111bbf8eb9..19a85c54e1 100644 --- a/lib/rdoc/generator/template/darkfish/js/darkfish.js +++ b/lib/rdoc/generator/template/darkfish/js/darkfish.js @@ -54,7 +54,7 @@ function hookSearch() { var html = ''; // TODO add relative path to <script> per-page - html += '<p class="search-match"><a href="' + index_rel_prefix + result.path + '">' + this.hlt(result.title); + html += '<p class="search-match"><a href="' + index_rel_prefix + this.escapeHTML(result.path) + '">' + this.hlt(result.title); if (result.params) html += '<span class="params">' + result.params + '</span>'; html += '</a>'; @@ -78,7 +78,20 @@ function hookSearch() { search.scrollIntoView = search.scrollInWindow; }; +function hookFocus() { + document.addEventListener("keydown", (event) => { + if (document.activeElement.tagName === 'INPUT') { + return; + } + if (event.key === "/") { + event.preventDefault(); + document.querySelector('#search-field').focus(); + } + }); +} + document.addEventListener('DOMContentLoaded', function() { hookSourceViews(); hookSearch(); + hookFocus(); }); diff --git a/lib/rdoc/generator/template/darkfish/js/search.js b/lib/rdoc/generator/template/darkfish/js/search.js index b558ca5b4f..d3cded1d57 100644 --- a/lib/rdoc/generator/template/darkfish/js/search.js +++ b/lib/rdoc/generator/template/darkfish/js/search.js @@ -15,9 +15,9 @@ Search.prototype = Object.assign({}, Navigation, new function() { this.init = function() { var _this = this; var observer = function(e) { - switch(e.keyCode) { - case 38: // Event.KEY_UP - case 40: // Event.KEY_DOWN + switch(e.key) { + case 'ArrowUp': + case 'ArrowDown': return; } _this.search(_this.input.value); @@ -101,7 +101,7 @@ Search.prototype = Object.assign({}, Navigation, new function() { } this.escapeHTML = function(html) { - return html.replace(/[&<>]/g, function(c) { + return html.replace(/[&<>"`']/g, function(c) { return '&#' + c.charCodeAt(0) + ';'; }); } diff --git a/lib/rdoc/generator/template/darkfish/table_of_contents.rhtml b/lib/rdoc/generator/template/darkfish/table_of_contents.rhtml index 303d7016cc..54a376c9e5 100644 --- a/lib/rdoc/generator/template/darkfish/table_of_contents.rhtml +++ b/lib/rdoc/generator/template/darkfish/table_of_contents.rhtml @@ -8,14 +8,14 @@ <ul> <%- simple_files.sort.each do |file| -%> <li class="file"> - <a href="<%= file.path %>"><%= h file.page_name %></a> + <a href="<%= h file.path %>"><%= h file.page_name %></a> <% # HACK table_of_contents should not exist on Document table = file.parse(file.comment).table_of_contents unless table.empty? then %> <ul> <%- table.each do |heading| -%> - <li><a href="<%= file.path %>#<%= heading.aref %>"><%= heading.plain_html %></a> + <li><a href="<%= h file.path %>#<%= heading.aref %>"><%= heading.plain_html %></a> <%- end -%> </ul> <%- end -%> @@ -36,8 +36,9 @@ unless table.empty? then %> <ul> <%- table.each do |item| -%> - <li><a href="<%= klass.path %>#<%= item.aref %>"><%= item.plain_html %></a> -<%- end -%> +<%- label = item.respond_to?(:label) ? item.label(klass) : item.aref -%> + <li><a href="<%= klass.path %>#<%= label %>"><%= item.plain_html %></a> +<%- end -%> </ul> <%- end -%> </li> @@ -46,9 +47,9 @@ <h2 id="methods">Methods</h2> <ul> -<%- @store.all_classes_and_modules.map do |mod| +<%- @store.all_classes_and_modules.flat_map do |mod| mod.method_list - end.flatten.sort.each do |method| %> + end.sort.each do |method| %> <li class="method"> <a href="<%= method.path %>"><%= h method.pretty_name %></a> — diff --git a/lib/rdoc/generator/template/json_index/js/navigation.js b/lib/rdoc/generator/template/json_index/js/navigation.js index dfad74b1ae..137e3a0038 100644 --- a/lib/rdoc/generator/template/json_index/js/navigation.js +++ b/lib/rdoc/generator/template/json_index/js/navigation.js @@ -23,24 +23,24 @@ Navigation = new function() { this.onkeydown = function(e) { if (!this.navigationActive) return; - switch(e.keyCode) { - case 37: //Event.KEY_LEFT: + switch(e.key) { + case 'ArrowLeft': if (this.moveLeft()) e.preventDefault(); break; - case 38: //Event.KEY_UP: - if (e.keyCode == 38 || e.ctrlKey) { + case 'ArrowUp': + if (e.key == 'ArrowUp' || e.ctrlKey) { if (this.moveUp()) e.preventDefault(); } break; - case 39: //Event.KEY_RIGHT: + case 'ArrowRight': if (this.moveRight()) e.preventDefault(); break; - case 40: //Event.KEY_DOWN: - if (e.keyCode == 40 || e.ctrlKey) { + case 'ArrowDown': + if (e.key == 'ArrowDown' || e.ctrlKey) { if (this.moveDown()) e.preventDefault(); } break; - case 13: //Event.KEY_RETURN: + case 'Enter': if (this.current) e.preventDefault(); this.select(this.current); break; |