diff --git a/lib/sdoc/postprocessor.rb b/lib/sdoc/postprocessor.rb
index d9630f09..8ba39094 100644
--- a/lib/sdoc/postprocessor.rb
+++ b/lib/sdoc/postprocessor.rb
@@ -10,7 +10,7 @@ def process(rendered)
document = Nokogiri::HTML5.parse(rendered)
rebase_urls!(document)
- version_rails_guides_urls!(document)
+ version_rubyonrails_urls!(document)
add_ref_link_classes!(document)
unify_h1_headings!(document)
highlight_code_blocks!(document)
@@ -49,9 +49,12 @@ def rebase_url(url, current_path)
end
end
- def version_rails_guides_urls!(document)
+ def version_rubyonrails_urls!(document)
if ENV["HORO_PROJECT_NAME"] == "Ruby on Rails" && version = ENV["HORO_PROJECT_VERSION"]
- document.css("a[href^='https://guides.rubyonrails.org/']").each do |element|
+ document.css(
+ "a[href^='https://api.rubyonrails.org/']",
+ "a[href^='https://guides.rubyonrails.org/']"
+ ).each do |element|
element["href"] = version_url(element["href"], version)
end
end
diff --git a/spec/postprocessor_spec.rb b/spec/postprocessor_spec.rb
index d29b9e27..c481e3e8 100644
--- a/spec/postprocessor_spec.rb
+++ b/spec/postprocessor_spec.rb
@@ -29,6 +29,24 @@
_(postprocessed).must_include expected_body
end
+ it "versions Rails API Docs URLs based on ENV['HORO_PROJECT_VERSION']" do
+ rendered = <<~HTML
+ Learn more
+ HTML
+
+ {
+ "3.2.1" => %(Learn more),
+ "v3.2.1" => %(Learn more),
+ "main@1337c0d3" => %(Learn more),
+ "edge" => %(Learn more),
+ nil => %(Learn more),
+ }.each do |version, expected|
+ with_env("HORO_PROJECT_VERSION" => version, "HORO_PROJECT_NAME" => "Ruby on Rails") do
+ _(SDoc::Postprocessor.process(rendered)).must_include expected
+ end
+ end
+ end
+
it "versions Rails guides URLs based on ENV['HORO_PROJECT_VERSION']" do
rendered = <<~HTML
Testing
@@ -47,14 +65,16 @@
end
end
- it "does not version Rails guides URLs when ENV['HORO_PROJECT_NAME'] is not Ruby on Rails" do
+ it "does not version rubyonrails.org URLs when ENV['HORO_PROJECT_NAME'] is not Ruby on Rails" do
rendered = <<~HTML
+ Learn more
Testing
HTML
with_env("HORO_PROJECT_VERSION" => "3.2.1", "HORO_PROJECT_NAME" => "My Rails Gem") do
- _(SDoc::Postprocessor.process(rendered)).
- must_include %(Testing)
+ postprocessed = _(SDoc::Postprocessor.process(rendered))
+ postprocessed.must_include %(Learn more)
+ postprocessed.must_include %(Testing)
end
end