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
4bac1a4d
Commit
4bac1a4d
authored
Feb 27, 2012
by
Timothée Peignier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
remove mhtml embedding
parent
273d0abd
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
6 additions
and
37 deletions
+6
-37
docs/configuration.rst
+3
-3
pipeline/compressors/__init__.py
+2
-32
pipeline/packager.py
+1
-2
No files found.
docs/configuration.rst
View file @
4bac1a4d
...
...
@@ -67,8 +67,8 @@ Group options
**Optional**
Is the variant you want to apply to your CSS. This allow you to embed images
and fonts in CSS with data-URI
or MHTML
.
Allowed values are : ``None``
, ``datauri`` or ``mhtml
``.
and fonts in CSS with data-URI.
Allowed values are : ``None``
and ``datauri
``.
Defaults to ``None``.
...
...
@@ -182,7 +182,7 @@ Embedding fonts and images
==========================
You can embed fonts and images directly in your compiled css, using Data-URI in
modern browser
or MHTML in Internet Explorer 7 or below
.
modern browser.
To do so, setup variant group options to the method you wish to use : ::
...
...
pipeline/compressors/__init__.py
View file @
4bac1a4d
...
...
@@ -15,10 +15,6 @@ EMBEDDABLE = r'[/]?embed/'
URL_DETECTOR
=
r'url\([\'"]?([^\s)]+\.[a-z]+[\?\#\d\w]*)[\'"]?\)'
URL_REPLACER
=
r'url\(__EMBED__(.+?)(\?\d+)?\)'
MHTML_START
=
"/*
\r\n
Content-Type: multipart/related; boundary=
\"
MHTML_MARK
\"\r\n\r\n
"
MHTML_SEPARATOR
=
"--MHTML_MARK
\r\n
"
MHTML_END
=
"
\r\n
--MHTML_MARK--
\r\n
*/
\r\n
"
DEFAULT_TEMPLATE_FUNC
=
"template"
TEMPLATE_FUNC
=
"""var template = function(str){var fn = new Function('obj', 'var __p=[],print=function(){__p.push.apply(__p,arguments);};with(obj||{}){__p.push(
\'
'+str.replace(/
\\
/g, '
\\\\
').replace(/'/g, "
\\
'").replace(/<
%
=([
\
s
\
S]+?)
%
>/g,function(match,code){return "',"+code.replace(/
\\
'/g, "'")+",'";}).replace(/<
%
([
\
s
\
S]+?)
%
>/g,function(match,code){return "');"+code.replace(/
\\
'/g, "'").replace(/[
\r\n\t
]/g,' ')+"__p.push('";}).replace(/
\r
/g,'
\\
r').replace(/
\n
/g,'
\\
n').replace(/
\t
/g,'
\\
t')+"');}return __p.join('');");return fn;};"""
...
...
@@ -52,7 +48,7 @@ class Compressor(object):
return
to_class
(
settings
.
PIPELINE_CSS_COMPRESSOR
)
css_compressor
=
property
(
css_compressor
)
def
compress_js
(
self
,
paths
,
templates
=
None
,
asset_url
=
None
,
**
kwargs
):
def
compress_js
(
self
,
paths
,
templates
=
None
,
**
kwargs
):
"""Concatenate and compress JS files"""
js
=
self
.
concatenate
(
paths
)
if
templates
:
...
...
@@ -65,8 +61,7 @@ class Compressor(object):
return
js
def
compress_css
(
self
,
paths
,
variant
=
None
,
asset_url
=
None
,
absolute_paths
=
True
,
**
kwargs
):
def
compress_css
(
self
,
paths
,
variant
=
None
,
absolute_paths
=
True
,
**
kwargs
):
"""Concatenate and compress CSS files"""
css
=
self
.
concatenate_and_rewrite
(
paths
,
variant
,
absolute_paths
)
...
...
@@ -77,8 +72,6 @@ class Compressor(object):
return
css
elif
variant
==
"datauri"
:
return
self
.
with_data_uri
(
css
)
elif
variant
==
"mhtml"
:
return
self
.
with_mhtml
(
css
,
asset_url
)
else
:
raise
CompressorError
(
"
\"
%
s
\"
is not a valid variant"
%
variant
)
...
...
@@ -176,29 +169,6 @@ class Compressor(object):
return
"url(
\"
data:
%
s;charset=utf-8;base64,
%
s
\"
)"
%
(
mime_type
,
data
)
return
re
.
sub
(
URL_REPLACER
,
datauri
,
css
)
def
with_mhtml
(
self
,
css
,
asset_url
):
paths
=
{}
def
mhtml
(
match
):
path
=
match
.
group
(
1
)
if
not
path
in
paths
:
paths
[
path
]
=
"
%
s-
%
s"
%
(
match
.
start
(),
os
.
path
.
basename
(
path
))
return
"url(mhtml:
%
s!
%
s)"
%
(
asset_url
,
paths
[
path
])
css
=
re
.
sub
(
URL_REPLACER
,
mhtml
,
css
)
mhtml
=
[]
for
path
,
location
in
paths
.
items
():
mime_type
=
self
.
mime_type
(
path
)
data
=
self
.
encoded_content
(
path
)
mhtml
.
extend
([
MHTML_SEPARATOR
,
"Content-Location:
%
s
\r\n
"
%
location
,
"Content-Type:
%
s
\r\n
"
%
mime_type
,
"Content-Transfer-Encoding: base64
\r\n\r\n
"
,
data
,
"
\r\n
"
])
output
=
[
MHTML_START
,
mhtml
,
MHTML_END
,
css
]
return
''
.
join
([
part
for
parts
in
output
for
part
in
parts
])
def
encoded_content
(
self
,
path
):
"""Return the base64 encoded contents"""
if
path
in
self
.
__class__
.
asset_contents
:
...
...
pipeline/packager.py
View file @
4bac1a4d
...
...
@@ -101,8 +101,7 @@ class Packager(object):
if
self
.
verbose
:
print
"Saving:
%
s"
%
output_filename
paths
=
self
.
compile
(
package
.
paths
)
content
=
compress
(
paths
,
asset_url
=
self
.
individual_url
(
output_filename
),
**
kwargs
)
content
=
compress
(
paths
,
**
kwargs
)
self
.
save_file
(
output_filename
,
content
)
signal
.
send
(
sender
=
self
,
package
=
package
,
**
kwargs
)
return
output_filename
...
...
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