Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
D
django-pipeline
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
OpenEdx
django-pipeline
Commits
8ae24c32
Commit
8ae24c32
authored
Aug 14, 2012
by
Timothée Peignier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
deal with storage prefix
parent
9256848c
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
54 additions
and
43 deletions
+54
-43
pipeline/storage.py
+16
-6
tests/settings.py
+8
-8
tests/tests/compiler.py
+3
-3
tests/tests/compressor.py
+19
-18
tests/tests/jinja2.py
+4
-4
tests/tests/packager.py
+3
-3
tests/tests/storage.py
+1
-1
No files found.
pipeline/storage.py
View file @
8ae24c32
...
...
@@ -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
)
...
...
tests/settings.py
View file @
8ae24c32
...
...
@@ -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'
}
...
...
tests/tests/compiler.py
View file @
8ae24c32
...
...
@@ -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
tests/tests/compressor.py
View file @
8ae24c32
...
...
@@ -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\n
function 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
\n
window.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
\n
window.JST[
\'
video_detail
\'
] = template(
\'
<div class="video">
\\
n <video src="<
%%
= src
%%
>" />
\\
n <div class="caption">
\\
n <
%%
= description
%%
>
\\
n </div>
\\
n</div>
\'
);
\n
window.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);
...
...
tests/tests/jinja2.py
View file @
8ae24c32
...
...
@@ -33,7 +33,7 @@ class Jinja2Test(TestCase):
tpl
=
self
.
environment
.
get_template
(
'css.jinja'
)
tpl
.
render
()
except
:
self
.
fail
(
'Failed to load individual
J
S'
)
self
.
fail
(
'Failed to load individual
CS
S'
)
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
J
S'
)
self
.
fail
(
'Failed to load compressed
CS
S'
)
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
CS
S'
)
self
.
fail
(
'Failed to load individual
J
S'
)
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
CS
S'
)
self
.
fail
(
'Failed to load compressed
J
S'
)
tests/tests/packager.py
View file @
8ae24c32
...
...
@@ -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'
])
tests/tests/storage.py
View file @
8ae24c32
...
...
@@ -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
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment