Commit 8ae24c32 by Timothée Peignier

deal with storage prefix

parent 9256848c
......@@ -101,21 +101,31 @@ class BaseFinderStorage(PipelineStorage):
except OSError:
pass
def match_location(self, name, path, prefix=None):
if prefix:
prefix = "%s%s" % (prefix, os.sep)
name = name[len(prefix):]
if path == name:
return name
if os.path.splitext(path)[0] == os.path.splitext(name)[0]:
return name
return None
def find_storage(self, name):
for finder in finders.get_finders():
for path, storage in finder.list([]):
if path == name:
return storage
if os.path.splitext(path)[0] == os.path.splitext(name)[0]:
return storage
prefix = getattr(storage, 'prefix', None)
matched_path = self.match_location(name, path, prefix)
if matched_path:
return matched_path, storage
raise ValueError("The file '%s' could not be found with %r." % (name, self))
def _open(self, name, mode="rb"):
storage = self.find_storage(name)
name, storage = self.find_storage(name)
return storage._open(name, mode)
def _save(self, name, content):
storage = self.find_storage(name)
name, storage = self.find_storage(name)
# Ensure we overwrite file, since we have no control on external storage
if storage.exists(name):
storage.delete(name)
......
......@@ -28,7 +28,7 @@ STATICFILES_STORAGE = 'pipeline.storage.PipelineStorage'
STATIC_ROOT = local_path('static/')
STATIC_URL = '/static/'
STATICFILES_DIRS = (
local_path('assets/'),
('pipeline', local_path('assets/')),
local_path('assets2/'),
)
STATICFILES_FINDERS = (
......@@ -45,9 +45,9 @@ TEMPLATE_DIRS = (
PIPELINE_CSS = {
'screen': {
'source_filenames': (
'css/first.css',
'css/second.css',
'css/urls.css',
'pipeline/css/first.css',
'pipeline/css/second.css',
'pipeline/css/urls.css',
),
'output_filename': 'screen.css'
}
......@@ -55,10 +55,10 @@ PIPELINE_CSS = {
PIPELINE_JS = {
'scripts': {
'source_filenames': (
'js/first.js',
'js/second.js',
'js/application.js',
'templates/**/*.jst'
'pipeline/js/first.js',
'pipeline/js/second.js',
'pipeline/js/application.js',
'pipeline/templates/**/*.jst'
),
'output_filename': 'scripts.css'
}
......
......@@ -30,10 +30,10 @@ class CompilerTest(TestCase):
def test_compile(self):
paths = self.compiler.compile([
'js/dummy.coffee',
'js/application.js',
'pipeline/js/dummy.coffee',
'pipeline/js/application.js',
])
self.assertEquals(['js/dummy.js', 'js/application.js'], paths)
self.assertEquals(['pipeline/js/dummy.js', 'pipeline/js/application.js'], paths)
def tearDown(self):
settings.PIPELINE_COMPILERS = self.old_compilers
......@@ -11,6 +11,7 @@ from pipeline.compressors.yui import YUICompressor
class CompressorTest(TestCase):
def setUp(self):
self.maxDiff = None
self.compressor = Compressor()
def test_js_compressor_class(self):
......@@ -21,24 +22,24 @@ class CompressorTest(TestCase):
def test_concatenate_and_rewrite(self):
css = self.compressor.concatenate_and_rewrite([
'css/first.css',
'css/second.css'
'pipeline/css/first.css',
'pipeline/css/second.css'
], 'css/screen.css')
self.assertEquals(""".concat {\n display: none;\n}\n\n.concatenate {\n display: block;\n}\n""", css)
def test_concatenate(self):
js = self.compressor.concatenate([
'js/first.js',
'js/second.js'
'pipeline/js/first.js',
'pipeline/js/second.js'
])
self.assertEquals("""function concat() {\n console.log(arguments);\n}\n\nfunction cat() {\n console.log("hello world");\n}\n""", js)
@patch.object(base64, 'b64encode')
def test_encoded_content(self, mock):
self.compressor.encoded_content('images/arrow.png')
self.compressor.encoded_content('pipeline/images/arrow.png')
self.assertTrue(mock.called)
mock.reset_mock()
self.compressor.encoded_content('images/arrow.png')
self.compressor.encoded_content('pipeline/images/arrow.png')
self.assertFalse(mock.called)
def test_relative_path(self):
......@@ -70,19 +71,19 @@ class CompressorTest(TestCase):
self.assertEquals(name, 'photo_detail')
def test_compile_templates(self):
templates = self.compressor.compile_templates(['templates/photo/list.jst'])
templates = self.compressor.compile_templates(['pipeline/templates/photo/list.jst'])
self.assertEquals(templates, """window.JST = window.JST || {};\n%s\nwindow.JST[\'list\'] = template(\'<div class="photo">\\n <img src="<%%= src %%>" />\\n <div class="caption">\\n <%%= caption %%>\\n </div>\\n</div>\');\n""" % TEMPLATE_FUNC)
templates = self.compressor.compile_templates([
'templates/video/detail.jst',
'templates/photo/detail.jst'
'pipeline/templates/video/detail.jst',
'pipeline/templates/photo/detail.jst'
])
self.assertEqual(templates, """window.JST = window.JST || {};\n%s\nwindow.JST[\'video_detail\'] = template(\'<div class="video">\\n <video src="<%%= src %%>" />\\n <div class="caption">\\n <%%= description %%>\\n </div>\\n</div>\');\nwindow.JST[\'photo_detail\'] = template(\'<div class="photo">\\n <img src="<%%= src %%>" />\\n <div class="caption">\\n <%%= caption %%> by <%%= author %%>\\n </div>\\n</div>\');\n""" % TEMPLATE_FUNC)
def test_embeddable(self):
self.assertFalse(self.compressor.embeddable('images/sprite.png', None))
self.assertFalse(self.compressor.embeddable('images/arrow.png', 'datauri'))
self.assertTrue(self.compressor.embeddable('images/embed/arrow.png', 'datauri'))
self.assertFalse(self.compressor.embeddable('images/arrow.dat', 'datauri'))
self.assertFalse(self.compressor.embeddable('pipeline/images/sprite.png', None))
self.assertFalse(self.compressor.embeddable('pipeline/images/arrow.png', 'datauri'))
self.assertTrue(self.compressor.embeddable('pipeline/images/embed/arrow.png', 'datauri'))
self.assertFalse(self.compressor.embeddable('pipeline/images/arrow.dat', 'datauri'))
def test_construct_asset_path(self):
asset_path = self.compressor.construct_asset_path("../../images/sprite.png",
......@@ -94,18 +95,18 @@ class CompressorTest(TestCase):
def test_url_rewrite(self):
output = self.compressor.concatenate_and_rewrite([
'css/urls.css',
'pipeline/css/urls.css',
], 'css/screen.css')
self.assertEquals(u"""@font-face {
font-family: 'Pipeline';
src: url(../fonts/pipeline.eot);
src: url(../fonts/pipeline.eot?#iefix) format('embedded-opentype');
src: local('☺'), url(../fonts/pipeline.woff) format('woff'), url(../fonts/pipeline.ttf) format('truetype'), url(../fonts/pipeline.svg#IyfZbseF) format('svg');
src: url(../pipeline/fonts/pipeline.eot);
src: url(../pipeline/fonts/pipeline.eot?#iefix) format('embedded-opentype');
src: local('☺'), url(../pipeline/fonts/pipeline.woff) format('woff'), url(../pipeline/fonts/pipeline.ttf) format('truetype'), url(../pipeline/fonts/pipeline.svg#IyfZbseF) format('svg');
font-weight: normal;
font-style: normal;
}
.relative-url {
background-image: url(../images/sprite-buttons.png);
background-image: url(../pipeline/images/sprite-buttons.png);
}
.absolute-url {
background-image: url(/images/sprite-buttons.png);
......
......@@ -33,7 +33,7 @@ class Jinja2Test(TestCase):
tpl = self.environment.get_template('css.jinja')
tpl.render()
except:
self.fail('Failed to load individual JS')
self.fail('Failed to load individual CSS')
def test_template_css_function_compressed(self):
settings.PIPELINE = True
......@@ -41,7 +41,7 @@ class Jinja2Test(TestCase):
tpl = self.environment.get_template('css.jinja')
tpl.render()
except:
self.fail('Failed to load compressed JS')
self.fail('Failed to load compressed CSS')
def test_template_js_function_individual(self):
settings.PIPELINE = False
......@@ -49,7 +49,7 @@ class Jinja2Test(TestCase):
tpl = self.environment.get_template('js.jinja')
tpl.render()
except:
self.fail('Failed to load individual CSS')
self.fail('Failed to load individual JS')
def test_template_js_function_compressed(self):
settings.PIPELINE = True
......@@ -57,4 +57,4 @@ class Jinja2Test(TestCase):
tpl = self.environment.get_template('js.jinja')
tpl.render()
except:
self.fail('Failed to load compressed CSS')
self.fail('Failed to load compressed JS')
......@@ -9,7 +9,7 @@ class PackagerTest(TestCase):
packager.packages['js'] = packager.create_packages({
'application': {
'source_filenames': (
'js/application.js',
'pipeline/js/application.js',
),
'output_filename': 'application.js'
}
......@@ -29,9 +29,9 @@ class PackagerTest(TestCase):
packages = packager.create_packages({
'templates': {
'source_filenames': (
'templates/photo/list.jst',
'pipeline/templates/photo/list.jst',
),
'output_filename': 'templates.js',
}
})
self.assertEqual(packages['templates'].templates, ['templates/photo/list.jst'])
self.assertEqual(packages['templates'].templates, ['pipeline/templates/photo/list.jst'])
......@@ -10,7 +10,7 @@ class StorageTest(TestCase):
settings.PIPELINE_CSS = {
'testing': {
'source_filenames': (
'css/first.css',
'pipeline/css/first.css',
'css/third.css',
),
'manifest': False,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment