Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fix issues raised in review feedback

* django 1.4 is now a requirement
* JINGO_MINIFY_USE_STATIC defaults to True--specify False if you want
  the old ways
  • Loading branch information...
commit 999655913639dc11c076281af58ad6efc8dd70d8 1 parent fb9876a
@willkg willkg authored
View
9 README.rst
@@ -13,6 +13,8 @@ Installing Jingo Minify
Requirements
------------
+* **Django 1.4**
+
* **Jingo and Jinja2**. Jingo Minify is not designed for Django templates.
One of the following:
@@ -55,6 +57,13 @@ Configure the following settings::
}
+Note: If you're using Django 1.4, but want to use MEDIA_ROOT and MEDIA_URL
+for static assets instead of conventional Django 1.4 STATIC_ROOT and
+STATIC_URL, you should also set::
+
+ JINGO_MINIFY_USE_STATIC = False
+
+
Configuring
===========
View
5 examples/minify/settings.py
@@ -5,6 +5,11 @@
ROOT = os.path.dirname(os.path.abspath(__file__))
path = lambda *a: os.path.join(ROOT, *a)
+MEDIA_ROOT = '/media'
+MEDIA_URL = ''
+STATIC_ROOT = '/static'
+STATIC_URL = ''
+
DATABASES = {
'default': {
'NAME': 'test.db',
View
6 jingo_minify/helpers.py
@@ -23,7 +23,7 @@ def get_media_root():
ways, but projects using Django 1.4 to use the new ways.
"""
- if getattr(settings, 'JINGO_MINIFY_USE_STATIC', False):
+ if getattr(settings, 'JINGO_MINIFY_USE_STATIC', True):
return settings.STATIC_ROOT
return settings.MEDIA_ROOT
@@ -35,7 +35,7 @@ def get_media_url():
but projects using Django 1.4 to use the new ways.
"""
- if getattr(settings, 'JINGO_MINIFY_USE_STATIC', False):
+ if getattr(settings, 'JINGO_MINIFY_USE_STATIC', True):
return settings.STATIC_URL
return settings.MEDIA_URL
@@ -151,7 +151,7 @@ def ensure_path_exists(path):
except OSError as e:
# If the directory already exists, that is fine. Otherwise re-raise.
if e.errno != os.errno.EEXIST:
- raise e
+ raise
def build_less(item):
View
2  jingo_minify/management/commands/compress_assets.py
@@ -12,7 +12,7 @@
import git
-from jingo_minify.helpers import get_media_root, get_media_url
+from jingo_minify.helpers import get_media_root
path = lambda *a: os.path.join(get_media_root(), *a)
View
166 jingo_minify/tests.py
@@ -1,5 +1,6 @@
from django.conf import settings
from django.test import TestCase
+from django.test.utils import override_settings
import jingo
from mock import patch
@@ -32,7 +33,7 @@ def test_js_helper(time):
s = t.render()
expected = "\n".join(['<script src="%s?build=1"></script>'
- % (settings.MEDIA_URL + j) for j in
+ % (settings.STATIC_URL + j) for j in
settings.MINIFY_BUNDLES['js']['common']])
eq_(s, expected)
@@ -41,7 +42,7 @@ def test_js_helper(time):
s = t.render()
eq_(s, '<script src="%sjs/common-min.js?build=%s"></script>' %
- (settings.MEDIA_URL, BUILD_ID_JS))
+ (settings.STATIC_URL, BUILD_ID_JS))
t = env.from_string("{{ js('common_url', debug=True) }}")
s = t.render()
@@ -53,7 +54,7 @@ def test_js_helper(time):
s = t.render()
eq_(s, '<script src="%sjs/common_url-min.js?build=%s"></script>' %
- (settings.MEDIA_URL, BUILD_ID_JS))
+ (settings.STATIC_URL, BUILD_ID_JS))
t = env.from_string("{{ js('common_protocol_less_url', debug=True) }}")
s = t.render()
@@ -65,7 +66,7 @@ def test_js_helper(time):
s = t.render()
eq_(s, '<script src="%sjs/common_protocol_less_url-min.js?build=%s">'
- '</script>' % (settings.MEDIA_URL, BUILD_ID_JS))
+ '</script>' % (settings.STATIC_URL, BUILD_ID_JS))
t = env.from_string("{{ js('common_bundle', debug=True) }}")
s = t.render()
@@ -79,7 +80,7 @@ def test_js_helper(time):
s = t.render()
eq_(s, '<script src="%sjs/common_bundle-min.js?build=%s"></script>' %
- (settings.MEDIA_URL, BUILD_ID_JS))
+ (settings.STATIC_URL, BUILD_ID_JS))
@patch('jingo_minify.helpers.time.time')
@@ -98,8 +99,8 @@ def test_css_helper(time):
expected ="\n".join(
['<link rel="stylesheet" media="screen,projection,tv" '
- 'href="%s?build=1" />' % (settings.MEDIA_URL + j) for j in
- settings.MINIFY_BUNDLES['css']['common']])
+ 'href="%s?build=1" />' % (settings.STATIC_URL + j)
+ for j in settings.MINIFY_BUNDLES['css']['common']])
eq_(s, expected)
@@ -109,7 +110,7 @@ def test_css_helper(time):
eq_(s,
'<link rel="stylesheet" media="screen,projection,tv" '
'href="%scss/common-min.css?build=%s" />'
- % (settings.MEDIA_URL, BUILD_ID_CSS))
+ % (settings.STATIC_URL, BUILD_ID_CSS))
t = env.from_string("{{ css('common_url', debug=True) }}")
s = t.render()
@@ -123,7 +124,7 @@ def test_css_helper(time):
eq_(s,
'<link rel="stylesheet" media="screen,projection,tv" '
'href="%scss/common_url-min.css?build=%s" />'
- % (settings.MEDIA_URL, BUILD_ID_CSS))
+ % (settings.STATIC_URL, BUILD_ID_CSS))
t = env.from_string("{{ css('common_protocol_less_url', debug=True) }}")
s = t.render()
@@ -137,7 +138,7 @@ def test_css_helper(time):
eq_(s,
'<link rel="stylesheet" media="screen,projection,tv" '
'href="%scss/common_protocol_less_url-min.css?build=%s" />'
- % (settings.MEDIA_URL, BUILD_ID_CSS))
+ % (settings.STATIC_URL, BUILD_ID_CSS))
t = env.from_string("{{ css('common_bundle', debug=True) }}")
s = t.render()
@@ -156,87 +157,64 @@ def test_css_helper(time):
eq_(s, '<link rel="stylesheet" media="screen,projection,tv" '
'href="%scss/common_bundle-min.css?build=%s" />' %
- (settings.MEDIA_URL, BUILD_ID_CSS))
-
-
-KEY = '_SAVESETTING'
-
-class TestStaticVsMedia(TestCase):
- def override_settings(self, **overrides):
- for k, v in overrides.items():
- # Save the original setting.
- setattr(self, '%s%s' % (KEY, k), getattr(settings, k, None))
- # Save the new setting.
- setattr(settings, k, v)
-
- def backout_overrides(self):
- for k, v in self.__dict__.items():
- if k.startswith(KEY):
- key = k[len(KEY):]
- if v is None:
- delattr(settings, key)
- else:
- setattr(settings, key, v)
-
- def tearDown(self):
- self.backout_overrides()
-
- def test_no_override(self):
- self.override_settings(STATIC_ROOT='static',
- MEDIA_ROOT='media',
- STATIC_URL='http://example.com/static',
- MEDIA_URL='http://example.com/media')
-
- eq_(get_media_root(), 'media')
- eq_(get_media_url(), 'http://example.com/media')
-
- def test_static_override(self):
- self.override_settings(JINGO_MINIFY_USE_STATIC=True,
- STATIC_ROOT='static',
- MEDIA_ROOT='media',
- STATIC_URL='http://example.com/static',
- MEDIA_URL='http://example.com/media')
-
- eq_(get_media_root(), 'static')
- eq_(get_media_url(), 'http://example.com/static')
-
- @patch('jingo_minify.helpers.time.time')
- def test_css(self, time):
- self.override_settings(JINGO_MINIFY_USE_STATIC=True,
- STATIC_ROOT='static',
- MEDIA_ROOT='media',
- STATIC_URL='http://example.com/static/',
- MEDIA_URL='http://example.com/media/')
-
- time.return_value = 1
- env = jingo.env
-
- t = env.from_string("{{ css('common', debug=True) }}")
- s = t.render()
-
- expected ="\n".join(
- ['<link rel="stylesheet" media="screen,projection,tv" '
- 'href="%s?build=1" />' % (settings.STATIC_URL + j)
- for j in settings.MINIFY_BUNDLES['css']['common']])
-
- eq_(s, expected)
-
- @patch('jingo_minify.helpers.time.time')
- def test_js(self, time):
- self.override_settings(JINGO_MINIFY_USE_STATIC=True,
- STATIC_ROOT='static',
- MEDIA_ROOT='media',
- STATIC_URL='http://example.com/static/',
- MEDIA_URL='http://example.com/media/')
-
- time.return_value = 1
- env = jingo.env
-
- t = env.from_string("{{ js('common', debug=True) }}")
- s = t.render()
-
- expected = "\n".join(
- ['<script src="%s?build=1"></script>' % (settings.STATIC_URL + j)
- for j in settings.MINIFY_BUNDLES['js']['common']])
-
- eq_(s, expected)
+ (settings.STATIC_URL, BUILD_ID_CSS))
+
+
+@override_settings(STATIC_ROOT='static',
+ MEDIA_ROOT='media',
+ STATIC_URL='http://example.com/static',
+ MEDIA_URL='http://example.com/media')
+def test_no_override():
+ """No override uses STATIC versions."""
+ eq_(get_media_root(), 'static')
+ eq_(get_media_url(), 'http://example.com/static')
+
+
+@override_settings(JINGO_MINIFY_USE_STATIC=False,
+ STATIC_ROOT='static',
+ MEDIA_ROOT='media',
+ STATIC_URL='http://example.com/static',
+ MEDIA_URL='http://example.com/media')
+def test_static_override():
+ """Overriding to False uses MEDIA versions."""
+ eq_(get_media_root(), 'media')
+ eq_(get_media_url(), 'http://example.com/media')
+
+
+@override_settings(STATIC_ROOT='static',
+ MEDIA_ROOT='media',
+ STATIC_URL='http://example.com/static/',
+ MEDIA_URL='http://example.com/media/')
+@patch('jingo_minify.helpers.time.time')
+def test_css(time):
+ time.return_value = 1
+ env = jingo.env
+
+ t = env.from_string("{{ css('common', debug=True) }}")
+ s = t.render()
+
+ expected ="\n".join(
+ ['<link rel="stylesheet" media="screen,projection,tv" '
+ 'href="%s?build=1" />' % (settings.STATIC_URL + j)
+ for j in settings.MINIFY_BUNDLES['css']['common']])
+
+ eq_(s, expected)
+
+
+@override_settings(STATIC_ROOT='static',
+ MEDIA_ROOT='media',
+ STATIC_URL='http://example.com/static/',
+ MEDIA_URL='http://example.com/media/')
+@patch('jingo_minify.helpers.time.time')
+def test_js(time):
+ time.return_value = 1
+ env = jingo.env
+
+ t = env.from_string("{{ js('common', debug=True) }}")
+ s = t.render()
+
+ expected = "\n".join(
+ ['<script src="%s?build=1"></script>' % (settings.STATIC_URL + j)
+ for j in settings.MINIFY_BUNDLES['js']['common']])
+
+ eq_(s, expected)
View
9 requirements.txt
@@ -1,6 +1,5 @@
-Django==1.3.1
+Django==1.4.1
jingo==0.4
-Fabric==1.0.1
-nose==1.0.0
--e git://github.com/jbalogh/django-nose.git@83c7867c3f90#egg=django-nose
-mock==0.8.0
+Fabric==1.4.3
+-e git://github.com/jbalogh/django-nose.git@83c7867c3f90ff3c7c7471716da91b643e8b2c01#egg=django_nose-dev
+mock==1.0b1
Please sign in to comment.
Something went wrong with that request. Please try again.