diff options
author | Robin Dupret <robin.dupret@gmail.com> | 2016-11-30 19:27:35 +0100 |
---|---|---|
committer | Robin Dupret <robin.dupret@gmail.com> | 2017-02-07 18:56:43 +0100 |
commit | 0676d28b2222eae21bbd43c721f0ec229385865a (patch) | |
tree | 1da80ad3c247c71e245769ef6dfc622e4f516b70 /guides/rails_guides/markdown | |
parent | 6a1c0218df1fcffaac97e7288db07934bfef277f (diff) | |
download | rails-0676d28b2222eae21bbd43c721f0ec229385865a.tar.gz rails-0676d28b2222eae21bbd43c721f0ec229385865a.tar.bz2 rails-0676d28b2222eae21bbd43c721f0ec229385865a.zip |
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.
Diffstat (limited to 'guides/rails_guides/markdown')
-rw-r--r-- | guides/rails_guides/markdown/renderer.rb | 23 |
1 files changed, 23 insertions, 0 deletions
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') + %(<a href="#{api_link(url)}">#{content}</a>) + elsif title + %(<a href="#{url}" title="#{title}">#{content}</a>) + else + %(<a href="#{url}">#{content}</a>) + 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 %(<div class="#{css_class}"><p>#{$2.strip}</p></div>) 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 |