Skip to content

Commit

Permalink
More cleanup and version bump (v0.5)
Browse files Browse the repository at this point in the history
  • Loading branch information
James Socol committed Oct 31, 2011
1 parent 1809838 commit 5d92974
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 15 deletions.
31 changes: 31 additions & 0 deletions CHANGES.rst
@@ -0,0 +1,31 @@
=========
CHANGELOG
=========

0.5
===

* Add support for UglifyJS_ and clean-css_.
* Support cache-busting images in CSS.
* Add --update-only option.
* Print out more info with --verbosity.
* Only minify changed files.
* Clean-up and refactor.


.. _UglifyJS: http://marijnhaverbeke.nl/uglifyjs
.. _clean-css: https://github.com/GoalSmashers/clean-css


0.4
===

* Add support for LESS_.

.. _LESS: http://lesscss.org/


0.3.2
=====

* Upgrade to YUICompressor 2.4.4.
1 change: 1 addition & 0 deletions MANIFEST.in
@@ -1,4 +1,5 @@
include LICENSE
include CONTRIBUTORS
include README.rst
include CHANGES.rst
include jingo_minify/bin/yuicompressor-2.4.2.jar
4 changes: 2 additions & 2 deletions jingo_minify/helpers.py
Expand Up @@ -37,7 +37,7 @@ def js(bundle, debug=settings.TEMPLATE_DEBUG):
build_id = BUNDLE_HASHES[bundle_full]
items = ("js/%s-min.js?build=%s" % (bundle, build_id,),)

return _build_html(items, """<script src="%s"></script>""")
return _build_html(items, '<script src="%s"></script>')


@register.function
Expand All @@ -64,7 +64,7 @@ def css(bundle, media="screen,projection,tv", debug=settings.TEMPLATE_DEBUG):
items = ("css/%s-min.css?build=%s" % (bundle, build_id,),)

return _build_html(items,
"""<link rel="stylesheet" media="%s" href="%%s" />""" % media)
'<link rel="stylesheet" media="%s" href="%%s" />' % media)

def build_less(item):
path_css = path('%s.css' % item)
Expand Down
14 changes: 7 additions & 7 deletions jingo_minify/management/commands/compress_assets.py
Expand Up @@ -106,7 +106,7 @@ def handle(self, **options):
self.minify_skipped)

def _preprocess_file(self, filename):
""" Preprocess files and return new filenames. """
"""Preprocess files and return new filenames."""
if filename.endswith('.less'):
fp = path(filename.lstrip('/'))
call('%s %s %s.css' % (settings.LESS_BIN, fp, fp),
Expand All @@ -115,7 +115,7 @@ def _preprocess_file(self, filename):
return path(filename.lstrip('/'))

def _is_changed(self, concatted_file):
""" Check if the file has been changed. """
"""Check if the file has been changed."""
tmp_concatted = '%s.tmp' % concatted_file
if (os.path.exists(concatted_file) and
os.path.getsize(concatted_file) == os.path.getsize(tmp_concatted)):
Expand All @@ -125,14 +125,14 @@ def _is_changed(self, concatted_file):
return True # Different filesize, so it was definitely changed

def _clean_tmp(self, concatted_file):
""" Replace the old file with the temp file. """
"""Replace the old file with the temp file."""
tmp_concatted = '%s.tmp' % concatted_file
if os.path.exists(concatted_file):
os.remove(concatted_file)
os.rename(tmp_concatted, concatted_file)

def _cachebust(self, css_file, bundle_name):
""" Cache bust images. Return a new bundle hash. """
"""Cache bust images. Return a new bundle hash."""
print "Cache busting images in %s" % re.sub('.tmp$', '', css_file)

css_content = ''
Expand All @@ -157,7 +157,7 @@ def _cachebust(self, css_file, bundle_name):
return file_hash

def _minify(self, ftype, file_in, file_out):
""" Run the proper minifier on the file. """
"""Run the proper minifier on the file."""
if ftype == 'js' and hasattr(settings, 'UGLIFY_BIN'):
o = {'method': 'UglifyJS', 'bin': settings.UGLIFY_BIN}
call("%s %s -nc -o %s %s" % (o['bin'], self.v, file_out, file_in),
Expand All @@ -175,7 +175,7 @@ def _minify(self, ftype, file_in, file_out):
print "Minifying %s (using %s)" % (file_in, o['method'])

def _file_hash(self, url):
""" Open the file and get a hash of it. """
"""Open the file and get a hash of it."""
if url in self.checked_hash:
return self.checked_hash[url]

Expand All @@ -192,7 +192,7 @@ def _file_hash(self, url):
return file_hash

def _cachebust_regex(self, img, parent):
""" Run over the regex; img is the structural regex object. """
"""Run over the regex; img is the structural regex object."""
url = img.group(1).strip('"\'')
if url.startswith('data:') or url.startswith('http'):
return "url(%s)" % url
Expand Down
12 changes: 7 additions & 5 deletions jingo_minify/tests.py
Expand Up @@ -9,9 +9,11 @@
except:
BUILD_ID_CSS = BUILD_ID_JS = 'dev'


def setup():
jingo.load_helpers()


def test_js_helper():
"""
Given the js() tag if we return the assets that make up that bundle
Expand All @@ -25,15 +27,15 @@ def test_js_helper():
t = env.from_string("{{ js('common', debug=True) }}")
s = t.render()

expected ="\n".join(["""<script src="%s"></script>""" % (settings.MEDIA_URL + j)
expected ="\n".join(['<script src="%s"></script>' % (settings.MEDIA_URL + j)
for j in settings.MINIFY_BUNDLES['js']['common']])

eq_(s, expected)

t = env.from_string("{{ js('common', debug=False) }}")
s = t.render()

eq_(s, """<script src="%s"></script>""" %
eq_(s, '<script src="%s"></script>' %
(settings.MEDIA_URL + "js/common-min.js?build=%s" % BUILD_ID_JS))


Expand All @@ -50,7 +52,7 @@ def test_css_helper():
s = t.render()

expected ="\n".join(
["""<link rel="stylesheet" media="screen,projection,tv" href="%s" />"""
['<link rel="stylesheet" media="screen,projection,tv" href="%s" />'
% (settings.MEDIA_URL + j) for j in
settings.MINIFY_BUNDLES['css']['common']])

Expand All @@ -60,5 +62,5 @@ def test_css_helper():
s = t.render()

eq_(s,
"""<link rel="stylesheet" media="screen,projection,tv" href="%s" />"""
% (settings.MEDIA_URL + "css/common-min.css?build=%s" % BUILD_ID_CSS))
'<link rel="stylesheet" media="screen,projection,tv" href="%s" />'
% (settings.MEDIA_URL + 'css/common-min.css?build=%s' % BUILD_ID_CSS))
3 changes: 2 additions & 1 deletion setup.py
Expand Up @@ -2,8 +2,9 @@

setup(
name='jingo_minify',
version='0.4',
version='0.5',
description='A Django app that will concat and minify JS and CSS.',
long_description=open('README.rst').read(),
author='Dave Dash, James Socol',
author_email='dd@mozilla.com, james@mozilla.com',
url='http://github.com/jsocol/jingo-minify',
Expand Down

0 comments on commit 5d92974

Please sign in to comment.