Skip to content

Commit

Permalink
Fix broken links to assets. Fixes #359.
Browse files Browse the repository at this point in the history
  • Loading branch information
awood committed Aug 3, 2015
1 parent 1a3dd5d commit 4d81a1e
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 18 deletions.
2 changes: 1 addition & 1 deletion lib/rdoc/generator/template/darkfish/_head.rhtml
Expand Up @@ -3,7 +3,7 @@
<title><%= h @title %></title>

<script type="text/javascript">
var rdoc_rel_prefix = "<%= rel_prefix %>/";
var rdoc_rel_prefix = "<%= asset_rel_prefix %>/";
</script>

<script src="<%= asset_rel_prefix %>/js/jquery.js"></script>
Expand Down
12 changes: 6 additions & 6 deletions lib/rdoc/generator/template/darkfish/css/fonts.css
Expand Up @@ -17,7 +17,7 @@
font-weight: 400;
src: local("Source Code Pro"),
local("SourceCodePro-Regular"),
url("fonts/SourceCodePro-Regular.ttf") format("truetype");
url("../fonts/SourceCodePro-Regular.ttf") format("truetype");
}

@font-face {
Expand All @@ -26,7 +26,7 @@
font-weight: 700;
src: local("Source Code Pro Bold"),
local("SourceCodePro-Bold"),
url("fonts/SourceCodePro-Bold.ttf") format("truetype");
url("../fonts/SourceCodePro-Bold.ttf") format("truetype");
}

/*
Expand All @@ -46,7 +46,7 @@
font-weight: 300;
src: local("Lato Light"),
local("Lato-Light"),
url("fonts/Lato-Light.ttf") format("truetype");
url("../fonts/Lato-Light.ttf") format("truetype");
}

@font-face {
Expand All @@ -55,7 +55,7 @@
font-weight: 300;
src: local("Lato Light Italic"),
local("Lato-LightItalic"),
url("fonts/Lato-LightItalic.ttf") format("truetype");
url("../fonts/Lato-LightItalic.ttf") format("truetype");
}

@font-face {
Expand All @@ -64,7 +64,7 @@
font-weight: 700;
src: local("Lato Regular"),
local("Lato-Regular"),
url("fonts/Lato-Regular.ttf") format("truetype");
url("../fonts/Lato-Regular.ttf") format("truetype");
}

@font-face {
Expand All @@ -73,7 +73,7 @@
font-weight: 700;
src: local("Lato Italic"),
local("Lato-Italic"),
url("fonts/Lato-RegularItalic.ttf") format("truetype");
url("../fonts/Lato-RegularItalic.ttf") format("truetype");
}

/*
Expand Down
6 changes: 3 additions & 3 deletions lib/rdoc/servlet.rb
Expand Up @@ -114,8 +114,8 @@ def do_GET req, res
case req.path
when '/' then
root req, res
when '/rdoc.css', '/js/darkfish.js', '/js/jquery.js', '/js/search.js',
%r%^/images/% then
when '/js/darkfish.js', '/js/jquery.js', '/js/search.js',
%r%^/css/%, %r%^/images/%, %r%^/fonts/% then
asset :darkfish, req, res
when '/js/navigation.js', '/js/searcher.js' then
asset :json_index, req, res
Expand Down Expand Up @@ -202,7 +202,7 @@ def error exception, req, res
<title>Error - #{ERB::Util.html_escape exception.class}</title>
<link type="text/css" media="screen" href="#{@mount_path}/rdoc.css" rel="stylesheet">
<link type="text/css" media="screen" href="#{@mount_path}/css/rdoc.css" rel="stylesheet">
</head>
<body>
<h1>Error</h1>
Expand Down
19 changes: 11 additions & 8 deletions test/test_rdoc_servlet.rb
Expand Up @@ -65,14 +65,15 @@ def teardown

def test_asset
temp_dir do
now = Time.now
FileUtils.mkdir 'css'

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

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

@req.path = 'rdoc.css'
@req.path = '/css/rdoc.css'

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

Expand All @@ -94,11 +95,12 @@ def test_do_GET

def test_do_GET_asset_darkfish
temp_dir do
FileUtils.touch 'rdoc.css'
FileUtils.mkdir 'css'
FileUtils.touch 'css/rdoc.css'

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

@req.path = '/rdoc.css'
@req.path = '/css/rdoc.css'

@s.do_GET @req, @res

Expand Down Expand Up @@ -135,11 +137,12 @@ def test_do_GET_mount_path
@s = RDoc::Servlet.new @server, @stores, @cache, '/mount/path'

temp_dir do
FileUtils.touch 'rdoc.css'
FileUtils.mkdir 'css'
FileUtils.touch 'css/rdoc.css'

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

@req.path = '/mount/path/rdoc.css'
@req.path = '/mount/path/css/rdoc.css'

@s.do_GET @req, @res

Expand Down

0 comments on commit 4d81a1e

Please sign in to comment.