Merge branch 'hotfix/0.9.1' into develop

This commit is contained in:
Jannis Leidel
2011-05-19 11:29:58 +02:00
6 changed files with 122 additions and 115 deletions

View File

@@ -1,4 +1,4 @@
VERSION = (0, 9, 0, "f", 0) # following PEP 386
VERSION = (0, 9, 1, "f", 0) # following PEP 386
DEV_N = None

View File

@@ -2,6 +2,7 @@ import os
from django.core.files.base import ContentFile
from django.template.loader import render_to_string
from django.utils.encoding import smart_unicode
from compressor.cache import get_hexdigest, get_mtime
from compressor.conf import settings
@@ -94,7 +95,7 @@ class Compressor(object):
if kind == SOURCE_HUNK:
content = self.filter(value, METHOD_INPUT,
elem=elem, kind=kind, basename=basename)
yield unicode(content)
yield smart_unicode(content)
elif kind == SOURCE_FILE:
content = ""
fd = open(value, 'rb')
@@ -109,7 +110,7 @@ class Compressor(object):
filename=value, basename=basename, elem=elem, kind=kind)
attribs = self.parser.elem_attribs(elem)
charset = attribs.get("charset", self.charset)
yield unicode(content, charset)
yield smart_unicode(content, charset.lower())
@cached_property
def concat(self):

View File

@@ -1,3 +1,112 @@
from compressor.settings import CompressorSettings
import os
from django import VERSION as DJANGO_VERSION
from django.conf import settings as global_settings
from django.core.exceptions import ImproperlyConfigured
from compressor.utils.settings import AppSettings
class CompressorSettings(AppSettings):
# Main switch
ENABLED = not global_settings.DEBUG
# Allows changing verbosity from the settings.
VERBOSE = False
# GET variable that disables compressor e.g. "nocompress"
DEBUG_TOGGLE = "None"
# the backend to use when parsing the JavaScript or Stylesheet files
PARSER = 'compressor.parser.AutoSelectParser'
OUTPUT_DIR = 'CACHE'
STORAGE = 'compressor.storage.CompressorFileStorage'
CSS_COMPRESSOR = "compressor.css.CssCompressor"
JS_COMPRESSOR = "compressor.js.JsCompressor"
URL = None
ROOT = None
CSS_FILTERS = ['compressor.filters.css_default.CssAbsoluteFilter']
JS_FILTERS = ['compressor.filters.jsmin.JSMinFilter']
PRECOMPILERS = (
# ('text/coffeescript', 'coffee --compile --stdio'),
# ('text/less', 'lessc {infile} {outfile}'),
# ('text/x-sass', 'sass {infile} {outfile}'),
# ('text/x-scss', 'sass --scss {infile} {outfile}'),
)
CLOSURE_COMPILER_BINARY = 'java -jar compiler.jar'
CLOSURE_COMPILER_ARGUMENTS = ''
CSSTIDY_BINARY = 'csstidy'
CSSTIDY_ARGUMENTS = '--template=highest'
YUI_BINARY = 'java -jar yuicompressor.jar'
YUI_CSS_ARGUMENTS = ''
YUI_JS_ARGUMENTS = ''
DATA_URI_MIN_SIZE = 1024
# the cache backend to use
CACHE_BACKEND = None
# rebuilds the cache every 30 days if nothing has changed.
REBUILD_TIMEOUT = 60 * 60 * 24 * 30 # 30 days
# the upper bound on how long any compression should take to be generated
# (used against dog piling, should be a lot smaller than REBUILD_TIMEOUT
MINT_DELAY = 30 # seconds
# check for file changes only after a delay
MTIME_DELAY = 10 # seconds
# enables the offline cache -- also filled by the compress command
OFFLINE = False
# invalidates the offline cache after one year
OFFLINE_TIMEOUT = 60 * 60 * 24 * 365 # 1 year
# The context to be used when compressing the files "offline"
OFFLINE_CONTEXT = {}
def configure_enabled(self, value):
return value or getattr(global_settings, 'COMPRESS', value)
def configure_root(self, value):
if value is None:
value = getattr(global_settings, 'STATIC_ROOT', None)
if not value:
value = global_settings.MEDIA_ROOT
if not value:
raise ImproperlyConfigured(
"The COMPRESS_ROOT setting must be set.")
return os.path.normcase(os.path.abspath(value))
def configure_url(self, value):
# Uses Django 1.3's STATIC_URL by default or falls back to MEDIA_URL
if value is None:
value = getattr(global_settings, "STATIC_URL", None)
if not value:
value = global_settings.MEDIA_URL
if not value.endswith("/"):
raise ImproperlyConfigured("The URL settings (e.g. COMPRESS_URL) "
"must have a trailing slash.")
return value
def configure_cache_backend(self, value):
if value is None:
# If we are on Django 1.3 AND using the new CACHES setting...
if DJANGO_VERSION[:2] >= (1, 3) and hasattr(global_settings, "CACHES"):
value = "default"
else:
# falling back to the old CACHE_BACKEND setting
value = getattr(global_settings, "CACHE_BACKEND", None)
if not value:
raise ImproperlyConfigured(
"Please specify a cache backend in your settings.")
return value
def configure_offline_context(self, value):
if not value:
value = {
"MEDIA_URL": global_settings.MEDIA_URL,
}
# Adds the 1.3 STATIC_URL setting to the context if available
if getattr(global_settings, "STATIC_URL", None):
value["STATIC_URL"] = global_settings.STATIC_URL
return value
def configure_precompilers(self, value):
if not isinstance(value, (list, tuple)):
raise ImproperlyConfigured("The COMPRESS_PRECOMPILERS setting "
"must be a list or tuple. Check for missing commas.")
return value
settings = CompressorSettings(prefix="COMPRESS")

View File

@@ -1,110 +0,0 @@
import os
from django import VERSION as DJANGO_VERSION
from django.conf import settings
from django.core.exceptions import ImproperlyConfigured
from compressor.utils.settings import AppSettings
class CompressorSettings(AppSettings):
# Main switch
ENABLED = not settings.DEBUG
# Allows changing verbosity from the settings.
VERBOSE = False
# GET variable that disables compressor e.g. "nocompress"
DEBUG_TOGGLE = "None"
# the backend to use when parsing the JavaScript or Stylesheet files
PARSER = 'compressor.parser.AutoSelectParser'
OUTPUT_DIR = 'CACHE'
STORAGE = 'compressor.storage.CompressorFileStorage'
CSS_COMPRESSOR = "compressor.css.CssCompressor"
JS_COMPRESSOR = "compressor.js.JsCompressor"
URL = None
ROOT = None
CSS_FILTERS = ['compressor.filters.css_default.CssAbsoluteFilter']
JS_FILTERS = ['compressor.filters.jsmin.JSMinFilter']
PRECOMPILERS = (
# ('text/coffeescript', 'coffee --compile --stdio'),
# ('text/less', 'lessc {infile} {outfile}'),
# ('text/x-sass', 'sass {infile} {outfile}'),
# ('text/x-scss', 'sass --scss {infile} {outfile}'),
)
CLOSURE_COMPILER_BINARY = 'java -jar compiler.jar'
CLOSURE_COMPILER_ARGUMENTS = ''
CSSTIDY_BINARY = 'csstidy'
CSSTIDY_ARGUMENTS = '--template=highest'
YUI_BINARY = 'java -jar yuicompressor.jar'
YUI_CSS_ARGUMENTS = ''
YUI_JS_ARGUMENTS = ''
DATA_URI_MIN_SIZE = 1024
# the cache backend to use
CACHE_BACKEND = None
# rebuilds the cache every 30 days if nothing has changed.
REBUILD_TIMEOUT = 60 * 60 * 24 * 30 # 30 days
# the upper bound on how long any compression should take to be generated
# (used against dog piling, should be a lot smaller than REBUILD_TIMEOUT
MINT_DELAY = 30 # seconds
# check for file changes only after a delay
MTIME_DELAY = 10 # seconds
# enables the offline cache -- also filled by the compress command
OFFLINE = False
# invalidates the offline cache after one year
OFFLINE_TIMEOUT = 60 * 60 * 24 * 365 # 1 year
# The context to be used when compressing the files "offline"
OFFLINE_CONTEXT = {}
def configure_enabled(self, value):
return value or getattr(settings, 'COMPRESS', value)
def configure_root(self, value):
if value is None:
value = getattr(settings, 'STATIC_ROOT', None)
if not value:
value = settings.MEDIA_ROOT
if not value:
raise ImproperlyConfigured(
"The COMPRESS_ROOT setting must be set.")
return os.path.normcase(os.path.abspath(value))
def configure_url(self, value):
# Uses Django 1.3's STATIC_URL by default or falls back to MEDIA_URL
if value is None:
value = getattr(settings, "STATIC_URL", None)
if not value:
value = settings.MEDIA_URL
if not value.endswith("/"):
raise ImproperlyConfigured("The URL settings (e.g. COMPRESS_URL) "
"must have a trailing slash.")
return value
def configure_cache_backend(self, value):
if value is None:
# If we are on Django 1.3 AND using the new CACHES setting...
if DJANGO_VERSION[:2] >= (1, 3) and hasattr(settings, "CACHES"):
value = "default"
else:
# falling back to the old CACHE_BACKEND setting
value = getattr(settings, "CACHE_BACKEND", None)
if not value:
raise ImproperlyConfigured(
"Please specify a cache backend in your settings.")
return value
def configure_offline_context(self, value):
if not value:
value = {
"MEDIA_URL": settings.MEDIA_URL,
}
# Adds the 1.3 STATIC_URL setting to the context if available
if getattr(settings, "STATIC_URL", None):
value["STATIC_URL"] = settings.STATIC_URL
return value
def configure_precompilers(self, value):
if not isinstance(value, (list, tuple)):
raise ImproperlyConfigured("The COMPRESS_PRECOMPILERS setting "
"must be a list or tuple. Check for missing commas.")
return value

View File

@@ -1,6 +1,13 @@
Changelog
=========
0.9.1
-----
- Fixed encoding related issue.
- Minor cleanups.
0.9
---

View File

@@ -50,7 +50,7 @@ copyright = u'2011, Django Compressor authors'
# The short X.Y version.
version = '0.9'
# The full version, including alpha/beta/rc tags.
release = '0.9'
release = '0.9.1'
# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.