Skip to main content
Python Software Foundation 20th Year Anniversary Fundraiser  Donate today!

django_compressor filter to compile ember templates

Project description

Ember Compressor Compiler

[![Build Status](](


This tool is meant to be used as an extension to [django-compressor](

It precompiles [handlebars.js]( templates specifically for [ember.js](


- platform independent
- no need to install node.js packages
- flexible template naming conventions
- inline handlebars in django templates
- 100% test coverage
- [PEP 8]( compliance
- [semver]( compliance


Install with pip/easy_install from the pypi

`pip install ember-compressor-compiler`

or clone the latest source

git clone
cd ember-compressor-compiler
python install

You must also install [node.js]( or [PyV8](

The latest versions of node.js can be found [here](


Using this tool is as simple as installing it and adding it to the `COMPRESS_PRECOMPILERS` django setting

('text/x-handlebars', 'embercompressorcompiler.filter.EmberHandlebarsCompiler'),

Then, in your django templates you can embed handlebars templates like so
{% load staticfiles %}
{% load compress %}

{% compress js %}
<script type="text/x-handlebars" src="{% static 'app/templates/application.hbs' %}" ></script>
<script type="text/x-handlebars" data-template-name="index">
{% endcompress %}

Template Names

Template names are determined in one of two ways

1. the `data-template-name` attribute on the `script` tag in your django template
2. the `src` attribute on the `script` tag in your django template

When specified, the `data-template-name` value is used verbatim

If not, the `src` value is manipulated to give proper template names.

- the file extensions `.handlebars` and `.hbs` are removed
- everything before the parent directory `templates` is removed

<!-- results in template named 'application' -->
<script type="text/x-handlebars" src="{% static 'app/templates/application.hbs' %}" ></script>

<!-- results in template named 'example/index' -->
<script type="text/x-handlebars" src="{% static 'app/templates/example/index.handlebars' %}" ></script>

Advanced Usage

If you need to change the template naming behavior, you can subclass `embercompressorcompiler.filter.EmberHandlebarsCompiler`

from embercompressorcompiler.filter import EmberHandlebarsCompiler

class MyCompiler(EmberHandlebarsCompiler):
# override default parent directory
parent_dir = 'tpls'

# override default extensions
extensions = ['.tpl']

Then you register your own compiler subclass in `COMPRESS_PRECOMPILERS`

('text/x-handlebars', 'myapp.MyCompiler'),

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for ember-compressor-compiler, version 0.3.1
Filename, size File type Python version Upload date Hashes
Filename, size (33.8 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page