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
d4b24e31
Commit
d4b24e31
authored
Dec 24, 2012
by
Timothée Peignier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
continue working on this
parent
bbc0a4e1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
47 additions
and
13 deletions
+47
-13
pipeline/jinja2/ext.py
+27
-12
tests/tests/__init__.py
+3
-1
tests/tests/extension.py
+17
-0
No files found.
pipeline/jinja2/ext.py
View file @
d4b24e31
...
...
@@ -8,6 +8,7 @@ from jinja2.ext import Extension
from
pipeline.conf
import
settings
from
pipeline.packager
import
Packager
,
PackageNotFound
from
pipeline.utils
import
guess_type
class
PipelineExtension
(
Extension
):
...
...
@@ -19,15 +20,19 @@ class PipelineExtension(Extension):
if
stream
.
current
.
test
(
'string'
):
if
stream
.
look
()
.
test
(
'string'
):
token
=
stream
.
next
()
package_name
=
nodes
.
Const
(
token
.
value
,
lineno
=
token
.
lineno
)
package_name
=
token
.
value
else
:
package_name
=
parser
.
parse_expression
()
package_name
=
parser
.
parse_expression
()
.
value
if
tag
.
value
==
"compressed_css"
:
return
self
.
package_css
(
package_name
)
return
nodes
.
Output
([
self
.
call_method
(
'package_css'
,
args
=
[
package_name
]),
])
.
set_lineno
(
tag
.
lineno
)
if
tag
.
value
==
"compressed_js"
:
return
self
.
package_js
(
package_name
)
return
nodes
.
Output
([
self
.
call_method
(
'package_js'
,
args
=
[
package_name
]),
])
.
set_lineno
(
tag
.
lineno
)
return
[]
...
...
@@ -40,21 +45,31 @@ class PipelineExtension(Extension):
try
:
package
=
packager
.
package_for
(
'css'
,
package_name
)
except
PackageNotFound
:
return
''
# fail silently, do not return anything if an invalid group is specified
return
nodes
.
Markup
(
''
)
if
settings
.
PIPELINE
:
return
self
.
render_css
(
package
,
package
.
output_filename
)
return
nodes
.
Markup
(
self
.
render_css
(
package
,
package
.
output_filename
)
)
else
:
paths
=
packager
.
compile
(
package
.
paths
)
return
self
.
render_individual
(
package
,
paths
)
return
nodes
.
Markup
(
self
.
render_individual_css
(
package
,
paths
)
)
def
render_css
(
self
,
package
,
path
):
print
"render"
return
template_name
=
"pipeline/css.jinja"
if
package
.
template_name
:
template_name
=
package
.
template_name
def
render_individual
(
self
,
package
,
paths
):
print
"render"
return
context
=
package
.
extra_context
context
.
update
({
'type'
:
guess_type
(
path
,
'text/css'
),
'url'
:
staticfiles_storage
.
url
(
path
)
})
template
=
self
.
environment
.
get_template
(
template_name
)
return
template
.
render
(
**
context
)
def
render_individual_css
(
self
,
package
,
paths
):
tags
=
[
self
.
render_css
(
package
,
path
)
for
path
in
paths
]
return
'
\n
'
.
join
(
tags
)
def
package_js
(
self
,
package_name
):
return
tests/tests/__init__.py
View file @
d4b24e31
# -*- coding: utf-8 flake8: noqa -*-
from
compiler
import
*
from
compressor
import
*
from
extension
import
*
from
glob
import
*
from
packager
import
*
from
storage
import
*
from
utils
import
*
from
utils
import
*
\ No newline at end of file
tests/tests/extension.py
0 → 100644
View file @
d4b24e31
# -*- coding: utf-8 -*-
from
jinja2
import
Environment
,
FileSystemLoader
from
pipeline.jinja2.ext
import
PipelineExtension
from
django.template.loaders
import
app_directories
from
django.test
import
TestCase
class
PipelineExtensionTest
(
TestCase
):
def
setUp
(
self
):
loader
=
FileSystemLoader
(
app_directories
.
app_template_dirs
)
self
.
env
=
Environment
(
extensions
=
[
PipelineExtension
],
loader
=
loader
)
def
test_compressed_css
(
self
):
output
=
self
.
env
.
from_string
(
"{
%
compressed_css 'screen'
%
}"
)
.
render
()
print
output
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