Refactor page url generation.

Avoid appending './' to urls.
This commit is contained in:
bootstraponline
2012-07-27 14:45:40 -06:00
parent 8fcef5401b
commit 96842d9742
4 changed files with 11 additions and 5 deletions
+8 -2
View File
@@ -15,7 +15,7 @@ module Gollum
def new_page page def new_page page
name = page.name name = page.name
url = ::File.join(::File.dirname(page.path), page.filename_stripped) url = url_for_page page
%Q( <li class="file"><a href="#{url}">#{name}</a></li>\n) %Q( <li class="file"><a href="#{url}">#{name}</a></li>\n)
end end
@@ -38,6 +38,12 @@ module Gollum
HTML HTML
end end
def url_for_page page
url = ::File.join(::File.dirname(page.path), page.filename_stripped)
url = url[2..-1] if url[0,2] == './'
url
end
def render_files def render_files
html = '' html = ''
count = @pages.size count = @pages.size
@@ -65,7 +71,7 @@ module Gollum
if (count - folder_start == 1) if (count - folder_start == 1)
page = @pages[ folder_start ] page = @pages[ folder_start ]
name = page.name name = page.name
url = ::File.join(::File.dirname(page.path), page.filename_stripped) url = url_for_page page
html += <<-HTML html += <<-HTML
<li> <li>
<label>#{::File.dirname(page.path)}</label> <input type="checkbox" checked /> <label>#{::File.dirname(page.path)}</label> <input type="checkbox" checked />
+1 -1
View File
@@ -1,3 +1,3 @@
<ol class="tree"> <ol class="tree">
<li class="file"><a href="./0">0</a></li> <li class="file"><a href="0">0</a></li>
</ol> </ol>
+1 -1
View File
@@ -2,7 +2,7 @@
<li> <li>
<label>.</label> <input type="checkbox" checked /> <label>.</label> <input type="checkbox" checked />
<ol> <ol>
<li class="file"><a href="./folder0">folder0</a></li> <li class="file"><a href="folder0">folder0</a></li>
</ol> </ol>
</li> </li>
</ol> </ol>
+1 -1
View File
@@ -1,5 +1,5 @@
<ol class="tree"> <ol class="tree">
<li class="file"><a href="./root">root</a></li> <li class="file"><a href="root">root</a></li>
<li> <li>
<label>folder0</label> <input type="checkbox" checked /> <label>folder0</label> <input type="checkbox" checked />
<ol> <ol>