diff options
author | Robin Dupret <robin.dupret@gmail.com> | 2017-01-29 13:16:10 +0100 |
---|---|---|
committer | Robin Dupret <robin.dupret@gmail.com> | 2017-02-07 21:45:53 +0100 |
commit | ea141d62dfbb8cb02f20137e75da0fa9977e84c8 (patch) | |
tree | 5ccb07c39c9a32c5687b3f8597fa9dc550e8a053 /guides/rails_guides | |
parent | 0676d28b2222eae21bbd43c721f0ec229385865a (diff) | |
download | rails-ea141d62dfbb8cb02f20137e75da0fa9977e84c8.tar.gz rails-ea141d62dfbb8cb02f20137e75da0fa9977e84c8.tar.bz2 rails-ea141d62dfbb8cb02f20137e75da0fa9977e84c8.zip |
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]
Diffstat (limited to 'guides/rails_guides')
-rw-r--r-- | guides/rails_guides/markdown/renderer.rb | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/guides/rails_guides/markdown/renderer.rb b/guides/rails_guides/markdown/renderer.rb index 2fc2c5d9cb..97df6f0559 100644 --- a/guides/rails_guides/markdown/renderer.rb +++ b/guides/rails_guides/markdown/renderer.rb @@ -33,7 +33,9 @@ HTML 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 @@ HTML 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 |