This repository was archived by the owner on Feb 28, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathsettings.py
85 lines (67 loc) · 2.72 KB
/
settings.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
from django.conf import settings
from gears.environment import Environment, DEFAULT_PUBLIC_ASSETS
from .utils import get_cache, get_finder, get_asset_handler
DEFAULT_CACHE = 'gears.cache.SimpleCache'
DEFAULT_FINDERS = (
('gears.finders.FileSystemFinder', {
'directories': getattr(settings, 'GEARS_DIRS', ()),
}),
)
DEFAULT_MIMETYPES = {
'.css': 'text/css',
'.js': 'application/javascript',
}
DEFAULT_PREPROCESSORS = {
'text/css': 'gears.processors.DirectivesProcessor',
'application/javascript': 'gears.processors.DirectivesProcessor',
}
DEFAULT_POSTPROCESSORS = {
'text/css': 'gears.processors.HexdigestPathsProcessor',
}
GEARS_DEBUG = getattr(settings, 'GEARS_DEBUG', settings.DEBUG)
# Controls whether or not a query string with the file's modified time is
# appended to the file path.
GEARS_CACHE_BUST = getattr(settings, 'GEARS_CACHE_BUST', GEARS_DEBUG)
GEARS_URL = getattr(settings, 'GEARS_URL', settings.STATIC_URL)
path = getattr(settings, 'GEARS_CACHE', DEFAULT_CACHE)
if isinstance(path, (list, tuple)):
path, options = path
else:
options = None
cache = get_cache(path, options)
environment = Environment(
root=getattr(settings, 'GEARS_ROOT'),
public_assets=getattr(settings, 'GEARS_PUBLIC_ASSETS', DEFAULT_PUBLIC_ASSETS),
cache=cache,
gzip=getattr(settings, 'GEARS_GZIP', False),
)
for path in getattr(settings, 'GEARS_FINDERS', DEFAULT_FINDERS):
if isinstance(path, (list, tuple)):
path, options = path
else:
options = None
environment.finders.register(get_finder(path, options))
mimetypes = getattr(settings, 'GEARS_MIMETYPES', DEFAULT_MIMETYPES)
for extension, mimetype in mimetypes.items():
environment.mimetypes.register(extension, mimetype)
for extension, path in getattr(settings, 'GEARS_COMPILERS', {}).items():
if isinstance(path, (list, tuple)):
path, options = path
else:
options = {}
environment.compilers.register(extension, get_asset_handler(path, options))
preprocessors = getattr(settings, 'GEARS_PREPROCESSORS', DEFAULT_PREPROCESSORS)
for mimetype, paths in preprocessors.items():
if not isinstance(paths, (list, tuple)):
paths = [paths]
for path in paths:
environment.preprocessors.register(mimetype, get_asset_handler(path))
postprocessors = getattr(settings, 'GEARS_POSTPROCESSORS', DEFAULT_POSTPROCESSORS)
for mimetype, paths in postprocessors.items():
if not isinstance(paths, (list, tuple)):
paths = [paths]
for path in paths:
environment.postprocessors.register(mimetype, get_asset_handler(path))
compressors = getattr(settings, 'GEARS_COMPRESSORS', {})
for mimetype, path in compressors.items():
environment.compressors.register(mimetype, get_asset_handler(path))