Skip to content

Commit 13be7a5

Browse files
committed
Fix relative path location, allow generators to override path locations
1 parent 9ac6aa5 commit 13be7a5

File tree

4 files changed

+85
-4
lines changed

4 files changed

+85
-4
lines changed

History.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
* Y Minor Enhancements
1313
* Added a space after the commas in ri class method lists. RubyForge
1414
enhancement #22182.
15+
* Generators can now override generated file locations.
1516
* Converted to minitest.
1617

1718
* Z Bug Fixes
@@ -22,6 +23,7 @@
2223
Patterson.
2324
* When merging ri data with a nonexistant directory, RDoc no longer crashes.
2425
* Fix visibility of methods in XML output. Issue by Yehuda Katz.
26+
* Fixed relative link generation.
2527

2628
=== 2.2.1 / 2008-09-24
2729
This version provides some minor fixes and enhancements to 2.2.0 intended

lib/rdoc/generator.rb

Lines changed: 67 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -133,14 +133,26 @@ def self.build_indices(toplevels, options, template_cache = nil)
133133
classes = []
134134
template_cache ||= RDoc::Cache.instance
135135

136+
file_dir = if defined? options.generator::FILE_DIR then
137+
options.generator::FILE_DIR
138+
else
139+
RDoc::Generator::FILE_DIR
140+
end
141+
136142
toplevels.each do |toplevel|
137143
files << RDoc::Generator::File.new(template_cache, toplevel, options,
138-
RDoc::Generator::FILE_DIR)
144+
file_dir)
139145
end
140146

147+
class_dir = if defined? options.generator::CLASS_DIR then
148+
options.generator::CLASS_DIR
149+
else
150+
RDoc::Generator::CLASS_DIR
151+
end
152+
141153
RDoc::TopLevel.all_classes_and_modules.each do |cls|
142154
build_class_list(template_cache, classes, options, cls, files[0],
143-
RDoc::Generator::CLASS_DIR)
155+
class_dir)
144156
end
145157

146158
return files, classes
@@ -517,7 +529,9 @@ def http_url(full_name, prefix)
517529

518530
path.gsub!(/<<\s*(\w*)/, 'from-\1') if path['<<']
519531

520-
::File.join(prefix, path.split("::")) + ".html"
532+
path = [prefix] + path.split('::')
533+
534+
::File.join(*path.compact) + ".html"
521535
end
522536

523537
def name
@@ -670,6 +684,32 @@ def <=>(other)
670684
self.name <=> other.name
671685
end
672686

687+
def inspect
688+
"#<#{self.class} name: #{name} path: #{@path}>"
689+
end
690+
691+
def pretty_print(q)
692+
q.group 1, "#<#{self.class} ", '>' do
693+
q.text 'name: '
694+
q.pp name
695+
q.text ','
696+
q.breakable
697+
698+
q.text 'path: '
699+
q.pp @path
700+
q.text ','
701+
q.breakable
702+
703+
q.text 'values: '
704+
q.pp @values
705+
q.text ','
706+
q.breakable
707+
708+
q.text 'methods: '
709+
q.pp @methods
710+
end
711+
end
712+
673713
end
674714

675715
##
@@ -704,7 +744,9 @@ def initialize(template_cache, context, options, file_dir)
704744
end
705745

706746
def http_url(file_dir)
707-
::File.join file_dir, "#{@context.file_relative_name.tr '.', '_'}.html"
747+
path = [file_dir, "#{@context.file_relative_name.tr '.', '_'}.html"]
748+
749+
::File.join path.compact
708750
end
709751

710752
def filename_to_label
@@ -811,6 +853,27 @@ def <=>(other)
811853
self.name <=> other.name
812854
end
813855

856+
def inspect
857+
"#<#{self.class} name: #{@name} path: #{@path}>"
858+
end
859+
860+
def pretty_print(q)
861+
q.group 1, "#<#{self.class} ", '>' do
862+
q.text 'name: '
863+
q.pp @name
864+
q.text ','
865+
q.breakable
866+
867+
q.text 'path: '
868+
q.pp @path
869+
q.text ','
870+
q.breakable
871+
872+
q.text 'values: '
873+
q.pp @values
874+
end
875+
end
876+
814877
end
815878

816879
class Method

lib/rdoc/markup/to_html.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ def self.gen_relative_url(path, target)
4444
from = from.split "/"
4545
to = to.split "/"
4646

47+
from.delete '.'
48+
to.delete '.'
49+
4750
while from.size > 0 and to.size > 0 and from[0] == to[0] do
4851
from.shift
4952
to.shift

test/test_rdoc_markup_to_html.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,19 @@ def setup
1010
@th = RDoc::Markup::ToHtml.new
1111
end
1212

13+
def test_class_gen_relative_url
14+
def gen(from, to)
15+
RDoc::Markup::ToHtml.gen_relative_url from, to
16+
end
17+
18+
assert_equal 'a.html', gen('a.html', 'a.html')
19+
assert_equal 'b.html', gen('a.html', 'b.html')
20+
21+
assert_equal 'd.html', gen('a/c.html', 'a/d.html')
22+
assert_equal '../a.html', gen('a/c.html', 'a.html')
23+
assert_equal 'a/c.html', gen('a.html', 'a/c.html')
24+
end
25+
1326
def test_tt_formatting
1427
assert_equal "<p>\n<tt>--</tt> &#8212; <tt>cats'</tt> cats&#8217;\n</p>\n",
1528
util_format("<tt>--</tt> -- <tt>cats'</tt> cats'")

0 commit comments

Comments
 (0)