Skip to content

Commit

Permalink
Upgrade clean-css
Browse files Browse the repository at this point in the history
In order to upgrade clean-css it is necessary to import the filter
definition from the future version of webassets. This version takes
extra arguments in the filter configuration, allowing us to disable
the advanced optimizations that became the default in 3.0+ but that
breaks some of our styles.
  • Loading branch information
tilgovi committed Aug 20, 2015
1 parent 90026dd commit c6cbd3e
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 1 deletion.
1 change: 1 addition & 0 deletions conf/production.ini
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ webassets.static_view: True
webassets.browserify_bin: ./node_modules/.bin/browserify
webassets.browserify_extra_args: --extension=.coffee --transform coffeeify
webassets.cleancss_bin: ./node_modules/.bin/cleancss
webassets.cleancss_extra_args: --skip-advanced --skip-rebase
webassets.uglifyjs_bin: ./node_modules/.bin/uglifyjs


Expand Down
40 changes: 40 additions & 0 deletions h/assets.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# -*- coding: utf-8 -*-
import os
import re

from deform.field import Field
Expand Down Expand Up @@ -36,6 +37,45 @@ def input(self, in_, out, **kwargs):
register_filter(Browserify)


# The release versions of webassets upstream don't support extra arguments yet.
class CleanCSS(ExternalTool):
"""
Minify css using `Clean-css <https://github.com/GoalSmashers/clean-css/>`_.
Clean-css is an external tool written for NodeJS; this filter assumes that
the ``cleancss`` executable is in the path. Otherwise, you may define
a ``CLEANCSS_BIN`` setting.
Additional options may be passed to ``cleancss`` binary using the setting
``CLEANCSS_EXTRA_ARGS``, which expects a list of strings.
"""

name = 'cleancss'
options = {
'binary': 'CLEANCSS_BIN',
'extra_args': 'CLEANCSS_EXTRA_ARGS',
}

def output(self, _in, out, **kw):
args = [self.binary or 'cleancss']
if self.extra_args:
if isinstance(self.extra_args, basestring):
self.extra_args = self.extra_args.split()
args.extend(self.extra_args)
self.subprocess(args, out, _in)

def input(self, _in, out, **kw):
args = [self.binary or 'cleancss', '--root',
os.path.dirname(kw['source_path'])]
if self.extra_args:
if isinstance(self.extra_args, basestring):
self.extra_args = self.extra_args.split()
args.extend(self.extra_args)
self.subprocess(args, out, _in)

register_filter(CleanCSS)


class WebassetsResourceRegistry(object):

def __init__(self, env):
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"browserify": "^9.0.3",
"browserify-ngannotate": "^1.0.1",
"browserify-shim": "^3.8.3",
"clean-css": "2.2.2",
"clean-css": "3.3.9",
"coffee-script": "1.7.1",
"coffeeify": "^1.0.0",
"diff-match-patch": "^1.0.0",
Expand Down

0 comments on commit c6cbd3e

Please sign in to comment.