Skip to content

Commit

Permalink
Merge pull request #721 from jazzband/css-html-js-minify
Browse files Browse the repository at this point in the history
Add css-html-js-minify compressor
  • Loading branch information
Buky committed May 29, 2020
2 parents 2f98377 + 01081d9 commit d767ac3
Show file tree
Hide file tree
Showing 9 changed files with 61 additions and 15 deletions.
3 changes: 2 additions & 1 deletion AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -121,4 +121,5 @@ or just made Pipeline more awesome.
* Wismill
* Zachary Kazanski <[email protected]>
* Zenobius Jiricek <[email protected]>
* Zeus Kronion
* Zeus Kronion

10 changes: 9 additions & 1 deletion HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@
History
=======

2.0.4
======

* Adding **css-html-js-minify** support to compress JS and CSS.
* Update compressors documentation with css-html-js-minify.
* Create tests for css-html-js-minify compressor.
* Optimization by grouping the tests yuglify compressor.

2.0.3
======

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

1.7.0
Expand Down
21 changes: 21 additions & 0 deletions docs/compressors.rst
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ To us it for your stylesheets add this to your ``PIPELINE['CSS_COMPRESSOR']`` ::

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


CSSMin compressor
=================

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

Default to ``''``


css-html-js-minify compressor
=============================

The css-html-js-minify is full Python compressor using `css-html-js-minify <https://github.com/ciotto/css-html-js-minify>`_
for compressing javascript and stylesheets.

To use it for your stylesheets add this to your ``PIPELINE['CSS_COMPRESSOR']`` ::

PIPELINE['CSS_COMPRESSOR'] = 'pipeline.compressors.csshtmljsminify.CssHtmlJsMinifyCompressor'

To use it for your javascripts add this to your ``PIPELINE['JS_COMPRESSOR']`` ::

PIPELINE['JS_COMPRESSOR'] = 'pipeline.compressors.csshtmljsminify.CssHtmlJsMinifyCompressor'

Install the css-html-js-minify library with your favorite Python package manager ::

pip install css-html-js-minify


No-Op Compressors
=================

Expand Down
15 changes: 15 additions & 0 deletions pipeline/compressors/csshtmljsminify.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from pipeline.compressors import CompressorBase


class CssHtmlJsMinifyCompressor(CompressorBase):
"""
CSS, HTML and JS compressor based on the Python library css-html-js-minify
(https://pypi.org/project/css-html-js-minify/).
"""
def compress_css(self, css):
from css_html_js_minify import css_minify
return css_minify(css)

def compress_js(self, js):
from css_html_js_minify import js_minify
return js_minify(js)
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

setup(
name='django-pipeline',
version='2.0.2',
version='2.0.4',
description='Pipeline is an asset packaging library for Django.',
long_description=io.open('README.rst', encoding='utf-8').read() + '\n\n' +
io.open('HISTORY.rst', encoding='utf-8').read(),
Expand All @@ -33,7 +33,7 @@
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: Implementation :: PyPy3',
'Programming Language :: Python :: Implementation :: PyPy',
'Topic :: Utilities',
'Topic :: Software Development :: Libraries :: Python Modules',
'Topic :: Internet :: WWW/HTTP',
Expand Down
1 change: 1 addition & 0 deletions tests/assets/compressors/csshtmljsminify.css
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@charset "utf-8";.concat{display:none}.concatenate{display:block}
1 change: 1 addition & 0 deletions tests/assets/compressors/csshtmljsminify.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 9 additions & 11 deletions tests/tests/test_compressor.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,20 +230,18 @@ def test_slimit(self):
self._test_compressor('pipeline.compressors.slimit.SlimItCompressor',
'js', 'pipeline/compressors/slimit.js')

def test_csshtmljsminify(self):
self._test_compressor('pipeline.compressors.csshtmljsminify.CssHtmlJsMinifyCompressor',
'css', 'pipeline/compressors/csshtmljsminify.css')
self._test_compressor('pipeline.compressors.csshtmljsminify.CssHtmlJsMinifyCompressor',
'js', 'pipeline/compressors/csshtmljsminify.js')

@skipUnless(settings.HAS_NODE, "requires node")
def test_uglifyjs(self):
self._test_compressor('pipeline.compressors.uglifyjs.UglifyJSCompressor',
'js', 'pipeline/compressors/uglifyjs.js')

@skipUnless(settings.HAS_NODE, "requires node")
def test_yuglify_js(self):
self._test_compressor('pipeline.compressors.yuglify.YuglifyCompressor',
'js', 'pipeline/compressors/yuglify.js')

@skipUnless(settings.HAS_NODE, "requires node")
def test_yuglify_css(self):
def test_yuglify(self):
self._test_compressor('pipeline.compressors.yuglify.YuglifyCompressor',
'css', 'pipeline/compressors/yuglify.css')
self._test_compressor('pipeline.compressors.yuglify.YuglifyCompressor',
'js', 'pipeline/compressors/yuglify.js')

@skipUnless(settings.HAS_NODE, "requires node")
def test_cssmin(self):
Expand Down
1 change: 1 addition & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ deps =
jsmin==2.2.0
ply==3.4
slimit==0.8.1
css-html-js-minify==2.5.5
setenv =
DJANGO_SETTINGS_MODULE = tests.settings
PYTHONPATH = {toxinidir}
Expand Down

0 comments on commit d767ac3

Please sign in to comment.