Skip to content

Commit 1575e97

Browse files
Merge pull request #285 from jonathanhefner/main-page-fix-ref-links
Fix ref links in main page
2 parents b9786d4 + d0ce1ca commit 1575e97

File tree

5 files changed

+29
-12
lines changed

5 files changed

+29
-12
lines changed

lib/rdoc/generator/template/rails/index.rhtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<meta charset="<%= @options.charset %>">
55
<title><%= page_title %></title>
66
<meta name="viewport" content="width=device-width,initial-scale=1">
7-
<%= include_template '_head.rhtml', {:context => nil, tree_keys: []} %>
7+
<%= include_template '_head.rhtml', {:context => index, tree_keys: []} %>
88
</head>
99

1010
<body>

lib/sdoc/generator.rb

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,14 @@
88
require 'sdoc/version'
99
require 'rdoc'
1010

11+
RDoc::TopLevel.prepend(Module.new do
12+
attr_writer :path
13+
14+
def path
15+
@path ||= super
16+
end
17+
end)
18+
1119
class RDoc::ClassModule
1220
def with_documentation?
1321
document_self_or_methods || classes_and_modules.any?{ |c| c.with_documentation? }
@@ -122,10 +130,16 @@ def file_dir
122130

123131
### Determines index page based on @options.main_page (or lack thereof)
124132
def index
125-
path = @original_dir.join(@options.main_page || @options.files.first || "")
126-
file = @files.find { |file| @options.root.join(file.full_name) == path }
127-
raise "Could not find main page #{path.to_s.inspect} among rendered files" if !file
128-
file
133+
@index ||= begin
134+
path = @original_dir.join(@options.main_page || @options.files.first || "")
135+
file = @files.find { |file| @options.root.join(file.full_name) == path }
136+
raise "Could not find main page #{path.to_s.inspect} among rendered files" if !file
137+
138+
file = file.dup
139+
file.path = ""
140+
141+
file
142+
end
129143
end
130144

131145
protected

lib/sdoc/helpers.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ def full_name(named)
3636
end
3737

3838
def base_tag_for_context(context)
39-
relative_root = "../" * context.path.count("/") if context
40-
%(<base href="./#{relative_root}" data-current-path="#{context&.path}">)
39+
relative_root = "../" * context.path.count("/")
40+
%(<base href="./#{relative_root}" data-current-path="#{context.path}">)
4141
end
4242

4343
def canonical_url(path = nil)

spec/helpers_spec.rb

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -196,11 +196,6 @@ module Foo; module Bar; class Qux; end; end; end
196196
end
197197

198198
describe "#base_tag_for_context" do
199-
it "returns an idempotent <base> tag for nil context" do
200-
_(@helpers.base_tag_for_context(nil)).
201-
must_equal %(<base href="./" data-current-path="">)
202-
end
203-
204199
it "returns a <base> tag with an appropriate path for the given RDoc::Context" do
205200
top_level = rdoc_top_level_for <<~RUBY
206201
module Foo; module Bar; module Qux; end; end; end

spec/rdoc_generator_spec.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,5 +123,13 @@ def parse_options(*options)
123123
sdoc = rdoc_dry_run("--main", @files.first, "--files", *@files).generator
124124
_(sdoc.index.absolute_name).must_equal @files.first
125125
end
126+
127+
it "overrides RDoc::TopLevel#path" do
128+
Dir.chdir(@dir) do
129+
sdoc = rdoc_dry_run("--files", *@files).generator
130+
_(sdoc.index.path).must_equal ""
131+
sdoc.store.all_files.each { |file| _(file.path).wont_equal "" }
132+
end
133+
end
126134
end
127135
end

0 commit comments

Comments
 (0)