Skip to content

Commit d767ac3

Browse files
author
Buky
authored
Merge pull request #721 from jazzband/css-html-js-minify
Add css-html-js-minify compressor
2 parents 2f98377 + 01081d9 commit d767ac3

File tree

9 files changed

+61
-15
lines changed

9 files changed

+61
-15
lines changed

AUTHORS

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,4 +121,5 @@ or just made Pipeline more awesome.
121121
* Wismill
122122
* Zachary Kazanski <[email protected]>
123123
* Zenobius Jiricek <[email protected]>
124-
* Zeus Kronion
124+
* Zeus Kronion
125+

HISTORY.rst

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,14 @@
33
History
44
=======
55

6+
2.0.4
7+
======
8+
9+
* Adding **css-html-js-minify** support to compress JS and CSS.
10+
* Update compressors documentation with css-html-js-minify.
11+
* Create tests for css-html-js-minify compressor.
12+
* Optimization by grouping the tests yuglify compressor.
13+
614
2.0.3
715
======
816

@@ -36,7 +44,7 @@ History
3644
* Remove tests of uncovered versions of Python and Django.
3745
* Replace tests for Pypy by Pypy3.
3846
* Explicitly specify when files are read / write in binary mode.
39-
* Set opening files for tests to deal with universal newlines.
47+
* Set opening files for tests to deal with universal newlines.
4048
* Upgrade documentation version to 2.0 to follow the project version.
4149

4250
1.7.0

docs/compressors.rst

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@ To us it for your stylesheets add this to your ``PIPELINE['CSS_COMPRESSOR']`` ::
198198

199199
Default to ``'--template=highest'``
200200

201+
201202
CSSMin compressor
202203
=================
203204

@@ -221,6 +222,26 @@ command to compress stylesheets. To use it, add this to your ``PIPELINE['CSS_COM
221222

222223
Default to ``''``
223224

225+
226+
css-html-js-minify compressor
227+
=============================
228+
229+
The css-html-js-minify is full Python compressor using `css-html-js-minify <https://github.com/ciotto/css-html-js-minify>`_
230+
for compressing javascript and stylesheets.
231+
232+
To use it for your stylesheets add this to your ``PIPELINE['CSS_COMPRESSOR']`` ::
233+
234+
PIPELINE['CSS_COMPRESSOR'] = 'pipeline.compressors.csshtmljsminify.CssHtmlJsMinifyCompressor'
235+
236+
To use it for your javascripts add this to your ``PIPELINE['JS_COMPRESSOR']`` ::
237+
238+
PIPELINE['JS_COMPRESSOR'] = 'pipeline.compressors.csshtmljsminify.CssHtmlJsMinifyCompressor'
239+
240+
Install the css-html-js-minify library with your favorite Python package manager ::
241+
242+
pip install css-html-js-minify
243+
244+
224245
No-Op Compressors
225246
=================
226247

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
from pipeline.compressors import CompressorBase
2+
3+
4+
class CssHtmlJsMinifyCompressor(CompressorBase):
5+
"""
6+
CSS, HTML and JS compressor based on the Python library css-html-js-minify
7+
(https://pypi.org/project/css-html-js-minify/).
8+
"""
9+
def compress_css(self, css):
10+
from css_html_js_minify import css_minify
11+
return css_minify(css)
12+
13+
def compress_js(self, js):
14+
from css_html_js_minify import js_minify
15+
return js_minify(js)

setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
setup(
88
name='django-pipeline',
9-
version='2.0.2',
9+
version='2.0.4',
1010
description='Pipeline is an asset packaging library for Django.',
1111
long_description=io.open('README.rst', encoding='utf-8').read() + '\n\n' +
1212
io.open('HISTORY.rst', encoding='utf-8').read(),
@@ -33,7 +33,7 @@
3333
'Programming Language :: Python :: 3.6',
3434
'Programming Language :: Python :: 3.7',
3535
'Programming Language :: Python :: 3.8',
36-
'Programming Language :: Python :: Implementation :: PyPy3',
36+
'Programming Language :: Python :: Implementation :: PyPy',
3737
'Topic :: Utilities',
3838
'Topic :: Software Development :: Libraries :: Python Modules',
3939
'Topic :: Internet :: WWW/HTTP',
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
@charset "utf-8";.concat{display:none}.concatenate{display:block}

tests/assets/compressors/csshtmljsminify.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/tests/test_compressor.py

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -230,20 +230,18 @@ def test_slimit(self):
230230
self._test_compressor('pipeline.compressors.slimit.SlimItCompressor',
231231
'js', 'pipeline/compressors/slimit.js')
232232

233+
def test_csshtmljsminify(self):
234+
self._test_compressor('pipeline.compressors.csshtmljsminify.CssHtmlJsMinifyCompressor',
235+
'css', 'pipeline/compressors/csshtmljsminify.css')
236+
self._test_compressor('pipeline.compressors.csshtmljsminify.CssHtmlJsMinifyCompressor',
237+
'js', 'pipeline/compressors/csshtmljsminify.js')
238+
233239
@skipUnless(settings.HAS_NODE, "requires node")
234-
def test_uglifyjs(self):
235-
self._test_compressor('pipeline.compressors.uglifyjs.UglifyJSCompressor',
236-
'js', 'pipeline/compressors/uglifyjs.js')
237-
238-
@skipUnless(settings.HAS_NODE, "requires node")
239-
def test_yuglify_js(self):
240-
self._test_compressor('pipeline.compressors.yuglify.YuglifyCompressor',
241-
'js', 'pipeline/compressors/yuglify.js')
242-
243-
@skipUnless(settings.HAS_NODE, "requires node")
244-
def test_yuglify_css(self):
240+
def test_yuglify(self):
245241
self._test_compressor('pipeline.compressors.yuglify.YuglifyCompressor',
246242
'css', 'pipeline/compressors/yuglify.css')
243+
self._test_compressor('pipeline.compressors.yuglify.YuglifyCompressor',
244+
'js', 'pipeline/compressors/yuglify.js')
247245

248246
@skipUnless(settings.HAS_NODE, "requires node")
249247
def test_cssmin(self):

tox.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ deps =
2222
jsmin==2.2.0
2323
ply==3.4
2424
slimit==0.8.1
25+
css-html-js-minify==2.5.5
2526
setenv =
2627
DJANGO_SETTINGS_MODULE = tests.settings
2728
PYTHONPATH = {toxinidir}

0 commit comments

Comments
 (0)