提交 ea141d62 编写于 作者: R Robin Dupret

Automatically link to Ruby files referenced in notes [ci skip]

To ease reading the "Active Support Core Extensions" guide, let's
automatically link references to Ruby files.

It's also possible to reference other components' files in the even
though it's not used in the guides at the moment.

[Petr Skocik & Robin Dupret]
上级 0676d28b
......@@ -33,7 +33,9 @@ def header(text, header_level)
end
def paragraph(text)
if text =~ /^(TIP|IMPORTANT|CAUTION|WARNING|NOTE|INFO|TODO)[.:]/
if text =~ %r{^NOTE:\s+Defined\s+in\s+<code>(.*?)</code>\.?$}
%(<div class="note"><p>Defined in <code><a href="#{github_file_url($1)}">#{$1}</a></code>.</p></div>)
elsif text =~ /^(TIP|IMPORTANT|CAUTION|WARNING|NOTE|INFO|TODO)[.:]/
convert_notes(text)
elsif text.include?("DO NOT READ THIS FILE ON GITHUB")
elsif text =~ /^\[<sup>(\d+)\]:<\/sup> (.+)$/
......@@ -90,6 +92,22 @@ def convert_notes(body)
end
end
def github_file_url(file_path)
root, rest = file_path.split('/', 2)
case root
when 'abstract_controller', 'action_controller', 'action_dispatch'
path = ['actionpack', 'lib', root, rest].join('/')
when 'active_support', 'active_record', 'active_model', 'action_view',
'action_cable', 'action_mailer', 'action_pack', 'active_job'
path = [root.sub('_', ''), 'lib', root, rest].join('/')
else
path = file_path
end
["https://github.com/rails/rails/tree", version || 'master', path].join('/')
end
def version
ENV['RAILS_VERSION']
end
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册