Skip to content

Instantly share code, notes, and snippets.

@timmyomahony
Created October 25, 2011 01:11
Show Gist options
  • Save timmyomahony/1311010 to your computer and use it in GitHub Desktop.
Save timmyomahony/1311010 to your computer and use it in GitHub Desktop.
django-sekizai postprocessor for enabling django-compressor compatibility
"""
Get django-sekizai, django-compessor (and django-cms) playing nicely together
re: https://github.com/ojii/django-sekizai/issues/4
using: https://github.com/jezdez/django_compressor.git
and: https://github.com/ojii/django-sekizai.git@0.5
"""
from compressor.templatetags.compress import CompressorNode
from django.template.base import *
def compress(data, name):
"""
Data is the string from the template (the list of js files in this case)
Name is either 'js' or 'css' (the sekizai namespace)
We basically just manually pass the string through the {% compress 'js' %} template tag
"""
return CompressorNode(Template(data).nodelist, name, 'file').render({})
...
{% render_block "js" postprocessor "postprocess_sekizai.compress" %}
...
@andreif
Copy link

andreif commented Apr 27, 2012

from compressor.templatetags.compress import CompressorNode
from django.template.base import Template

def compress(context, data, name):
    """
    Data is the string from the template (the list of js files in this case)
    Name is either 'js' or 'css' (the sekizai namespace)

    We basically just manually pass the string through the {% compress 'js' %} template tag
    """
    return CompressorNode(nodelist=Template(data).nodelist, kind=name, mode='file').render(context=context)

Copy link

ghost commented Mar 30, 2015

In the template.html, what should be loaded at the top? I am getting an import error for postprocess_sekizai

@blueyed
Copy link

blueyed commented Jun 20, 2015

This has been included in django-compressor by now, and there's a fix for it to prevent double-rendering: django-compressor/django-compressor#623

Another PR provides the functionality to use several "js" and "css" blocks: django-compressor/django-compressor#622

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment