mjumbewu / django-jstemplate

Embed Javascript templates (mustache.js and more) into Django templates with minimal fuss.
Other
41 stars 16 forks source link

Precompile Handlebars templates on the server (instead of on page load) #5

Open atogle opened 10 years ago

atogle commented 10 years ago
ghost commented 10 years ago

how ?

mjumbewu commented 10 years ago

@hannicolas This could be done if the user has node installed. Something like:

  1. Specify servercompile flag in the template tag
  2. Compile the template with node and cache the result (raise an exception if the handlebars command isn't available on the server)
  3. Render that cached result instead of the actual template file into the page

The whole caching part may not even be necessary (you could just depend on Django's built-in caching infrastructure). It'd be great to get this into the app (pull requests appreciated)!

mitsest commented 9 years ago

Hello, I 'm trying to load a template that uses a custom context preprocessor server-side. Which method do you suggest in order to add support for this?

I 've checked I18nPreprocessor and it seems like a lot of work(makes sense as they 're translations) The one I 'm trying to add is allauth's socialaccount preprocessor that goes like:

from . import providers

def socialaccount(request):
    ctx = { 'providers': providers.registry.get_list() }
    return dict(socialaccount=ctx)

in order to add the following template

{% load socialaccount %}

{% providers_media_js %}
mjumbewu commented 9 years ago

@mitsest The most important function in the I18nPreprocessor is the process function. Any class you create with a function that matches this signature can be used as a preprocessor. See http://django-jstemplate.readthedocs.org/en/latest/#custom-preprocessors for more info. If you have further questions, please start a new issue. Thanks!

mitsest commented 9 years ago

Thanks for the fast reply. Will do!