Blob Blame History Raw
From 4d81a1eb22b51eef485420be897bbea937d37f28 Mon Sep 17 00:00:00 2001
From: Alex Wood <awood@redhat.com>
Date: Mon, 3 Aug 2015 15:39:53 -0400
Subject: [PATCH 1/2] Fix broken links to assets.  Fixes #359.

---
 lib/rdoc/generator/template/darkfish/_head.rhtml   |  2 +-
 lib/rdoc/generator/template/darkfish/css/fonts.css | 12 ++++++------
 lib/rdoc/servlet.rb                                |  6 +++---
 test/test_rdoc_servlet.rb                          | 19 +++++++++++--------
 4 files changed, 21 insertions(+), 18 deletions(-)

diff --git a/lib/rdoc/generator/template/darkfish/_head.rhtml b/lib/rdoc/generator/template/darkfish/_head.rhtml
index 70f1c18..2a1d0b8 100644
--- a/lib/rdoc/generator/template/darkfish/_head.rhtml
+++ b/lib/rdoc/generator/template/darkfish/_head.rhtml
@@ -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>
diff --git a/lib/rdoc/generator/template/darkfish/css/fonts.css b/lib/rdoc/generator/template/darkfish/css/fonts.css
index e9e7211..57302b5 100644
--- a/lib/rdoc/generator/template/darkfish/css/fonts.css
+++ b/lib/rdoc/generator/template/darkfish/css/fonts.css
@@ -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 {
@@ -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");
 }
 
 /*
@@ -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 {
@@ -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 {
@@ -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 {
@@ -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");
 }
 
 /*
diff --git a/lib/rdoc/servlet.rb b/lib/rdoc/servlet.rb
index ec8fd73..94c3d39 100644
--- a/lib/rdoc/servlet.rb
+++ b/lib/rdoc/servlet.rb
@@ -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
@@ -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>
diff --git a/test/test_rdoc_servlet.rb b/test/test_rdoc_servlet.rb
index 143e2f2..acd37cf 100644
--- a/test/test_rdoc_servlet.rb
+++ b/test/test_rdoc_servlet.rb
@@ -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
 
@@ -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
 
@@ -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
 

From cfde4f9891764439d747fb646686e76adaf4f2e4 Mon Sep 17 00:00:00 2001
From: Alex Wood <awood@redhat.com>
Date: Mon, 17 Aug 2015 11:13:55 -0400
Subject: [PATCH 2/2] Use gem search index instead of global index.

---
 lib/rdoc/generator/template/darkfish/_head.rhtml    |  1 +
 lib/rdoc/generator/template/darkfish/js/darkfish.js | 14 +++++++-------
 2 files changed, 8 insertions(+), 7 deletions(-)

diff --git a/lib/rdoc/generator/template/darkfish/_head.rhtml b/lib/rdoc/generator/template/darkfish/_head.rhtml
index 2a1d0b8..f308526 100644
--- a/lib/rdoc/generator/template/darkfish/_head.rhtml
+++ b/lib/rdoc/generator/template/darkfish/_head.rhtml
@@ -4,6 +4,7 @@
 
 <script type="text/javascript">
   var rdoc_rel_prefix = "<%= asset_rel_prefix %>/";
+  var index_rel_prefix = "<%= rel_prefix %>/";
 </script>
 
 <script src="<%= asset_rel_prefix %>/js/jquery.js"></script>
diff --git a/lib/rdoc/generator/template/darkfish/js/darkfish.js b/lib/rdoc/generator/template/darkfish/js/darkfish.js
index b789a65..38f877e 100644
--- a/lib/rdoc/generator/template/darkfish/js/darkfish.js
+++ b/lib/rdoc/generator/template/darkfish/js/darkfish.js
@@ -59,7 +59,7 @@ function hookSearch() {
     var html = '';
 
     // TODO add relative path to <script> per-page
-    html += '<p class="search-match"><a href="' + rdoc_rel_prefix + result.path + '">' + this.hlt(result.title);
+    html += '<p class="search-match"><a href="' + index_rel_prefix + result.path + '">' + this.hlt(result.title);
     if (result.params)
       html += '<span class="params">' + result.params + '</span>';
     html += '</a>';
@@ -121,9 +121,9 @@ function highlightClickTarget( event ) {
   };
 };
 
-function loadAsync(path, success) {
+function loadAsync(path, success, prefix) {
   $.ajax({
-    url: rdoc_rel_prefix + path,
+    url: prefix + path,
     dataType: 'script',
     success: success,
     cache: true
@@ -154,8 +154,8 @@ $(document).ready( function() {
     });
   }
 
-  loadAsync('js/navigation.js',   search_success_function('navigation_loaded'));
-  loadAsync('js/search.js',       search_success_function('search_loaded'));
-  loadAsync('js/search_index.js', search_success_function('search_index_loaded'));
-  loadAsync('js/searcher.js',     search_success_function('searcher_loaded'));
+  loadAsync('js/navigation.js',   search_success_function('navigation_loaded'), rdoc_rel_prefix);
+  loadAsync('js/search.js',       search_success_function('search_loaded'), rdoc_rel_prefix);
+  loadAsync('js/search_index.js', search_success_function('search_index_loaded'), index_rel_prefix);
+  loadAsync('js/searcher.js',     search_success_function('searcher_loaded'), rdoc_rel_prefix);
 });