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
9aa44e53
Commit
9aa44e53
authored
Jan 14, 2012
by
Timothée Peignier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add defaut template function. close #12
parent
f52ae576
Hide whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
19 additions
and
43 deletions
+19
-43
pipeline/compressors/__init__.py
+5
-0
pipeline/conf/settings.py
+1
-1
pipeline/manifest.py
+0
-2
pipeline/packager.py
+0
-3
tests/assets/css/first.css
+1
-2
tests/assets/css/second.css
+1
-2
tests/assets/js/application.js
+1
-2
tests/assets/js/first.js
+1
-2
tests/assets/js/second.js
+1
-2
tests/settings.py
+0
-1
tests/tests/compressor.py
+5
-5
tests/tests/packager.py
+0
-20
tests/tests/storage.py
+3
-1
No files found.
pipeline/compressors/__init__.py
View file @
9aa44e53
...
...
@@ -19,6 +19,9 @@ MHTML_START = "/*\r\nContent-Type: multipart/related; boundary=\"MHTML_MARK\"\r\
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;};"""
MIME_TYPES
=
{
'.png'
:
'image/png'
,
'.jpg'
:
'image/jpeg'
,
...
...
@@ -95,8 +98,10 @@ class Compressor(object):
settings
.
PIPELINE_TEMPLATE_FUNC
,
contents
)
compiler
=
TEMPLATE_FUNC
if
settings
.
PIPELINE_TEMPLATE_FUNC
==
DEFAULT_TEMPLATE_FUNC
else
""
return
"
\n
"
.
join
([
"
%(namespace)
s =
%(namespace)
s || {};"
%
{
'namespace'
:
namespace
},
compiler
,
compiled
])
...
...
pipeline/conf/settings.py
View file @
9aa44e53
...
...
@@ -22,7 +22,7 @@ PIPELINE_JS = getattr(settings, 'PIPELINE_JS', {})
PIPELINE_TEMPLATE_NAMESPACE
=
getattr
(
settings
,
'PIPELINE_TEMPLATE_NAMESPACE'
,
"window.JST"
)
PIPELINE_TEMPLATE_EXT
=
getattr
(
settings
,
'PIPELINE_TEMPLATE_EXT'
,
".jst"
)
PIPELINE_TEMPLATE_FUNC
=
getattr
(
settings
,
'PIPELINE_TEMPLATE_FUNC'
,
"
_.
template"
)
PIPELINE_TEMPLATE_FUNC
=
getattr
(
settings
,
'PIPELINE_TEMPLATE_FUNC'
,
"template"
)
PIPELINE_CSSTIDY_BINARY
=
getattr
(
settings
,
'PIPELINE_CSSTIDY_BINARY'
,
'/usr/local/bin/csstidy'
)
PIPELINE_CSSTIDY_ARGUMENTS
=
getattr
(
settings
,
'PIPELINE_CSSTIDY_ARGUMENTS'
,
'--template=highest'
)
...
...
pipeline/manifest.py
View file @
9aa44e53
import
os
try
:
from
staticfiles.finders
import
DefaultStorageFinder
except
ImportError
:
...
...
pipeline/packager.py
View file @
9aa44e53
import
os
import
urlparse
from
django.core.files.base
import
ContentFile
from
pipeline.conf
import
settings
...
...
tests/assets/css/first.css
View file @
9aa44e53
.concat
{
display
:
none
;
}
\ No newline at end of file
}
tests/assets/css/second.css
View file @
9aa44e53
.concatenate
{
display
:
block
;
}
\ No newline at end of file
}
tests/assets/js/application.js
View file @
9aa44e53
function
()
{
alert
(
'this is a test'
);
}
\ No newline at end of file
}
tests/assets/js/first.js
View file @
9aa44e53
function
concat
()
{
console
.
log
(
arguments
);
}
\ No newline at end of file
}
tests/assets/js/second.js
View file @
9aa44e53
function
cat
()
{
console
.
log
(
"hello world"
);
}
\ No newline at end of file
}
tests/settings.py
View file @
9aa44e53
...
...
@@ -36,7 +36,6 @@ STATICFILES_FINDERS = (
)
PIPELINE_ROOT
=
local_path
(
'assets/'
)
PIPELINE_TEMPLATE_EXT
=
".jst"
TEMPLATE_DIRS
=
(
local_path
(
'templates'
),
...
...
tests/tests/compressor.py
View file @
9aa44e53
...
...
@@ -6,7 +6,7 @@ from mock import patch
from
django.test
import
TestCase
from
pipeline.conf
import
settings
from
pipeline.compressors
import
Compressor
from
pipeline.compressors
import
Compressor
,
TEMPLATE_FUNC
from
pipeline.compressors.yui
import
YUICompressor
...
...
@@ -26,14 +26,14 @@ class CompressorTest(TestCase):
'css/first.css'
,
'css/second.css'
])
self
.
assertEquals
(
""".concat {
\n
display: none;
\n
}
\n
.concatenate {
\n
display: block;
\n
}
"""
,
css
)
self
.
assertEquals
(
""".concat {
\n
display: none;
\n
}
\n
\n
.concatenate {
\n
display: block;
\n
}
\n
"""
,
css
)
def
test_concatenate
(
self
):
js
=
self
.
compressor
.
concatenate
([
'js/first.js'
,
'js/second.js'
])
self
.
assertEquals
(
"""function concat() {
\n
console.log(arguments);
\n
}
\n
function cat() {
\n
console.log("hello world");
\n
}
"""
,
js
)
self
.
assertEquals
(
"""function concat() {
\n
console.log(arguments);
\n
}
\n
\n
function cat() {
\n
console.log("hello world");
\n
}
\n
"""
,
js
)
@patch.object
(
base64
,
'b64encode'
)
def
test_encoded_content
(
self
,
mock
):
...
...
@@ -71,12 +71,12 @@ class CompressorTest(TestCase):
def
test_compile_templates
(
self
):
templates
=
self
.
compressor
.
compile_templates
([
'templates/photo/list.jst'
])
self
.
assertEquals
(
templates
,
"""window.JST = window.JST || {};
\n
window.JST['list'] = _.template('<div class="photo"> <img src="<
%
= src
%
>" /> <div class="caption"> <
%
= caption
%
> </div></div>');
\n
"""
)
self
.
assertEquals
(
templates
,
"""window.JST = window.JST || {};
\n
%
s
\n
window.JST['list'] = template('<div class="photo"> <img src="<
%%
= src
%%
>" /> <div class="caption"> <
%%
= caption
%%
> </div></div>');
\n
"""
%
TEMPLATE_FUNC
)
templates
=
self
.
compressor
.
compile_templates
([
'templates/video/detail.jst'
,
'templates/photo/detail.jst'
])
self
.
assertEqual
(
templates
,
"""window.JST = window.JST || {};
\n
window.JST['video_detail'] = _.template('<div class="video"> <video src="<
%
= src
%
>" /> <div class="caption"> <
%
= description
%
> </div></div>');
\n
window.JST[
\'
photo_detail
\'
] = _.template(
\'
<div class="photo"> <img src="<
%
= src
%
>" /> <div class="caption"> <
%
= caption
%
> by <
%
= author
%
> </div></div>
\'
);
\n
"""
)
self
.
assertEqual
(
templates
,
"""window.JST = window.JST || {};
\n
%
s
\n
window.JST['video_detail'] = template('<div class="video"> <video src="<
%%
= src
%%
>" /> <div class="caption"> <
%%
= description
%%
> </div></div>');
\n
window.JST[
\'
photo_detail
\'
] = template(
\'
<div class="photo"> <img src="<
%%
= src
%%
>" /> <div class="caption"> <
%%
= caption
%%
> by <
%%
= author
%%
> </div></div>
\'
);
\n
"""
%
TEMPLATE_FUNC
)
def
test_embeddable
(
self
):
self
.
assertFalse
(
self
.
compressor
.
embeddable
(
'images/sprite.png'
,
None
))
...
...
tests/tests/packager.py
View file @
9aa44e53
import
os
from
django.test
import
TestCase
from
pipeline.conf
import
settings
from
pipeline.packager
import
Packager
,
PackageNotFound
...
...
@@ -38,20 +35,3 @@ class PackagerTest(TestCase):
}
})
self
.
assertEqual
(
packages
[
'templates'
]
.
templates
,
[
'templates/photo/list.jst'
])
def
test_individual_url
(
self
):
"""Check that individual URL is correctly generated"""
packager
=
Packager
()
filename
=
os
.
path
.
join
(
settings
.
PIPELINE_ROOT
,
u'js/application.js'
)
individual_url
=
packager
.
individual_url
(
filename
)
self
.
assertEqual
(
individual_url
,
"/static/js/application.js"
)
def
test_periods_safe_individual_url
(
self
):
"""Check that the periods in file names do not get replaced by individual_url when
PIPELINE_ROOT/STATIC_ROOT is not set, such as in development
"""
settings
.
PIPELINE_ROOT
=
settings
.
STATIC_ROOT
=
settings
.
MEDIA_ROOT
=
""
packager
=
Packager
()
filename
=
os
.
path
.
join
(
settings
.
PIPELINE_ROOT
,
u'js/application.js'
)
individual_url
=
packager
.
individual_url
(
filename
)
self
.
assertEqual
(
individual_url
,
"/static/js/application.js"
)
tests/tests/storage.py
View file @
9aa44e53
...
...
@@ -13,8 +13,10 @@ class StorageTest(TestCase):
),
'manifest'
:
False
,
'output_filename'
:
'testing.css'
,
}
}
}
settings
.
PIPELINE_JS_COMPRESSOR
=
None
settings
.
PIPELINE_CSS_COMPRESSOR
=
None
self
.
storage
=
PipelineStorage
()
def
test_post_process_dry_run
(
self
):
...
...
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