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
3bdf1a53
Commit
3bdf1a53
authored
Mar 14, 2014
by
Timothée Peignier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
rename template tags to be more obvious
parent
30f3d637
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
35 additions
and
35 deletions
+35
-35
docs/usage.rst
+6
-6
pipeline/jinja2/ext.py
+5
-5
pipeline/templatetags/pipeline.py
+10
-10
tests/tests/test_template.py
+14
-14
No files found.
docs/usage.rst
View file @
3bdf1a53
...
...
@@ -9,8 +9,8 @@ Describes how to use Pipeline when it is installed and configured.
Templatetags
============
Pipeline includes two template tags: ``
compressed_css`` and ``compressed_js
``,
in a template library called ``
compressed
``.
Pipeline includes two template tags: ``
stylesheet`` and ``javascript
``,
in a template library called ``
pipeline
``.
They are used to output the ``<link>`` and ``<script>``-tags for the
specified CSS/JavaScript-groups (as specified in the settings).
...
...
@@ -35,10 +35,10 @@ Example
If you have specified the CSS-groups “colors” and “stats” and a JavaScript-group
with the name “scripts”, you would use the following code to output them all ::
{% load
compressed
%}
{%
compressed_css
'colors' %}
{%
compressed_css
'stats' %}
{%
compressed_js
'scripts' %}
{% load
pipeline
%}
{%
stylesheet
'colors' %}
{%
stylesheet
'stats' %}
{%
javascript
'scripts' %}
Collect static
==============
...
...
pipeline/jinja2/ext.py
View file @
3bdf1a53
...
...
@@ -7,11 +7,11 @@ from django.contrib.staticfiles.storage import staticfiles_storage
from
pipeline.packager
import
PackageNotFound
from
pipeline.utils
import
guess_type
from
pipeline.templatetags.
compressed
import
Compressed
Mixin
from
pipeline.templatetags.
pipeline
import
Pipeline
Mixin
class
PipelineExtension
(
Compressed
Mixin
,
Extension
):
tags
=
set
([
'
compressed_css'
,
'compressed_js
'
])
class
PipelineExtension
(
Pipeline
Mixin
,
Extension
):
tags
=
set
([
'
stylesheet'
,
'javascript
'
])
def
parse
(
self
,
parser
):
tag
=
next
(
parser
.
stream
)
...
...
@@ -21,10 +21,10 @@ class PipelineExtension(CompressedMixin, Extension):
raise
TemplateSyntaxError
(
"Bad package name"
,
tag
.
lineno
)
args
=
[
package_name
]
if
tag
.
value
==
"
compressed_css
"
:
if
tag
.
value
==
"
stylesheet
"
:
return
nodes
.
CallBlock
(
self
.
call_method
(
'package_css'
,
args
),
[],
[],
[])
.
set_lineno
(
tag
.
lineno
)
if
tag
.
value
==
"
compressed_js
"
:
if
tag
.
value
==
"
javascript
"
:
return
nodes
.
CallBlock
(
self
.
call_method
(
'package_js'
,
args
),
[],
[],
[])
.
set_lineno
(
tag
.
lineno
)
return
[]
...
...
pipeline/templatetags/
compressed
.py
→
pipeline/templatetags/
pipeline
.py
View file @
3bdf1a53
...
...
@@ -6,14 +6,14 @@ from django import template
from
django.template.loader
import
render_to_string
from
django.utils.safestring
import
mark_safe
from
pipeline
.conf
import
settings
from
pipeline
.packager
import
Packager
,
PackageNotFound
from
pipeline
.utils
import
guess_type
from
.
.conf
import
settings
from
.
.packager
import
Packager
,
PackageNotFound
from
.
.utils
import
guess_type
register
=
template
.
Library
()
class
Compressed
Mixin
(
object
):
class
Pipeline
Mixin
(
object
):
def
package_for
(
self
,
package_name
,
package_type
):
package
=
{
'js'
:
getattr
(
settings
,
'PIPELINE_JS'
,
{})
.
get
(
package_name
,
{}),
...
...
@@ -42,7 +42,7 @@ class CompressedMixin(object):
return
method
(
package
,
paths
,
templates
=
templates
)
class
CompressedCSSNode
(
Compressed
Mixin
,
template
.
Node
):
class
StylesheetNode
(
Pipeline
Mixin
,
template
.
Node
):
def
__init__
(
self
,
name
):
self
.
name
=
name
...
...
@@ -68,7 +68,7 @@ class CompressedCSSNode(CompressedMixin, template.Node):
return
'
\n
'
.
join
(
tags
)
class
CompressedJSNode
(
Compressed
Mixin
,
template
.
Node
):
class
JavascriptNode
(
Pipeline
Mixin
,
template
.
Node
):
def
__init__
(
self
,
name
):
self
.
name
=
name
...
...
@@ -104,18 +104,18 @@ class CompressedJSNode(CompressedMixin, template.Node):
@register.tag
def
compressed_css
(
parser
,
token
):
def
stylesheet
(
parser
,
token
):
try
:
tag_name
,
name
=
token
.
split_contents
()
except
ValueError
:
raise
template
.
TemplateSyntaxError
(
'
%
r requires exactly one argument: the name of a group in the PIPELINE_CSS setting'
%
token
.
split_contents
()[
0
])
return
CompressedCSS
Node
(
name
)
return
Stylesheet
Node
(
name
)
@register.tag
def
compressed_js
(
parser
,
token
):
def
javascript
(
parser
,
token
):
try
:
tag_name
,
name
=
token
.
split_contents
()
except
ValueError
:
raise
template
.
TemplateSyntaxError
(
'
%
r requires exactly one argument: the name of a group in the PIPELINE_JS setting'
%
token
.
split_contents
()[
0
])
return
CompressedJS
Node
(
name
)
return
Javascript
Node
(
name
)
tests/tests/test_template.py
View file @
3bdf1a53
...
...
@@ -17,36 +17,36 @@ class JinjaTest(TestCase):
PackageLoader
(
'pipeline'
,
'templates'
))
def
test_no_package
(
self
):
template
=
self
.
env
.
from_string
(
u"""{
%
compressed_css
"unknow"
%
}"""
)
template
=
self
.
env
.
from_string
(
u"""{
%
stylesheet
"unknow"
%
}"""
)
self
.
assertEqual
(
u''
,
template
.
render
())
template
=
self
.
env
.
from_string
(
u"""{
%
compressed_js
"unknow"
%
}"""
)
template
=
self
.
env
.
from_string
(
u"""{
%
javascript
"unknow"
%
}"""
)
self
.
assertEqual
(
u''
,
template
.
render
())
def
test_package_css
(
self
):
template
=
self
.
env
.
from_string
(
u"""{
%
compressed_css
"screen"
%
}"""
)
template
=
self
.
env
.
from_string
(
u"""{
%
stylesheet
"screen"
%
}"""
)
self
.
assertEqual
(
u'<link href="/static/screen.css" rel="stylesheet" type="text/css" />'
,
template
.
render
())
def
test_package_css_disabled
(
self
):
with
pipeline_settings
(
PIPELINE_ENABLED
=
False
):
template
=
self
.
env
.
from_string
(
u"""{
%
compressed_css
"screen"
%
}"""
)
template
=
self
.
env
.
from_string
(
u"""{
%
stylesheet
"screen"
%
}"""
)
self
.
assertEqual
(
u'''<link href="/static/pipeline/css/first.css" rel="stylesheet" type="text/css" />
<link href="/static/pipeline/css/second.css" rel="stylesheet" type="text/css" />
<link href="/static/pipeline/css/urls.css" rel="stylesheet" type="text/css" />'''
,
template
.
render
())
def
test_package_js
(
self
):
template
=
self
.
env
.
from_string
(
u"""{
%
compressed_js
"scripts"
%
}"""
)
template
=
self
.
env
.
from_string
(
u"""{
%
javascript
"scripts"
%
}"""
)
self
.
assertEqual
(
u'<script type="text/javascript" src="/static/scripts.js" charset="utf-8"></script>'
,
template
.
render
())
def
test_package_js_async
(
self
):
template
=
self
.
env
.
from_string
(
u"""{
%
compressed_js
"scripts_async"
%
}"""
)
template
=
self
.
env
.
from_string
(
u"""{
%
javascript
"scripts_async"
%
}"""
)
self
.
assertEqual
(
u'<script async type="text/javascript" src="/static/scripts_async.js" charset="utf-8"></script>'
,
template
.
render
())
def
test_package_js_defer
(
self
):
template
=
self
.
env
.
from_string
(
u"""{
%
compressed_js
"scripts_defer"
%
}"""
)
template
=
self
.
env
.
from_string
(
u"""{
%
javascript
"scripts_defer"
%
}"""
)
self
.
assertEqual
(
u'<script defer type="text/javascript" src="/static/scripts_defer.js" charset="utf-8"></script>'
,
template
.
render
())
def
test_package_js_async_defer
(
self
):
template
=
self
.
env
.
from_string
(
u"""{
%
compressed_js
"scripts_async_defer"
%
}"""
)
template
=
self
.
env
.
from_string
(
u"""{
%
javascript
"scripts_async_defer"
%
}"""
)
self
.
assertEqual
(
u'<script async defer type="text/javascript" src="/static/scripts_async_defer.js" charset="utf-8"></script>'
,
template
.
render
())
...
...
@@ -55,25 +55,25 @@ class DjangoTest(TestCase):
return
Template
(
template
)
.
render
(
Context
())
def
test_compressed_empty
(
self
):
rendered
=
self
.
render_template
(
u"""{
%
load
compressed
%
}{
%
compressed_css
"unknow"
%
}"""
)
rendered
=
self
.
render_template
(
u"""{
%
load
pipeline
%
}{
%
stylesheet
"unknow"
%
}"""
)
self
.
assertEqual
(
u""
,
rendered
)
def
test_compressed_css
(
self
):
rendered
=
self
.
render_template
(
u"""{
%
load
compressed
%
}{
%
compressed_css
"screen"
%
}"""
)
rendered
=
self
.
render_template
(
u"""{
%
load
pipeline
%
}{
%
stylesheet
"screen"
%
}"""
)
self
.
assertEqual
(
u'<link href="/static/screen.css" rel="stylesheet" type="text/css" />'
,
rendered
)
def
test_compressed_js
(
self
):
rendered
=
self
.
render_template
(
u"""{
%
load
compressed
%
}{
%
compressed_js
"scripts"
%
}"""
)
rendered
=
self
.
render_template
(
u"""{
%
load
pipeline
%
}{
%
javascript
"scripts"
%
}"""
)
self
.
assertEqual
(
u'<script type="text/javascript" src="/static/scripts.js" charset="utf-8"></script>'
,
rendered
)
def
test_compressed_js_async
(
self
):
rendered
=
self
.
render_template
(
u"""{
%
load
compressed
%
}{
%
compressed_js
"scripts_async"
%
}"""
)
rendered
=
self
.
render_template
(
u"""{
%
load
pipeline
%
}{
%
javascript
"scripts_async"
%
}"""
)
self
.
assertEqual
(
u'<script async type="text/javascript" src="/static/scripts_async.js" charset="utf-8"></script>'
,
rendered
)
def
test_compressed_js_defer
(
self
):
rendered
=
self
.
render_template
(
u"""{
%
load
compressed
%
}{
%
compressed_js
"scripts_defer"
%
}"""
)
rendered
=
self
.
render_template
(
u"""{
%
load
pipeline
%
}{
%
javascript
"scripts_defer"
%
}"""
)
self
.
assertEqual
(
u'<script defer type="text/javascript" src="/static/scripts_defer.js" charset="utf-8"></script>'
,
rendered
)
def
test_compressed_js_async_defer
(
self
):
rendered
=
self
.
render_template
(
u"""{
%
load
compressed
%
}{
%
compressed_js
"scripts_async_defer"
%
}"""
)
rendered
=
self
.
render_template
(
u"""{
%
load
pipeline
%
}{
%
javascript
"scripts_async_defer"
%
}"""
)
self
.
assertEqual
(
u'<script async defer type="text/javascript" src="/static/scripts_async_defer.js" charset="utf-8"></script>'
,
rendered
)
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