From 0676d28b2222eae21bbd43c721f0ec229385865a Mon Sep 17 00:00:00 2001 From: Robin Dupret Date: Wed, 30 Nov 2016 19:27:35 +0100 Subject: Automatically inject the current Rails version in API links [ci skip] To make sure that the user won't look at a feature that doesn't already exist if they are looking at a previous version of the guides, let's automatically inject the Rails version the guides have been generated against. --- guides/rails_guides/markdown/renderer.rb | 23 +++++++++++++++++++++++ guides/source/5_0_release_notes.md | 2 +- 2 files changed, 24 insertions(+), 1 deletion(-) (limited to 'guides') diff --git a/guides/rails_guides/markdown/renderer.rb b/guides/rails_guides/markdown/renderer.rb index deab741023..2fc2c5d9cb 100644 --- a/guides/rails_guides/markdown/renderer.rb +++ b/guides/rails_guides/markdown/renderer.rb @@ -15,6 +15,16 @@ module RailsGuides HTML end + def link(url, title, content) + if url.start_with?('http://api.rubyonrails.org') + %(#{content}) + elsif title + %(#{content}) + else + %(#{content}) + end + end + def header(text, header_level) # Always increase the heading level by 1, so we can use h1, h2 heading in the document header_level += 1 @@ -79,6 +89,19 @@ HTML %(

#{$2.strip}

) end end + + def version + ENV['RAILS_VERSION'] + end + + def api_link(url) + if version && !url.match(/v\d\.\d\.\d/) + url.insert(url.index('.org')+4, "/#{version}") + url.sub('http://edgeapi', 'http://api') if url.include?('edgeapi') + end + + url + end end end end diff --git a/guides/source/5_0_release_notes.md b/guides/source/5_0_release_notes.md index 24fb0ca6e1..e1b3b0a42e 100644 --- a/guides/source/5_0_release_notes.md +++ b/guides/source/5_0_release_notes.md @@ -150,7 +150,7 @@ The type of an attribute is given the opportunity to change how dirty tracking is performed. See its -[documentation](http://api.rubyonrails.org/classes/ActiveRecord/Attributes/ClassMethods.html) +[documentation](http://api.rubyonrails.org/v5.0.1/classes/ActiveRecord/Attributes/ClassMethods.html) for a detailed write up. -- cgit v1.2.3 From ea141d62dfbb8cb02f20137e75da0fa9977e84c8 Mon Sep 17 00:00:00 2001 From: Robin Dupret Date: Sun, 29 Jan 2017 13:16:10 +0100 Subject: 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] --- guides/rails_guides/markdown/renderer.rb | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'guides') 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+(.*?)\.?$} + %(

Defined in #{$1}.

) + elsif text =~ /^(TIP|IMPORTANT|CAUTION|WARNING|NOTE|INFO|TODO)[.:]/ convert_notes(text) elsif text.include?("DO NOT READ THIS FILE ON GITHUB") elsif text =~ /^\[(\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 -- cgit v1.2.3