Skip to content

Commit deb68c8

Browse files
author
Zachary Scott
committed
Merge pull request #360 from awood/master
Fix broken links to assets. Fixes #359.
2 parents 23efe97 + cfde4f9 commit deb68c8

File tree

5 files changed

+29
-25
lines changed

5 files changed

+29
-25
lines changed

lib/rdoc/generator/template/darkfish/_head.rhtml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
<title><%= h @title %></title>
44

55
<script type="text/javascript">
6-
var rdoc_rel_prefix = "<%= rel_prefix %>/";
6+
var rdoc_rel_prefix = "<%= asset_rel_prefix %>/";
7+
var index_rel_prefix = "<%= rel_prefix %>/";
78
</script>
89

910
<script src="<%= asset_rel_prefix %>/js/jquery.js"></script>

lib/rdoc/generator/template/darkfish/css/fonts.css

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
font-weight: 400;
1818
src: local("Source Code Pro"),
1919
local("SourceCodePro-Regular"),
20-
url("fonts/SourceCodePro-Regular.ttf") format("truetype");
20+
url("../fonts/SourceCodePro-Regular.ttf") format("truetype");
2121
}
2222

2323
@font-face {
@@ -26,7 +26,7 @@
2626
font-weight: 700;
2727
src: local("Source Code Pro Bold"),
2828
local("SourceCodePro-Bold"),
29-
url("fonts/SourceCodePro-Bold.ttf") format("truetype");
29+
url("../fonts/SourceCodePro-Bold.ttf") format("truetype");
3030
}
3131

3232
/*
@@ -46,7 +46,7 @@
4646
font-weight: 300;
4747
src: local("Lato Light"),
4848
local("Lato-Light"),
49-
url("fonts/Lato-Light.ttf") format("truetype");
49+
url("../fonts/Lato-Light.ttf") format("truetype");
5050
}
5151

5252
@font-face {
@@ -55,7 +55,7 @@
5555
font-weight: 300;
5656
src: local("Lato Light Italic"),
5757
local("Lato-LightItalic"),
58-
url("fonts/Lato-LightItalic.ttf") format("truetype");
58+
url("../fonts/Lato-LightItalic.ttf") format("truetype");
5959
}
6060

6161
@font-face {
@@ -64,7 +64,7 @@
6464
font-weight: 700;
6565
src: local("Lato Regular"),
6666
local("Lato-Regular"),
67-
url("fonts/Lato-Regular.ttf") format("truetype");
67+
url("../fonts/Lato-Regular.ttf") format("truetype");
6868
}
6969

7070
@font-face {
@@ -73,7 +73,7 @@
7373
font-weight: 700;
7474
src: local("Lato Italic"),
7575
local("Lato-Italic"),
76-
url("fonts/Lato-RegularItalic.ttf") format("truetype");
76+
url("../fonts/Lato-RegularItalic.ttf") format("truetype");
7777
}
7878

7979
/*

lib/rdoc/generator/template/darkfish/js/darkfish.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ function hookSearch() {
5959
var html = '';
6060

6161
// TODO add relative path to <script> per-page
62-
html += '<p class="search-match"><a href="' + rdoc_rel_prefix + result.path + '">' + this.hlt(result.title);
62+
html += '<p class="search-match"><a href="' + index_rel_prefix + result.path + '">' + this.hlt(result.title);
6363
if (result.params)
6464
html += '<span class="params">' + result.params + '</span>';
6565
html += '</a>';
@@ -121,9 +121,9 @@ function highlightClickTarget( event ) {
121121
};
122122
};
123123

124-
function loadAsync(path, success) {
124+
function loadAsync(path, success, prefix) {
125125
$.ajax({
126-
url: rdoc_rel_prefix + path,
126+
url: prefix + path,
127127
dataType: 'script',
128128
success: success,
129129
cache: true
@@ -154,8 +154,8 @@ $(document).ready( function() {
154154
});
155155
}
156156

157-
loadAsync('js/navigation.js', search_success_function('navigation_loaded'));
158-
loadAsync('js/search.js', search_success_function('search_loaded'));
159-
loadAsync('js/search_index.js', search_success_function('search_index_loaded'));
160-
loadAsync('js/searcher.js', search_success_function('searcher_loaded'));
157+
loadAsync('js/navigation.js', search_success_function('navigation_loaded'), rdoc_rel_prefix);
158+
loadAsync('js/search.js', search_success_function('search_loaded'), rdoc_rel_prefix);
159+
loadAsync('js/search_index.js', search_success_function('search_index_loaded'), index_rel_prefix);
160+
loadAsync('js/searcher.js', search_success_function('searcher_loaded'), rdoc_rel_prefix);
161161
});

lib/rdoc/servlet.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,8 @@ def do_GET req, res
116116
case req.path
117117
when '/' then
118118
root req, res
119-
when '/rdoc.css', '/js/darkfish.js', '/js/jquery.js', '/js/search.js',
120-
%r%^/images/% then
119+
when '/js/darkfish.js', '/js/jquery.js', '/js/search.js',
120+
%r%^/css/%, %r%^/images/%, %r%^/fonts/% then
121121
asset :darkfish, req, res
122122
when '/js/navigation.js', '/js/searcher.js' then
123123
asset :json_index, req, res
@@ -204,7 +204,7 @@ def error exception, req, res
204204
205205
<title>Error - #{ERB::Util.html_escape exception.class}</title>
206206
207-
<link type="text/css" media="screen" href="#{@mount_path}/rdoc.css" rel="stylesheet">
207+
<link type="text/css" media="screen" href="#{@mount_path}/css/rdoc.css" rel="stylesheet">
208208
</head>
209209
<body>
210210
<h1>Error</h1>

test/test_rdoc_servlet.rb

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -66,14 +66,15 @@ def teardown
6666

6767
def test_asset
6868
temp_dir do
69-
now = Time.now
69+
FileUtils.mkdir 'css'
7070

71-
open 'rdoc.css', 'w' do |io| io.write 'h1 { color: red }' end
72-
File.utime now, now, 'rdoc.css'
71+
now = Time.now
72+
open 'css/rdoc.css', 'w' do |io| io.write 'h1 { color: red }' end
73+
File.utime now, now, 'css/rdoc.css'
7374

7475
@s.asset_dirs[:darkfish] = '.'
7576

76-
@req.path = 'rdoc.css'
77+
@req.path = '/css/rdoc.css'
7778

7879
@s.asset :darkfish, @req, @res
7980

@@ -95,11 +96,12 @@ def test_do_GET
9596

9697
def test_do_GET_asset_darkfish
9798
temp_dir do
98-
FileUtils.touch 'rdoc.css'
99+
FileUtils.mkdir 'css'
100+
FileUtils.touch 'css/rdoc.css'
99101

100102
@s.asset_dirs[:darkfish] = '.'
101103

102-
@req.path = '/rdoc.css'
104+
@req.path = '/css/rdoc.css'
103105

104106
@s.do_GET @req, @res
105107

@@ -136,11 +138,12 @@ def test_do_GET_mount_path
136138
@s = RDoc::Servlet.new @server, @stores, @cache, '/mount/path'
137139

138140
temp_dir do
139-
FileUtils.touch 'rdoc.css'
141+
FileUtils.mkdir 'css'
142+
FileUtils.touch 'css/rdoc.css'
140143

141144
@s.asset_dirs[:darkfish] = '.'
142145

143-
@req.path = '/mount/path/rdoc.css'
146+
@req.path = '/mount/path/css/rdoc.css'
144147

145148
@s.do_GET @req, @res
146149

0 commit comments

Comments
 (0)