diff --git a/Rakefile b/Rakefile
index 68f33b37..4860fa0f 100644
--- a/Rakefile
+++ b/Rakefile
@@ -54,6 +54,9 @@ class RailsTask < Rails::API::EdgeTask
def setup_horo_variables
super
+
+ ENV["HORO_BADGE_VERSION"] ||= "edge" if ENV["HORO_PROJECT_VERSION"]&.include?("@")
+
if ENV['NETLIFY']
ENV['HORO_CANONICAL_URL'] = ENV.fetch('DEPLOY_PRIME_URL', 'https://edgeapi.rubyonrails.org')
end
diff --git a/lib/rdoc/generator/template/rails/class.rhtml b/lib/rdoc/generator/template/rails/class.rhtml
index 1817b161..1b8e8e40 100644
--- a/lib/rdoc/generator/template/rails/class.rhtml
+++ b/lib/rdoc/generator/template/rails/class.rhtml
@@ -22,7 +22,7 @@
<% if project_name %>
<%= project_name %>
- <%= badge_version || project_version %>
+ <%= project_version %>
<% end %>
@@ -40,8 +40,8 @@
<% end %>
- <% if badge_version %>
- <%= badge_version %>
+ <% if project_version %>
+ <%= project_version %>
<% end %>
diff --git a/lib/rdoc/generator/template/rails/file.rhtml b/lib/rdoc/generator/template/rails/file.rhtml
index fbae35aa..9d1cb379 100644
--- a/lib/rdoc/generator/template/rails/file.rhtml
+++ b/lib/rdoc/generator/template/rails/file.rhtml
@@ -19,7 +19,7 @@
<% if project_name %>
<%= project_name %>
- <%= badge_version || project_version %>
+ <%= project_version %>
<% end %>
@@ -36,8 +36,8 @@
Last modified: <%= file.file_stat.mtime %>
- <% if badge_version %>
- <%= badge_version %>
+ <% if project_version %>
+ <%= project_version %>
<% end %>
diff --git a/lib/rdoc/generator/template/rails/index.rhtml b/lib/rdoc/generator/template/rails/index.rhtml
index e7400238..2845d3e7 100644
--- a/lib/rdoc/generator/template/rails/index.rhtml
+++ b/lib/rdoc/generator/template/rails/index.rhtml
@@ -17,7 +17,7 @@
<% if project_name %>
<%= project_name %>
- <%= badge_version || project_version %>
+ <%= project_version %>
<% end %>
@@ -28,8 +28,8 @@
<%= h index.relative_name %>
Last modified: <%= index.last_modified %>
- <% if badge_version %>
- <%= badge_version %>
+ <% if project_version %>
+ <%= project_version %>
<% end %>
diff --git a/lib/sdoc/generator.rb b/lib/sdoc/generator.rb
index ec4957fe..41b0cefd 100644
--- a/lib/sdoc/generator.rb
+++ b/lib/sdoc/generator.rb
@@ -72,7 +72,11 @@ def self.setup_options(options)
exit
end
- options.title = [ENV["HORO_PROJECT_NAME"], ENV["HORO_BADGE_VERSION"], "API documentation"].compact.join(" ")
+ options.title = [
+ ENV["HORO_PROJECT_NAME"],
+ ENV["HORO_BADGE_VERSION"] || ENV["HORO_PROJECT_VERSION"],
+ "API documentation"
+ ].compact.join(" ")
end
def initialize(store, options)
diff --git a/lib/sdoc/helpers.rb b/lib/sdoc/helpers.rb
index deabb903..84069f93 100644
--- a/lib/sdoc/helpers.rb
+++ b/lib/sdoc/helpers.rb
@@ -34,11 +34,8 @@ def project_name
end
def project_version
- h(ENV["HORO_PROJECT_VERSION"]) if ENV["HORO_PROJECT_VERSION"]
- end
-
- def badge_version
- h(ENV["HORO_BADGE_VERSION"]) if ENV["HORO_BADGE_VERSION"]
+ version = ENV["HORO_BADGE_VERSION"] || ENV["HORO_PROJECT_VERSION"]
+ h version if version
end
def project_git_head
@@ -50,7 +47,7 @@ def page_title(title = nil)
end
def og_title(title)
- project = [project_name, badge_version].join(" ").strip
+ project = [project_name, project_version].join(" ").strip
"#{h title}#{" (#{project})" unless project.empty?}"
end
diff --git a/lib/sdoc/postprocessor.rb b/lib/sdoc/postprocessor.rb
index 525257b6..336420d2 100644
--- a/lib/sdoc/postprocessor.rb
+++ b/lib/sdoc/postprocessor.rb
@@ -61,8 +61,8 @@ def version_url(url, version)
uri = URI(url)
unless uri.path.match?(%r"\A/v\d")
- if version.match?(/\A[.0-9]+\z/)
- uri.path = "/v#{version}#{uri.path}"
+ if version.match?(/\Av?[.0-9]+\z/)
+ uri.path = "/#{version.sub(/\Av?/, "v")}#{uri.path}"
else
uri.host = "edge#{uri.host}"
end
diff --git a/spec/helpers_spec.rb b/spec/helpers_spec.rb
index d3bab8d2..89cc1aa3 100644
--- a/spec/helpers_spec.rb
+++ b/spec/helpers_spec.rb
@@ -208,23 +208,15 @@ module Foo; module Bar; module Qux; end; end; end
end
end
- it "returns nil when ENV['HORO_PROJECT_VERSION'] is not set" do
- with_env("HORO_PROJECT_VERSION" => nil) do
- _(@helpers.project_version).must_be_nil
- end
- end
- end
-
- describe "#badge_version" do
- it "returns escaped version from ENV['HORO_BADGE_VERSION']" do
- with_env("HORO_BADGE_VERSION" => "~> 1.0.0") do
- _(@helpers.badge_version).must_equal "~> 1.0.0"
+ it "prioritizes ENV['HORO_BADGE_VERSION'] over ENV['HORO_PROJECT_VERSION']" do
+ with_env("HORO_BADGE_VERSION" => "badge", "HORO_PROJECT_VERSION" => "project") do
+ _(@helpers.project_version).must_equal "badge"
end
end
- it "returns nil when ENV['HORO_BADGE_VERSION'] is not set" do
- with_env("HORO_BADGE_VERSION" => nil) do
- _(@helpers.badge_version).must_be_nil
+ it "returns nil when neither ENV['HORO_BADGE_VERSION'] nor ENV['HORO_PROJECT_VERSION'] are set" do
+ with_env("HORO_BADGE_VERSION" => nil, "HORO_PROJECT_VERSION" => nil) do
+ _(@helpers.project_version).must_be_nil
end
end
end
@@ -265,26 +257,26 @@ module Foo; module Bar; module Qux; end; end; end
end
describe "#og_title" do
- it "includes ENV['HORO_PROJECT_NAME'] and ENV['HORO_BADGE_VERSION']" do
- with_env("HORO_PROJECT_NAME" => "My Gem", "HORO_BADGE_VERSION" => "v2.0") do
+ it "includes ENV['HORO_PROJECT_NAME'] and ENV['HORO_PROJECT_VERSION']" do
+ with_env("HORO_PROJECT_NAME" => "My Gem", "HORO_PROJECT_VERSION" => "v2.0") do
_(@helpers.og_title("Foo")).must_equal "Foo (My Gem v2.0)"
end
- with_env("HORO_PROJECT_NAME" => "My Gem", "HORO_BADGE_VERSION" => nil) do
+ with_env("HORO_PROJECT_NAME" => "My Gem", "HORO_PROJECT_VERSION" => nil) do
_(@helpers.og_title("Foo")).must_equal "Foo (My Gem)"
end
- with_env("HORO_PROJECT_NAME" => nil, "HORO_BADGE_VERSION" => "v2.0") do
+ with_env("HORO_PROJECT_NAME" => nil, "HORO_PROJECT_VERSION" => "v2.0") do
_(@helpers.og_title("Foo")).must_equal "Foo (v2.0)"
end
- with_env("HORO_PROJECT_NAME" => nil, "HORO_BADGE_VERSION" => nil) do
+ with_env("HORO_PROJECT_NAME" => nil, "HORO_PROJECT_VERSION" => nil) do
_(@helpers.og_title("Foo")).must_equal "Foo"
end
end
it "escapes the title" do
- with_env("HORO_PROJECT_NAME" => "Ruby & Rails", "HORO_BADGE_VERSION" => "~> 1.0.0") do
+ with_env("HORO_PROJECT_NAME" => "Ruby & Rails", "HORO_PROJECT_VERSION" => "~> 1.0.0") do
_(@helpers.og_title("Foo")).must_equal "Foo<Bar> (Ruby & Rails ~> 1.0.0)"
end
end
diff --git a/spec/postprocessor_spec.rb b/spec/postprocessor_spec.rb
index 5ba4bd16..fd4c1c39 100644
--- a/spec/postprocessor_spec.rb
+++ b/spec/postprocessor_spec.rb
@@ -34,19 +34,16 @@
Testing
HTML
- with_env("HORO_PROJECT_VERSION" => "3.2.1", "HORO_PROJECT_NAME" => "Ruby on Rails") do
- _(SDoc::Postprocessor.process(rendered)).
- must_include %(Testing)
- end
-
- with_env("HORO_PROJECT_VERSION" => "main@1337c0d3", "HORO_PROJECT_NAME" => "Ruby on Rails") do
- _(SDoc::Postprocessor.process(rendered)).
- must_include %(Testing)
- end
-
- with_env("HORO_PROJECT_VERSION" => nil, "HORO_PROJECT_NAME" => "Ruby on Rails") do
- _(SDoc::Postprocessor.process(rendered)).
- must_include %(Testing)
+ {
+ "3.2.1" => %(Testing),
+ "v3.2.1" => %(Testing),
+ "main@1337c0d3" => %(Testing),
+ "edge" => %(Testing),
+ nil => %(Testing),
+ }.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
diff --git a/spec/rdoc_generator_spec.rb b/spec/rdoc_generator_spec.rb
index 5fb35052..4769a767 100644
--- a/spec/rdoc_generator_spec.rb
+++ b/spec/rdoc_generator_spec.rb
@@ -46,24 +46,30 @@ def parse_options(*options)
end
describe "options.title" do
- it "includes ENV['HORO_PROJECT_NAME'] and ENV['HORO_BADGE_VERSION'] by default" do
- with_env("HORO_PROJECT_NAME" => "My Gem", "HORO_BADGE_VERSION" => "v2.0") do
+ it "includes ENV['HORO_PROJECT_NAME'] and ENV['HORO_PROJECT_VERSION'] by default" do
+ with_env("HORO_PROJECT_NAME" => "My Gem", "HORO_PROJECT_VERSION" => "v2.0") do
_(parse_options().title).must_equal "My Gem v2.0 API documentation"
end
- with_env("HORO_PROJECT_NAME" => "My Gem", "HORO_BADGE_VERSION" => nil) do
+ with_env("HORO_PROJECT_NAME" => "My Gem", "HORO_PROJECT_VERSION" => nil) do
_(parse_options().title).must_equal "My Gem API documentation"
end
- with_env("HORO_PROJECT_NAME" => nil, "HORO_BADGE_VERSION" => "v2.0") do
+ with_env("HORO_PROJECT_NAME" => nil, "HORO_PROJECT_VERSION" => "v2.0") do
_(parse_options().title).must_equal "v2.0 API documentation"
end
- with_env("HORO_PROJECT_NAME" => nil, "HORO_BADGE_VERSION" => nil) do
+ with_env("HORO_PROJECT_NAME" => nil, "HORO_PROJECT_VERSION" => nil) do
_(parse_options().title).must_equal "API documentation"
end
end
+ it "prioritizes ENV['HORO_BADGE_VERSION'] over ENV['HORO_PROJECT_VERSION']" do
+ with_env("HORO_BADGE_VERSION" => "badge", "HORO_PROJECT_VERSION" => "project") do
+ _(parse_options().title).must_equal "badge API documentation"
+ end
+ end
+
it "can be overridden" do
_(parse_options("--title", "Docs Docs Docs!").title).must_equal "Docs Docs Docs!"
end