Skip to content

Commit

Permalink
Merge branch 'ruby:master' into feat/focus
Browse files Browse the repository at this point in the history
  • Loading branch information
gemmaro authored Jan 5, 2023
2 parents 88de321 + 9c03b6e commit eae3cfd
Show file tree
Hide file tree
Showing 37 changed files with 471 additions and 165 deletions.
6 changes: 6 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
version: 2
updates:
- package-ecosystem: 'github-actions'
directory: '/'
schedule:
interval: 'weekly'
14 changes: 11 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ name: Test

on: [push, pull_request]

permissions: # added using https://github.com/step-security/secure-workflows
contents: read

jobs:
build:
strategy:
Expand All @@ -12,12 +15,15 @@ jobs:
- ubuntu-latest
include:
- { ruby: '3.1', os: 'macos-latest' }
- { ruby: 'jruby-9.2.19.0', os: 'ubuntu-latest' }
- { ruby: 'jruby-head', os: 'ubuntu-latest' }
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@755da8c3cf115ac066823e79a1e1788f8940201b # v3.2.0
# libyaml-dev is needed for psych, see https://github.com/ruby/setup-ruby/issues/409
- if: ${{ matrix.os == 'ubuntu-latest' }}
run: sudo apt install libyaml-dev
- name: Set up Ruby
uses: ruby/setup-ruby@v1
uses: ruby/setup-ruby@09c10210cc6e998d842ce8433cd9d245933cd797 # v1.133.0
with:
ruby-version: ${{ matrix.ruby }}
bundler-cache: true # 'bundle install' and cache
Expand All @@ -28,4 +34,6 @@ jobs:
run: bundle exec rake
env:
RUBYOPT: --enable-frozen_string_literal
- if: ${{ matrix.ruby == 'head' && startsWith(matrix.os, 'ubuntu') }}
run: bundle exec rake rubocop

3 changes: 1 addition & 2 deletions CONTRIBUTING.rdoc
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ RDoc uses bundler for development. To get ready to work on RDoc run:
This will install all the necessary dependencies for development with rake,
generate documentation and run the tests for the first time.

If the tests don't pass on the first run check the {Travis CI page for
RDoc}[https://travis-ci.org/ruby/rdoc] to see if there are any known failures
If the tests don't pass on the first run check the {GitHub Actions page}[https://github.com/ruby/rdoc/actions] to see if there are any known failures
(there shouldn't be).

You can now use `rake` and `autotest` to run the tests.
Expand Down
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ group :development do
gem 'racc', '> 1.4.10'
gem 'kpeg', github: 'evanphx/kpeg'
gem 'test-unit'
gem 'rubocop'
gem 'rubocop', '>= 1.31.0'
gem 'gettext'
end
5 changes: 2 additions & 3 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,12 @@ task ghpages: :rdoc do
end

Rake::TestTask.new(:normal_test) do |t|
t.libs = []
t.verbose = true
t.deps = :generate
t.test_files = FileList["test/**/test_*.rb"].exclude("test/rdoc/test_rdoc_rubygems_hook.rb")
end

Rake::TestTask.new(:rubygems_test) do |t|
t.libs = []
t.verbose = true
t.deps = :generate
t.pattern = "test/rdoc/test_rdoc_rubygems_hook.rb"
Expand Down Expand Up @@ -83,6 +81,7 @@ parsed_files = PARSER_FILES.map do |parser_file|
kpeg = Gem.bin_path 'kpeg', 'kpeg'
rb_file = parser_file.gsub(/\.kpeg\z/, ".rb")
ruby "#{kpeg} -fsv -o #{rb_file} #{parser_file}"
File.write(rb_file, File.read(rb_file).gsub(/ +$/, '')) # remove trailing spaces
end
end

Expand All @@ -106,5 +105,5 @@ else
RuboCop::RakeTask.new(:rubocop) do |t|
t.options = [*parsed_files]
end
task :build => [:generate, "rubocop:auto_correct"]
task :build => [:generate, "rubocop:autocorrect"]
end
2 changes: 1 addition & 1 deletion lib/rdoc/generator/markup.rb
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def markup_code
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
Expand Down
20 changes: 10 additions & 10 deletions lib/rdoc/generator/template/darkfish/_head.rhtml
Original file line number Diff line number Diff line change
Expand Up @@ -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 -%>
6 changes: 3 additions & 3 deletions lib/rdoc/generator/template/darkfish/_sidebar_pages.rhtml
Original file line number Diff line number Diff line change
Expand Up @@ -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 -%>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 -%>
42 changes: 22 additions & 20 deletions lib/rdoc/generator/template/darkfish/class.rhtml
Original file line number Diff line number Diff line change
Expand Up @@ -98,28 +98,30 @@

<%- 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(/(.*)[-=]&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>
<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>
<%- end -%>

<div class="method-description">
<%- if method.comment then -%>
Expand Down
2 changes: 1 addition & 1 deletion lib/rdoc/generator/template/darkfish/index.rhtml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
2 changes: 1 addition & 1 deletion lib/rdoc/generator/template/darkfish/js/darkfish.js
Original file line number Diff line number Diff line change
Expand Up @@ -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>';
Expand Down
2 changes: 1 addition & 1 deletion lib/rdoc/generator/template/darkfish/js/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) + ';';
});
}
Expand Down
4 changes: 2 additions & 2 deletions lib/rdoc/generator/template/darkfish/table_of_contents.rhtml
Original file line number Diff line number Diff line change
Expand Up @@ -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 -%>
Expand Down
29 changes: 18 additions & 11 deletions lib/rdoc/markdown.kpeg
Original file line number Diff line number Diff line change
Expand Up @@ -1198,19 +1198,26 @@ CodeFence = &{ github? }
}

Table = &{ github? }
TableRow:header TableLine:line TableRow+:body
TableHead:header TableLine:line TableRow+:body
{ table = RDoc::Markup::Table.new(header, line, body) }

TableRow = TableItem+:row "|" @Newline
{ row }
TableItem = "|" < (!"|" !@Newline .)+ >
{ text.strip }

TableLine = TableColumn+:line "|" @Newline
{ line }
TableColumn = "|" < ( "-"+ ":"? | ":" "-"* ) >
{ text.start_with?(":") ? :left :
text.end_with?(":") ? :right : nil
TableHead = TableItem2+:items "|"? @Newline
{ items }

TableRow = ( ( TableItem:item1 TableItem2*:items { [item1, *items] } ):row | TableItem2+:row ) "|"? @Newline
{ row }
TableItem2 = "|" TableItem
TableItem = < /(?:\\.|[^|\n])+/ >
{ text.strip.gsub(/\\(.)/, '\1') }

TableLine = ( ( TableAlign:align1 TableAlign2*:aligns {[align1, *aligns] } ):line | TableAlign2+:line ) "|"? @Newline
{ line }
TableAlign2 = "|" @Sp TableAlign
TableAlign = < /:?-+:?/ > @Sp
{
text.start_with?(":") ?
(text.end_with?(":") ? :center : :left) :
(text.end_with?(":") ? :right : nil)
}

DefinitionList = &{ definition_lists? }
Expand Down
33 changes: 23 additions & 10 deletions lib/rdoc/markup/attribute_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,17 @@
##
# Manages changes of attributes in a block of text

unless MatchData.method_defined?(:match_length)
using Module.new {
refine(MatchData) {
def match_length(nth)
b, e = offset(nth)
e - b if b
end
}
}
end

class RDoc::Markup::AttributeManager

##
Expand Down Expand Up @@ -153,16 +164,17 @@ def convert_attrs_matching_word_pairs(str, attrs, exclusive)
tags = "[#{tags.join("")}](?!#{PROTECT_ATTR})"
all_tags = "[#{@matching_word_pairs.keys.join("")}](?!#{PROTECT_ATTR})"

re = /(^|\W|#{all_tags})(#{tags})(\2*[#\\]?[\w:#{PROTECT_ATTR}.\/\[\]-]+?\S?)\2(?!\2)(#{all_tags}|\W|$)/
re = /(?:^|\W|#{all_tags})\K(#{tags})(\1*[#\\]?[\w:#{PROTECT_ATTR}.\/\[\]-]+?\S?)\1(?!\1)(?=#{all_tags}|\W|$)/

1 while str.gsub!(re) { |orig|
attr = @matching_word_pairs[$2]
attr_updated = attrs.set_attrs($`.length + $1.length + $2.length, $3.length, attr)
if attr_updated
$1 + NULL * $2.length + $3 + NULL * $2.length + $4
a, w = (m = $~).values_at(1, 2)
attr = @matching_word_pairs[a]
if attrs.set_attrs(m.begin(2), w.length, attr)
a = NULL * a.length
else
$1 + NON_PRINTING_START + $2 + NON_PRINTING_END + $3 + NON_PRINTING_START + $2 + NON_PRINTING_END + $4
a = NON_PRINTING_START + a + NON_PRINTING_END
end
a + w + a
}
str.delete!(NON_PRINTING_START + NON_PRINTING_END)
end
Expand All @@ -173,9 +185,10 @@ def convert_attrs_word_pair_map(str, attrs, exclusive)
@word_pair_map.each do |regexp, attr|
next unless exclusive == exclusive?(attr)
1 while str.gsub!(regexp) { |orig|
updated = attrs.set_attrs($`.length + $1.length, $2.length, attr)
w = (m = ($~))[2]
updated = attrs.set_attrs(m.begin(2), w.length, attr)
if updated
NULL * $1.length + $2 + NULL * $3.length
NULL * m.match_length(1) + w + NULL * m.match_length(3)
else
orig
end
Expand All @@ -194,9 +207,9 @@ def convert_html(str, attrs, exclusive = false)

1 while str.gsub!(/<(#{tags})>(.*?)<\/\1>/i) { |orig|
attr = @html_tags[$1.downcase]
html_length = $1.length + 2
html_length = $~.match_length(1) + 2 # "<>".length
seq = NULL * html_length
attrs.set_attrs($`.length + html_length, $2.length, attr)
attrs.set_attrs($~.begin(2), $~.match_length(2), attr)
seq + $2 + seq + NULL
}
end
Expand Down
Loading

0 comments on commit eae3cfd

Please sign in to comment.