Template preprocessor/compiler for Django
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
src/template_preprocessor
.gitignore
AUTHORS
LICENCSE.txt
README
setup.py

README

===========================================================
Template Preprocessor Readme
===========================================================

Author: Jonathan Slenders, City Live nv

Description:

    Preprocessor for Django templates which compiles all files in a very
    compact version. This does not only result in less HTTP traffic, but also
    causes the template render engine of Django to have less work at runtime.
    (A lot of template tags can be processed in advance.)



Setup
-----

Add this to your settings.py:

    >   # Define languages -> otherwise templates will be compiled in all possible languages
    >   LANGUAGES = (
    >        ('en', 'EN'),
    >   )
    >
    >   # Define directories
    >   MEDIA_ROOT = ROOT + 'media/'
    >   MEDIA_URL = '/media/'
    >   MEDIA_CACHE_DIR = MEDIA_ROOT + 'cache/'
    >   MEDIA_CACHE_URL = MEDIA_URL + 'cache/'
    >   TEMPLATE_CACHE_DIR = ROOT + 'templates/cache/'
    >
    >   # Wrap template loaders
    >   if DEBUG:
    >       TEMPLATE_LOADERS = (
    >           #('template_preprocessor.template.loaders.ValidatorLoader',
    >           ('template_preprocessor.template.loaders.RuntimeProcessedLoader',
    >               TEMPLATE_LOADERS
    >           ),
    >       )
    >   else:
    >       TEMPLATE_LOADERS = (
    >           ('template_preprocessor.template.loaders.PreprocessedLoader',
    >               TEMPLATE_LOADERS
    >           ),
    >       )
    >
    >   # Applications
    >   INSTALLED_APPS += ( 'template_preprocessor', )


This will recompile every template during every page load at runtime, but it
will use the preprocessed templates during production.


You can finetune the behaviour of the preprocessor, by enabling or disabling
specific options. Add the following to your settings.py

    >   # Enabled modules of the template preprocessor

    >   TEMPLATE_PREPROCESSOR_OPTIONS = {
    >           # Default settings
    >           '*', ('html', 'whitespace-compression', ),
    >
    >           # Override for specific applications
    >           ('django.contrib.admin', 'django.contrib.admindocs', 'debug_toolbar'): ('no-html',),
    >   }

    The available options are:

    - 'whitespace-compression'
    - 'no-whitespace-compression'
    - 'merge-internal-javascript'
    - 'merge-internal-css'
    - 'html'
    - 'no-html'
    - 'html-remove-empty-class-attributes'
    - 'html-check-alt-and-title-attributes'
    - 'pack-external-javascript'
    - 'pack-external-css'
    - 'compile-css'
    - 'compile-javascript'
    - 'parse-all-html-tags'
    - 'validate-html'
    - 'no-validate-html'



Precompile templates
--------------------

Run this command on your shell

    > ./manage.py compile_templates -v 2


Or if you want to recompile *all* templates. (This is required when base
templates change, because the preprocessor does not yet trace template
dependecies when compiling only the changed templates.)

    > ./manage.py compile_templates -v 2 --all