Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use nil for index context #264

Merged
merged 1 commit into from
Jul 31, 2023
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
2 changes: 1 addition & 1 deletion lib/rdoc/generator/template/rails/index.rhtml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<meta charset="<%= @options.charset %>">
<title><%= page_title %></title>
<meta name="viewport" content="width=device-width,initial-scale=1">
<%= include_template '_head.rhtml', {:context => :index, tree_keys: []} %>
<%= include_template '_head.rhtml', {:context => nil, tree_keys: []} %>
</head>

<body>
Expand Down
16 changes: 3 additions & 13 deletions lib/sdoc/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,12 @@ def link_to_external(text, url, html_attributes = {})
end

def base_tag_for_context(context)
if context == :index
%(<base href="./" data-current-path=".">)
else
relative_root = "../" * context.path.count("/")
%(<base href="#{relative_root}" data-current-path="#{context.path}">)
end
relative_root = "../" * context.path.count("/") if context
%(<base href="./#{relative_root}" data-current-path="#{context&.path}">)
end

def canonical_url(context)
if ENV["HORO_CANONICAL_URL"]
if context == :index
"#{ENV["HORO_CANONICAL_URL"]}/"
else
"#{ENV["HORO_CANONICAL_URL"]}/#{context.as_href("")}"
end
end
"#{ENV["HORO_CANONICAL_URL"]}/#{context&.path}" if ENV["HORO_CANONICAL_URL"]
end

def project_name
Expand Down
18 changes: 9 additions & 9 deletions spec/helpers_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,9 @@ module Foo; class Bar; def qux; end; end; end
end

describe "#base_tag_for_context" do
it "returns an idempotent <base> tag for the :index context" do
_(@helpers.base_tag_for_context(:index)).
must_equal %(<base href="./" data-current-path=".">)
it "returns an idempotent <base> tag for nil context" do
_(@helpers.base_tag_for_context(nil)).
must_equal %(<base href="./" data-current-path="">)
end

it "returns a <base> tag with an appropriate path for the given RDoc::Context" do
Expand All @@ -146,13 +146,13 @@ module Foo; module Bar; module Qux; end; end; end
RUBY

_(@helpers.base_tag_for_context(top_level.find_module_named("Foo"))).
must_equal %(<base href="../" data-current-path="classes/Foo.html">)
must_equal %(<base href="./../" data-current-path="classes/Foo.html">)

_(@helpers.base_tag_for_context(top_level.find_module_named("Foo::Bar"))).
must_equal %(<base href="../../" data-current-path="classes/Foo/Bar.html">)
must_equal %(<base href="./../../" data-current-path="classes/Foo/Bar.html">)

_(@helpers.base_tag_for_context(top_level.find_module_named("Foo::Bar::Qux"))).
must_equal %(<base href="../../../" data-current-path="classes/Foo/Bar/Qux.html">)
must_equal %(<base href="./../../../" data-current-path="classes/Foo/Bar/Qux.html">)
end
end

Expand All @@ -167,15 +167,15 @@ module Foo; module Bar; module Qux; end; end; end
end
end

it "returns a URL based on ENV['HORO_CANONICAL_URL'] for the :index context" do
it "returns a URL based on ENV['HORO_CANONICAL_URL'] for nil context" do
with_env("HORO_CANONICAL_URL" => "https://canonical") do
_(@helpers.canonical_url(:index)).must_equal "https://canonical/"
_(@helpers.canonical_url(nil)).must_equal "https://canonical/"
end
end

it "returns nil when ENV['HORO_CANONICAL_URL'] is not set" do
with_env("HORO_CANONICAL_URL" => nil) do
_(@helpers.canonical_url(:index)).must_be_nil
_(@helpers.canonical_url(nil)).must_be_nil
end
end
end
Expand Down