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
59dbe419
Commit
59dbe419
authored
Dec 23, 2011
by
Timothée Peignier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
improve how we deal with unix and windows path
parent
385c978f
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
28 additions
and
11 deletions
+28
-11
pipeline/compressors/__init__.py
+7
-9
pipeline/packager.py
+2
-2
pipeline/utils.py
+8
-0
tests/tests/compressor.py
+11
-0
No files found.
pipeline/compressors/__init__.py
View file @
59dbe419
...
...
@@ -7,7 +7,7 @@ from itertools import takewhile
from
pipeline.conf
import
settings
from
pipeline.storage
import
storage
from
pipeline.utils
import
to_class
,
relpath
from
pipeline.utils
import
filepath_to_uri
,
to_class
,
relpath
MAX_IMAGE_SIZE
=
32700
...
...
@@ -112,13 +112,12 @@ class Compressor(object):
path
=
os
.
path
.
basename
(
path
)
if
path
==
base
:
base
=
os
.
path
.
dirname
(
path
)
name
=
re
.
sub
(
r"^
%
s
\/
?(.*)
%
s$"
%
(
name
=
re
.
sub
(
r"^
%
s
[\/\\]
?(.*)
%
s$"
%
(
re
.
escape
(
base
),
re
.
escape
(
settings
.
PIPELINE_TEMPLATE_EXT
)
),
r"\1"
,
path
)
return
re
.
sub
(
r"[\/\\]"
,
"_"
,
name
)
def
concatenate_and_rewrite
(
self
,
paths
,
variant
=
None
,
absolute_asset_paths
=
True
):
def
concatenate_and_rewrite
(
self
,
paths
,
variant
=
None
,
absolute_asset_paths
=
True
):
"""Concatenate together files and rewrite urls"""
stylesheets
=
[]
for
path
in
paths
:
...
...
@@ -126,8 +125,8 @@ class Compressor(object):
asset_path
=
match
.
group
(
1
)
if
asset_path
.
startswith
(
"http"
)
or
asset_path
.
startswith
(
"//"
):
return
"url(
%
s)"
%
asset_path
asset_url
=
self
.
construct_asset_path
(
asset_path
,
path
,
variant
,
absolute_asset_paths
)
asset_url
=
self
.
construct_asset_path
(
asset_path
,
path
,
variant
,
absolute_asset_paths
)
return
"url(
%
s)"
%
asset_url
content
=
self
.
read_file
(
path
)
content
=
re
.
sub
(
URL_DETECTOR
,
reconstruct
,
content
)
...
...
@@ -138,8 +137,7 @@ class Compressor(object):
"""Concatenate together a list of files"""
return
'
\n
'
.
join
([
self
.
read_file
(
path
)
for
path
in
paths
])
def
construct_asset_path
(
self
,
asset_path
,
css_path
,
variant
=
None
,
absolute_asset_paths
=
True
):
def
construct_asset_path
(
self
,
asset_path
,
css_path
,
variant
=
None
,
absolute_asset_paths
=
True
):
"""Return a rewritten asset URL for a stylesheet"""
public_path
=
self
.
absolute_path
(
asset_path
,
os
.
path
.
dirname
(
css_path
))
if
self
.
embeddable
(
public_path
,
variant
):
...
...
@@ -148,7 +146,7 @@ class Compressor(object):
return
asset_path
if
not
os
.
path
.
isabs
(
asset_path
):
asset_path
=
self
.
relative_path
(
public_path
)
asset_url
=
asset_path
.
replace
(
os
.
sep
,
'/'
)
asset_url
=
filepath_to_uri
(
asset_path
)
return
settings
.
PIPELINE_URL
+
asset_url
[
1
:]
def
embeddable
(
self
,
path
,
variant
):
...
...
pipeline/packager.py
View file @
59dbe419
...
...
@@ -9,6 +9,7 @@ from pipeline.compressors import Compressor
from
pipeline.glob
import
glob
from
pipeline.signals
import
css_compressed
,
js_compressed
from
pipeline.storage
import
storage
from
pipeline.utils
import
filepath_to_uri
from
pipeline.versioning
import
Versioning
...
...
@@ -39,9 +40,8 @@ class Packager(object):
def
individual_url
(
self
,
filename
):
relative_path
=
self
.
compressor
.
relative_path
(
filename
)[
1
:]
relative_url
=
relative_path
.
replace
(
os
.
sep
,
'/'
)
return
urlparse
.
urljoin
(
settings
.
PIPELINE_URL
,
relative_url
)
filepath_to_uri
(
relative_path
)
)
def
pack_stylesheets
(
self
,
package
,
**
kwargs
):
variant
=
package
.
get
(
'variant'
,
None
)
...
...
pipeline/utils.py
View file @
59dbe419
import
os
import
sys
import
urllib
from
django.utils
import
importlib
from
django.utils.encoding
import
smart_str
def
to_class
(
class_str
):
...
...
@@ -14,6 +16,12 @@ def to_class(class_str):
return
getattr
(
module
,
class_name
,
None
)
def
filepath_to_uri
(
path
):
if
path
is
None
:
return
path
return
urllib
.
quote
(
smart_str
(
path
)
.
replace
(
"
\\
"
,
"/"
),
safe
=
"/~!*()'#?"
)
def
_relpath_nt
(
path
,
start
=
os
.
path
.
curdir
):
"""Return a relative version of a path"""
if
not
path
:
...
...
tests/tests/compressor.py
View file @
59dbe419
# -*- coding: utf-8 -*-
import
base64
import
sys
from
mock
import
patch
from
django.test
import
TestCase
from
django.utils
import
unittest
from
pipeline.conf
import
settings
from
pipeline.compressors
import
Compressor
...
...
@@ -70,6 +72,9 @@ class CompressorTest(TestCase):
self
.
assertEquals
(
name
,
'photo_detail'
)
name
=
self
.
compressor
.
template_name
(
'templates/photo_edit.jst'
,
''
)
self
.
assertEquals
(
name
,
'photo_edit'
)
name
=
self
.
compressor
.
template_name
(
'templates
\
photo
\
detail.jst'
,
'templates
\\
'
)
self
.
assertEquals
(
name
,
'photo_detail'
)
def
test_compile_templates
(
self
):
templates
=
self
.
compressor
.
compile_templates
([
'templates/photo/list.jst'
])
...
...
@@ -94,6 +99,12 @@ class CompressorTest(TestCase):
"css/plugins/gallery.css"
)
self
.
assertEquals
(
asset_path
,
"http://localhost/static/images/sprite.png"
)
@unittest.skipUnless
(
sys
.
platform
.
startswith
(
"win"
),
"requires Windows"
)
def
test_construct_asset_path_windows
(
self
):
asset_path
=
self
.
compressor
.
construct_asset_path
(
"
\
image
\
sprite.png"
,
"css
\
plugins
\
gallery.css"
)
self
.
assertEquals
(
asset_path
,
"http://localhost/static/images/sprite.png"
)
def
test_construct_asset_path_relative
(
self
):
asset_path
=
self
.
compressor
.
construct_asset_path
(
"../../images/sprite.png"
,
"css/plugins/gallery.css"
,
...
...
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