Change the way to compute relative paths to avoid the leading .././ when using

relative urls.
This commit is contained in:
Simon 2012-11-28 22:28:27 +01:00
commit 088c810b00
3 changed files with 10 additions and 6 deletions

View file

@ -133,8 +133,12 @@ def clean_output_dir(path):
def get_relative_path(filename): def get_relative_path(filename):
"""Return the relative path to the given filename""" """Return the relative path from the given filename to the root path."""
return '../' * filename.count('/') + '.' nslashes = filename.count('/')
if nslashes == 0:
return '.'
else:
return '/'.join(['..'] * nslashes)
def truncate_html_words(s, num, end_text='...'): def truncate_html_words(s, num, end_text='...'):

View file

@ -51,9 +51,9 @@ class TestUtils(unittest.TestCase):
def test_get_relative_path(self): def test_get_relative_path(self):
samples = (('/test/test', '../../.'), samples = (('test/test.html', '..'),
('/test/test/', '../../../.'), ('test/test/test.html', '../..'),
('/', '../.')) ('test.html', '.'))
for value, expected in samples: for value, expected in samples:
self.assertEquals(utils.get_relative_path(value), expected) self.assertEquals(utils.get_relative_path(value), expected)

View file

@ -79,7 +79,7 @@ class TestWebAssetsRelativeURLS(TestWebAssets):
self.check_link_tag(css_file, os.path.join(self.temp_path, f)) self.check_link_tag(css_file, os.path.join(self.temp_path, f))
self.check_link_tag( self.check_link_tag(
'.././theme/gen/style.{0}.min.css'.format(CSS_HASH), '../theme/gen/style.{0}.min.css'.format(CSS_HASH),
os.path.join(self.temp_path, 'category/yeah.html')) os.path.join(self.temp_path, 'category/yeah.html'))