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
f5dc3a5b
Commit
f5dc3a5b
authored
Dec 22, 2011
by
Timothée Peignier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
make package more lazy
parent
0fee8967
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
84 additions
and
66 deletions
+84
-66
docs/configuration.rst
+14
-5
pipeline/packager.py
+53
-29
pipeline/templatetags/compressed.py
+17
-32
No files found.
docs/configuration.rst
View file @
f5dc3a5b
...
@@ -28,7 +28,6 @@ The basic syntax for specifying CSS/JavaScript groups files is ::
...
@@ -28,7 +28,6 @@ The basic syntax for specifying CSS/JavaScript groups files is ::
'media': 'screen,projection',
'media': 'screen,projection',
},
},
},
},
# other CSS groups goes here
}
}
PIPELINE_JS = {
PIPELINE_JS = {
...
@@ -73,14 +72,14 @@ Group options
...
@@ -73,14 +72,14 @@ Group options
Defaults to ``None``.
Defaults to ``None``.
``
manifest
``
``
template_name
``
............
............
.....
**Optional**
**Optional**
Indicate if you want this group to appear in your cache manifest
.
Name of the template used to render ``<script>`` for js package or ``<link>`` for css package
.
Defaults to ``
Tru
e``.
Defaults to ``
Non
e``.
``extra_context``
``extra_context``
.................
.................
...
@@ -108,6 +107,16 @@ Group options
...
@@ -108,6 +107,16 @@ Group options
Note that all filenames are specified relative to ``PIPELINE_ROOT``, and thus the source
Note that all filenames are specified relative to ``PIPELINE_ROOT``, and thus the source
files needs to be in your ``PIPELINE_ROOT``.
files needs to be in your ``PIPELINE_ROOT``.
``manifest``
............
**Optional**
Indicate if you want this group to appear in your cache manifest.
Defaults to ``True``.
Other settings
Other settings
--------------
--------------
...
...
pipeline/packager.py
View file @
f5dc3a5b
...
@@ -10,6 +10,53 @@ from pipeline.signals import css_compressed, js_compressed
...
@@ -10,6 +10,53 @@ from pipeline.signals import css_compressed, js_compressed
from
pipeline.storage
import
storage
from
pipeline.storage
import
storage
class
Package
(
object
):
def
__init__
(
self
,
config
):
self
.
config
=
config
self
.
_sources
=
[]
@property
def
sources
(
self
):
if
not
self
.
_sources
:
paths
=
[]
for
pattern
in
self
.
config
.
get
(
'source_filenames'
,
[]):
for
path
in
glob
(
pattern
):
if
not
path
in
paths
:
paths
.
append
(
str
(
path
))
self
.
_sources
=
paths
return
self
.
_sources
@property
def
paths
(
self
):
return
[
path
for
path
in
self
.
sources
if
not
path
.
endswith
(
settings
.
PIPELINE_TEMPLATE_EXT
)]
@property
def
templates
(
self
):
return
[
path
for
path
in
self
.
sources
if
path
.
endswith
(
settings
.
PIPELINE_TEMPLATE_EXT
)]
@property
def
output
(
self
):
return
self
.
config
.
get
(
'output_filename'
)
@property
def
extra_context
(
self
):
return
self
.
config
.
get
(
'extra_context'
,
{})
@property
def
template_name
(
self
):
return
self
.
config
.
get
(
'template_name'
)
@property
def
variant
(
self
):
return
self
.
config
.
get
(
'variant'
)
@property
def
manifest
(
self
):
return
self
.
config
.
get
(
'manifest'
,
True
)
class
Packager
(
object
):
class
Packager
(
object
):
def
__init__
(
self
,
verbose
=
False
,
css_packages
=
None
,
js_packages
=
None
):
def
__init__
(
self
,
verbose
=
False
,
css_packages
=
None
,
js_packages
=
None
):
self
.
verbose
=
verbose
self
.
verbose
=
verbose
...
@@ -26,7 +73,7 @@ class Packager(object):
...
@@ -26,7 +73,7 @@ class Packager(object):
def
package_for
(
self
,
kind
,
package_name
):
def
package_for
(
self
,
kind
,
package_name
):
try
:
try
:
return
self
.
packages
[
kind
][
package_name
]
.
copy
()
return
self
.
packages
[
kind
][
package_name
]
except
KeyError
:
except
KeyError
:
raise
PackageNotFound
(
raise
PackageNotFound
(
"No corresponding package for
%
s package name :
%
s"
%
(
"No corresponding package for
%
s package name :
%
s"
%
(
...
@@ -51,10 +98,10 @@ class Packager(object):
...
@@ -51,10 +98,10 @@ class Packager(object):
return
self
.
compiler
.
compile
(
paths
)
return
self
.
compiler
.
compile
(
paths
)
def
pack
(
self
,
package
,
compress
,
signal
,
**
kwargs
):
def
pack
(
self
,
package
,
compress
,
signal
,
**
kwargs
):
output_filename
=
package
[
"output"
]
output_filename
=
package
.
output
if
self
.
verbose
:
if
self
.
verbose
:
print
"Saving:
%
s"
%
output_filename
print
"Saving:
%
s"
%
output_filename
paths
=
self
.
compile
(
package
[
'paths'
]
)
paths
=
self
.
compile
(
package
.
paths
)
content
=
compress
(
paths
,
content
=
compress
(
paths
,
asset_url
=
self
.
individual_url
(
output_filename
),
**
kwargs
)
asset_url
=
self
.
individual_url
(
output_filename
),
**
kwargs
)
self
.
save_file
(
output_filename
,
content
)
self
.
save_file
(
output_filename
,
content
)
...
@@ -62,12 +109,10 @@ class Packager(object):
...
@@ -62,12 +109,10 @@ class Packager(object):
return
output_filename
return
output_filename
def
pack_javascripts
(
self
,
package
,
**
kwargs
):
def
pack_javascripts
(
self
,
package
,
**
kwargs
):
if
'externals'
in
package
:
return
self
.
pack
(
package
,
self
.
compressor
.
compress_js
,
js_compressed
,
templates
=
package
.
templates
,
**
kwargs
)
return
return
self
.
pack
(
package
,
self
.
compressor
.
compress_js
,
js_compressed
,
templates
=
package
[
'templates'
],
**
kwargs
)
def
pack_templates
(
self
,
package
):
def
pack_templates
(
self
,
package
):
return
self
.
compressor
.
compile_templates
(
package
[
'templates'
]
)
return
self
.
compressor
.
compile_templates
(
package
.
templates
)
def
save_file
(
self
,
path
,
content
):
def
save_file
(
self
,
path
,
content
):
return
storage
.
save
(
path
,
ContentFile
(
content
))
return
storage
.
save
(
path
,
ContentFile
(
content
))
...
@@ -77,28 +122,7 @@ class Packager(object):
...
@@ -77,28 +122,7 @@ class Packager(object):
if
not
config
:
if
not
config
:
return
packages
return
packages
for
name
in
config
:
for
name
in
config
:
packages
[
name
]
=
{}
packages
[
name
]
=
Package
(
config
[
name
])
paths
=
[]
for
pattern
in
config
[
name
][
'source_filenames'
]:
for
path
in
glob
(
pattern
):
if
not
path
in
paths
:
paths
.
append
(
str
(
path
))
packages
[
name
][
'paths'
]
=
[
path
for
path
in
paths
if
not
path
.
endswith
(
settings
.
PIPELINE_TEMPLATE_EXT
)]
packages
[
name
][
'templates'
]
=
[
path
for
path
in
paths
if
path
.
endswith
(
settings
.
PIPELINE_TEMPLATE_EXT
)]
packages
[
name
][
'output'
]
=
config
[
name
][
'output_filename'
]
packages
[
name
][
'context'
]
=
{}
packages
[
name
][
'manifest'
]
=
True
if
'absolute_asset_paths'
in
config
[
name
]:
packages
[
name
][
'absolute_asset_paths'
]
=
\
config
[
name
][
'absolute_asset_paths'
]
if
'extra_context'
in
config
[
name
]:
packages
[
name
][
'context'
]
=
config
[
name
][
'extra_context'
]
if
'template_name'
in
config
[
name
]:
packages
[
name
][
'template'
]
=
config
[
name
][
'template_name'
]
if
'variant'
in
config
[
name
]:
packages
[
name
][
'variant'
]
=
config
[
name
][
'variant'
]
if
'manifest'
in
config
[
name
]:
packages
[
name
][
'manifest'
]
=
config
[
name
][
'manifest'
]
return
packages
return
packages
...
...
pipeline/templatetags/compressed.py
View file @
f5dc3a5b
...
@@ -29,24 +29,21 @@ class CompressedCSSNode(template.Node):
...
@@ -29,24 +29,21 @@ class CompressedCSSNode(template.Node):
return
''
# fail silently, do not return anything if an invalid group is specified
return
''
# fail silently, do not return anything if an invalid group is specified
if
settings
.
PIPELINE
:
if
settings
.
PIPELINE
:
return
self
.
render_css
(
package
,
package
[
"output"
]
)
return
self
.
render_css
(
package
,
package
.
output
)
else
:
else
:
pa
ckage
[
'paths'
]
=
self
.
packager
.
compile
(
package
[
'paths'
]
)
pa
ths
=
self
.
packager
.
compile
(
package
.
paths
)
return
self
.
render_individual
(
package
)
return
self
.
render_individual
(
package
,
paths
)
def
render_css
(
self
,
package
,
path
):
def
render_css
(
self
,
package
,
path
):
context
=
{}
template_name
=
package
.
template_name
or
"pipeline/css.html"
if
not
'template'
in
package
:
context
=
package
.
extra_context
package
[
'template'
]
=
"pipeline/css.html"
if
'context'
in
package
:
context
=
package
[
'context'
]
context
.
update
({
context
.
update
({
'url'
:
staticfiles_storage
.
url
(
path
)
'url'
:
staticfiles_storage
.
url
(
path
)
})
})
return
render_to_string
(
package
[
'template'
]
,
context
)
return
render_to_string
(
template_name
,
context
)
def
render_individual
(
self
,
package
):
def
render_individual
(
self
,
package
,
paths
):
tags
=
[
self
.
render_css
(
package
,
path
)
for
path
in
pa
ckage
[
'paths'
]
]
tags
=
[
self
.
render_css
(
package
,
path
)
for
path
in
pa
ths
]
return
'
\n
'
.
join
(
tags
)
return
'
\n
'
.
join
(
tags
)
...
@@ -67,41 +64,29 @@ class CompressedJSNode(template.Node):
...
@@ -67,41 +64,29 @@ class CompressedJSNode(template.Node):
return
''
# fail silently, do not return anything if an invalid group is specified
return
''
# fail silently, do not return anything if an invalid group is specified
if
settings
.
PIPELINE
:
if
settings
.
PIPELINE
:
return
self
.
render_js
(
package
,
package
[
"output"
]
)
return
self
.
render_js
(
package
,
package
.
output
)
else
:
else
:
pa
ckage
[
'paths'
]
=
self
.
packager
.
compile
(
package
[
'paths'
]
)
pa
ths
=
self
.
packager
.
compile
(
package
.
paths
)
templates
=
self
.
packager
.
pack_templates
(
package
)
templates
=
self
.
packager
.
pack_templates
(
package
)
return
self
.
render_individual
(
package
,
templates
)
return
self
.
render_individual
(
package
,
paths
,
templates
)
def
render_js
(
self
,
package
,
path
):
def
render_js
(
self
,
package
,
path
):
context
=
{}
template_name
=
package
.
template_name
or
"pipeline/js.html"
if
not
'template'
in
package
:
context
=
package
.
extra_context
package
[
'template'
]
=
"pipeline/js.html"
if
'context'
in
package
:
context
=
package
[
'context'
]
context
.
update
({
context
.
update
({
'url'
:
staticfiles_storage
.
url
(
path
)
'url'
:
staticfiles_storage
.
url
(
path
)
})
})
return
render_to_string
(
package
[
'template'
],
context
)
return
render_to_string
(
template_name
,
context
)
def
render_external
(
self
,
package
,
url
):
if
not
'template'
in
package
:
package
[
'template'
]
=
"pipeline/js.html"
return
render_to_string
(
package
[
'template'
],
{
'url'
:
url
})
def
render_inline
(
self
,
package
,
js
):
def
render_inline
(
self
,
package
,
js
):
context
=
{}
context
=
package
.
extra_context
if
'context'
in
package
:
context
=
package
[
'context'
]
context
.
update
({
context
.
update
({
'source'
:
js
'source'
:
js
})
})
return
render_to_string
(
"pipeline/inline_js.html"
,
context
)
return
render_to_string
(
"pipeline/inline_js.html"
,
context
)
def
render_individual
(
self
,
package
,
templates
=
None
):
def
render_individual
(
self
,
package
,
paths
,
templates
=
None
):
tags
=
[
self
.
render_js
(
package
,
js
)
for
js
in
pa
ckage
[
'paths'
]
]
tags
=
[
self
.
render_js
(
package
,
js
)
for
js
in
pa
ths
]
if
templates
:
if
templates
:
tags
.
append
(
self
.
render_inline
(
package
,
templates
))
tags
.
append
(
self
.
render_inline
(
package
,
templates
))
return
'
\n
'
.
join
(
tags
)
return
'
\n
'
.
join
(
tags
)
...
...
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