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
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
86 additions
and
68 deletions
+86
-68
docs/configuration.rst
+16
-7
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 ::
'media': 'screen,projection',
},
},
# other CSS groups goes here
}
PIPELINE_JS = {
...
...
@@ -73,14 +72,14 @@ Group options
Defaults to ``None``.
``
manifest
``
............
``
template_name
``
............
.....
**Optional**
Indicate if you want this group to appear in your cache manifest
.
Defaults to ``
Tru
e``.
Name of the template used to render ``<script>`` for js package or ``<link>`` for css package
.
Defaults to ``
Non
e``.
``extra_context``
.................
...
...
@@ -108,6 +107,16 @@ Group options
Note that all filenames are specified relative to ``PIPELINE_ROOT``, and thus the source
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
--------------
...
...
pipeline/packager.py
View file @
f5dc3a5b
...
...
@@ -10,6 +10,53 @@ from pipeline.signals import css_compressed, js_compressed
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
):
def
__init__
(
self
,
verbose
=
False
,
css_packages
=
None
,
js_packages
=
None
):
self
.
verbose
=
verbose
...
...
@@ -26,7 +73,7 @@ class Packager(object):
def
package_for
(
self
,
kind
,
package_name
):
try
:
return
self
.
packages
[
kind
][
package_name
]
.
copy
()
return
self
.
packages
[
kind
][
package_name
]
except
KeyError
:
raise
PackageNotFound
(
"No corresponding package for
%
s package name :
%
s"
%
(
...
...
@@ -51,10 +98,10 @@ class Packager(object):
return
self
.
compiler
.
compile
(
paths
)
def
pack
(
self
,
package
,
compress
,
signal
,
**
kwargs
):
output_filename
=
package
[
"output"
]
output_filename
=
package
.
output
if
self
.
verbose
:
print
"Saving:
%
s"
%
output_filename
paths
=
self
.
compile
(
package
[
'paths'
]
)
paths
=
self
.
compile
(
package
.
paths
)
content
=
compress
(
paths
,
asset_url
=
self
.
individual_url
(
output_filename
),
**
kwargs
)
self
.
save_file
(
output_filename
,
content
)
...
...
@@ -62,12 +109,10 @@ class Packager(object):
return
output_filename
def
pack_javascripts
(
self
,
package
,
**
kwargs
):
if
'externals'
in
package
:
return
return
self
.
pack
(
package
,
self
.
compressor
.
compress_js
,
js_compressed
,
templates
=
package
[
'templates'
],
**
kwargs
)
return
self
.
pack
(
package
,
self
.
compressor
.
compress_js
,
js_compressed
,
templates
=
package
.
templates
,
**
kwargs
)
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
):
return
storage
.
save
(
path
,
ContentFile
(
content
))
...
...
@@ -77,28 +122,7 @@ class Packager(object):
if
not
config
:
return
packages
for
name
in
config
:
packages
[
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'
]
packages
[
name
]
=
Package
(
config
[
name
])
return
packages
...
...
pipeline/templatetags/compressed.py
View file @
f5dc3a5b
...
...
@@ -29,24 +29,21 @@ class CompressedCSSNode(template.Node):
return
''
# fail silently, do not return anything if an invalid group is specified
if
settings
.
PIPELINE
:
return
self
.
render_css
(
package
,
package
[
"output"
]
)
return
self
.
render_css
(
package
,
package
.
output
)
else
:
pa
ckage
[
'paths'
]
=
self
.
packager
.
compile
(
package
[
'paths'
]
)
return
self
.
render_individual
(
package
)
pa
ths
=
self
.
packager
.
compile
(
package
.
paths
)
return
self
.
render_individual
(
package
,
paths
)
def
render_css
(
self
,
package
,
path
):
context
=
{}
if
not
'template'
in
package
:
package
[
'template'
]
=
"pipeline/css.html"
if
'context'
in
package
:
context
=
package
[
'context'
]
template_name
=
package
.
template_name
or
"pipeline/css.html"
context
=
package
.
extra_context
context
.
update
({
'url'
:
staticfiles_storage
.
url
(
path
)
})
return
render_to_string
(
package
[
'template'
]
,
context
)
return
render_to_string
(
template_name
,
context
)
def
render_individual
(
self
,
package
):
tags
=
[
self
.
render_css
(
package
,
path
)
for
path
in
pa
ckage
[
'paths'
]
]
def
render_individual
(
self
,
package
,
paths
):
tags
=
[
self
.
render_css
(
package
,
path
)
for
path
in
pa
ths
]
return
'
\n
'
.
join
(
tags
)
...
...
@@ -67,41 +64,29 @@ class CompressedJSNode(template.Node):
return
''
# fail silently, do not return anything if an invalid group is specified
if
settings
.
PIPELINE
:
return
self
.
render_js
(
package
,
package
[
"output"
]
)
return
self
.
render_js
(
package
,
package
.
output
)
else
:
pa
ckage
[
'paths'
]
=
self
.
packager
.
compile
(
package
[
'paths'
]
)
pa
ths
=
self
.
packager
.
compile
(
package
.
paths
)
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
):
context
=
{}
if
not
'template'
in
package
:
package
[
'template'
]
=
"pipeline/js.html"
if
'context'
in
package
:
context
=
package
[
'context'
]
template_name
=
package
.
template_name
or
"pipeline/js.html"
context
=
package
.
extra_context
context
.
update
({
'url'
:
staticfiles_storage
.
url
(
path
)
})
return
render_to_string
(
package
[
'template'
],
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
})
return
render_to_string
(
template_name
,
context
)
def
render_inline
(
self
,
package
,
js
):
context
=
{}
if
'context'
in
package
:
context
=
package
[
'context'
]
context
=
package
.
extra_context
context
.
update
({
'source'
:
js
})
return
render_to_string
(
"pipeline/inline_js.html"
,
context
)
def
render_individual
(
self
,
package
,
templates
=
None
):
tags
=
[
self
.
render_js
(
package
,
js
)
for
js
in
pa
ckage
[
'paths'
]
]
def
render_individual
(
self
,
package
,
paths
,
templates
=
None
):
tags
=
[
self
.
render_js
(
package
,
js
)
for
js
in
pa
ths
]
if
templates
:
tags
.
append
(
self
.
render_inline
(
package
,
templates
))
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