Skip to content

Commit

Permalink
Merge pull request #1520 from lonnen/bixie-enable-compression
Browse files Browse the repository at this point in the history
Re-enable asset compression in Bixie
  • Loading branch information
lonnen committed Sep 17, 2013
2 parents 7a8b01b + 4dedd87 commit 2c65e29
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 5 deletions.
2 changes: 1 addition & 1 deletion bixie/bin/bootstrap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,5 @@ fi
./manage.py collectstatic --noinput
# even though COMPRESS_OFFLINE=True COMPRESS becomes (not DEBUG) which
# will become False so that's why we need to use --force here.
#./manage.py compress_jingo --force
./manage.py compress_jingo --force
./manage.py syncdb --noinput
17 changes: 17 additions & 0 deletions bixie/bixie/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,23 @@
# from django.contrib import admin
# admin.autodiscover()

# funfactory puts the more limited CompressorExtension extension in
# but we need the one from jingo_offline_compressor.jinja2ext otherwise we
# might an error like this:
#
# AttributeError: 'CompressorExtension' object has no attribute 'nodelist'
#
from jingo_offline_compressor.jinja2ext import CompressorExtension
import jingo
try:
jingo.env.extensions.pop(
'compressor.contrib.jinja2ext.CompressorExtension'
)
except KeyError:
# happens if the urlconf is loaded twice
pass
jingo.env.add_extension(CompressorExtension)

urlpatterns = patterns(
'',
(r'', include(urls)),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# following PEP 386
__version__ = "0.0.6"
__version__ = "0.0.7"
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# flake8: noqa
import os
import sys
import codecs
from fnmatch import fnmatch
import jinja2
from jinja2.nodes import CallBlock, Call, ExtensionAttribute
Expand Down Expand Up @@ -125,6 +126,8 @@ class Command(NoArgsCommand):
"(which defaults to MEDIA_ROOT). Be aware that using this "
"can lead to infinite recursion if a link points to a parent "
"directory of itself.", dest='follow_links'),
make_option('--encoding', default='utf-8', dest='encoding',
help="Template encoding to use when reading templates"),
)

requires_model_validation = False
Expand Down Expand Up @@ -183,8 +186,6 @@ def compress(self, log=None, **options):
raise OfflineGenerationError("No template loaders defined. You "
"must set TEMPLATE_LOADERS in your "
"settings.")
#from jingo import env

paths = set()
for loader in self.get_loaders():
try:
Expand Down Expand Up @@ -225,11 +226,15 @@ def compress(self, log=None, **options):
from jingo_offline_compressor.jinja2ext import CompressorExtension
env.add_extension(CompressorExtension)

template_encoding = options.get('encoding')
compressor_nodes = SortedDict()
for template_name in templates:
try:
#template_content = env.loader.get_source(env, template_name)[0]
template_content = open(template_name).read()
#template_content = open(template_name).read()
template_content = codecs.open(
template_name, 'r', template_encoding
).read()
template = env.parse(template_content)
except IOError: # unreadable file -> ignore
if verbosity > 0:
Expand Down

0 comments on commit 2c65e29

Please sign in to comment.