Giter Site home page Giter Site logo

django-ember-precompile's Introduction

ember.js precompiler for projects that use the django compressor

##Why did you write another precompiler npm module?

  1. django projects have a quick hook to execute code with django compressor
  2. I prefer to precompile my handlebars templates for ember.js when possible
  3. I couldn't find an existing npm module that was built to work with django compressor and ember.js

##How do I get started then?

First you need to install node.js if you have not already

http://nodejs.org/download/

Install the npm module

npm install django-ember-precompile

Add django compressor to your django web project

pip install -r django_compressor

Register a type to have the compressor fire off the precompile step (in your settings.py)

COMPRESS_PRECOMPILERS = (
    ('text/x-handlebars', 'node_modules/django-ember-precompile/bin/django-ember-precompile {infile}'),
)

Finally in your html you need to reference the uncompiled handlebars templates

{% load staticfiles %}
{% load compress %}

{% compress js %}
<script src="{% static 'script/app/templates/foo.handlebars' %}" type="text/x-handlebars"></script>
{% endcompress %}

This npm module makes a few assumptions to correctly register the template name with ember.js

1.) Each template must have a file extension of "handlebars" or "hbs"
2.) Each template must reside under a root "templates" directory

##Development

To run the tests

cd tests
./runner.sh

django-ember-precompile's People

Contributors

dgaus avatar lewtds avatar mattjmorrison avatar omarestrella avatar toranb avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

django-ember-precompile's Issues

working with ./mange.py runserver but not with uwsgi

Hi,

I am hoping to get some guidance on an issue I am having with this particular precompiler. Everything works just as it should when running with 'python manage.py runserver' but when I use uwsgi to run the application it will not work.

The error I am receiving is

ValueError at /
Empty module name

It is occurring because of this call in base.py of django_compressor on line 249:

mod = import_module(mod_name)

At this point the mod_name variable is empty. It is empty because of the call to get_mod_func a few lines above:

mod_name, cls_name = get_mod_func(filter_or_command)

It turns out the get_mod_func method just splits the 'filter_or_command' variable based on the first '.' on the right in this file of django_compressor - utils/init.py:

return callback[:dot], callback[dot + 1:]

When using django-ember-precompile the value of filter_or_command is this:
'./node_modules/django-ember-precompile/bin/django-ember-precompile {infile}'

which means the call to get_mod_func will return this:

'','./node_modules/django-ember-precompile/bin/django-ember-precompile {infile}'

Which causes the import_module call to fail due to the empty value.

I am sorry if this issue is not specifically related to django-ember-precompile but I would love if you could nudge me in to the right direction for tracking this down and I would greatly appreciate it.

The strange thing is that this only occurs when using uwsgi to run the app and not through the regular runserver

Leigh

Crashes with later versions of JSDOM

Noticed some problems with an npm install of django-ember-precompile of late.

Installation works fine, but when it's used you get:

"TypeError: Object [ null ] has no method 'createWindow'"

It looks to be related to django-ember-precompile installing one of the later jsdom packages, specifically the 1.0.0-pre.X versions.

Currently working around it by pre-installing [email protected] prior to installing django-ember-precompile - that seems to satisfy DEP's dependencies and avoids (on a clean install) it pulling in a problematic version by itself.

use ember-template-compiler.js

when you run rake dist on the ember.js project is generates a nice script called ember-template-compiler.js which as the name describes compiles ember templates nicely.

when using that, all you need is handlebars, no jquery and no full ember.

This also means no need for jsdom, which actually has requirements of its own that need compilation. Installing a compiler on windows just to get precompilation seems drastic to me ๐Ÿ˜„

I will probably not be using this project in production simply because node is kinda weird on windows with respect to file paths etc.

I plan on using PyExecJS with node as a backend to avoid having to call out to a cmd in django-compressor (it will be its own filter)

Just figured I would let you know you can cut off almost all your current dependencies and make this very slim.

Define template folder instead of each template

Toran,

I'm not very familiar with the compression pipeline in Django so I'm reaching out in case you have a guess.

Do you think it's possible we could pass a directory and it could scan and inject instead of having to list 100 templates?

Or do you think I should just lazily precompile them all and inject them in a single bundled file?

ability to specify template name explicitly

<script src="{% static 'templates/foo.handlebars' %}?name=foobar"
type="text/x-handlebars"></script>

or within foo.handlebars on the first line

{{! name:foobar }}
...

something like this would remove the need for the currently strict filename/path requirements

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.