Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions lib/rdoc/generator/template/rails/class.rhtml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<% if project_name %>
<div>
<%= project_name %>
<span title="<%= project_git_head %>"><%= badge_version || project_version %></span>
<span title="<%= project_git_head %>"><%= project_version %></span>
</div>
<% end %>

Expand All @@ -40,8 +40,8 @@
<% end %>
</h2>

<% if badge_version %>
<div id="version-badge"><%= badge_version %></div>
<% if project_version %>
<div id="version-badge"><%= project_version %></div>
<% end %>
</div>

Expand Down
6 changes: 3 additions & 3 deletions lib/rdoc/generator/template/rails/file.rhtml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<% if project_name %>
<div>
<%= project_name %>
<span title="<%= project_git_head %>"><%= badge_version || project_version %></span>
<span title="<%= project_git_head %>"><%= project_version %></span>
</div>
<% end %>

Expand All @@ -36,8 +36,8 @@
<li>Last modified: <%= file.file_stat.mtime %></li>
</ul>

<% if badge_version %>
<div id="version-badge"><%= badge_version %></div>
<% if project_version %>
<div id="version-badge"><%= project_version %></div>
<% end %>
</div>

Expand Down
6 changes: 3 additions & 3 deletions lib/rdoc/generator/template/rails/index.rhtml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<% if project_name %>
<div>
<%= project_name %>
<span title="<%= project_git_head %>"><%= badge_version || project_version %></span>
<span title="<%= project_git_head %>"><%= project_version %></span>
</div>
<% end %>

Expand All @@ -28,8 +28,8 @@
<li><%= h index.relative_name %></li>
<li>Last modified: <%= index.last_modified %></li>
</ul>
<% if badge_version %>
<div id="version-badge"><%= badge_version %></div>
<% if project_version %>
<div id="version-badge"><%= project_version %></div>
<% end %>
</div>

Expand Down
6 changes: 5 additions & 1 deletion lib/sdoc/generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
9 changes: 3 additions & 6 deletions lib/sdoc/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down
4 changes: 2 additions & 2 deletions lib/sdoc/postprocessor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
32 changes: 12 additions & 20 deletions spec/helpers_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 "~&gt; 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
Expand Down Expand Up @@ -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<Bar>")).must_equal "Foo&lt;Bar&gt; (Ruby &amp; Rails ~&gt; 1.0.0)"
end
end
Expand Down
23 changes: 10 additions & 13 deletions spec/postprocessor_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,16 @@
<a href="https://guides.rubyonrails.org/testing.html">Testing</a>
HTML

with_env("HORO_PROJECT_VERSION" => "3.2.1", "HORO_PROJECT_NAME" => "Ruby on Rails") do
_(SDoc::Postprocessor.process(rendered)).
must_include %(<a href="https://guides.rubyonrails.org/v3.2.1/testing.html">Testing</a>)
end

with_env("HORO_PROJECT_VERSION" => "main@1337c0d3", "HORO_PROJECT_NAME" => "Ruby on Rails") do
_(SDoc::Postprocessor.process(rendered)).
must_include %(<a href="https://edgeguides.rubyonrails.org/testing.html">Testing</a>)
end

with_env("HORO_PROJECT_VERSION" => nil, "HORO_PROJECT_NAME" => "Ruby on Rails") do
_(SDoc::Postprocessor.process(rendered)).
must_include %(<a href="https://guides.rubyonrails.org/testing.html">Testing</a>)
{
"3.2.1" => %(<a href="https://guides.rubyonrails.org/v3.2.1/testing.html">Testing</a>),
"v3.2.1" => %(<a href="https://guides.rubyonrails.org/v3.2.1/testing.html">Testing</a>),
"main@1337c0d3" => %(<a href="https://edgeguides.rubyonrails.org/testing.html">Testing</a>),
"edge" => %(<a href="https://edgeguides.rubyonrails.org/testing.html">Testing</a>),
nil => %(<a href="https://guides.rubyonrails.org/testing.html">Testing</a>),
}.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

Expand Down
16 changes: 11 additions & 5 deletions spec/rdoc_generator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down