aboutsummaryrefslogtreecommitdiffstats
path: root/guides/rails_guides/markdown/renderer.rb
diff options
context:
space:
mode:
Diffstat (limited to 'guides/rails_guides/markdown/renderer.rb')
-rw-r--r--guides/rails_guides/markdown/renderer.rb23
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