usage.rst 2.5 KB
Newer Older
1 2 3 4 5 6
.. _ref-usage:

=====
Usage
=====

7
Describes how to use Pipeline when it is installed and configured.
8 9 10 11

Templatetags
============

12
Pipeline includes two template tags: ``compressed_css`` and ``compressed_js``,
13 14 15 16 17 18 19
in a template library called ``compressed``.

They are used to output the ``<link>`` and ``<script>``-tags for the
specified CSS/JavaScript-groups (as specified in the settings).
The first argument must be the name of the CSS/JavaScript group.

The templatetags will either output the source filenames or the compressed filenames,
20
depending on the ``PIPELINE`` setting, if you do not specify the ``PIPELINE`` setting,
21 22
the source files will be used in DEBUG-mode, and compressed files in non-DEBUG-mode.

23 24 25
If you need to change the output of the HTML-tags generated from the templatetags,
this can be done by overriding the templates ``pipeline/css.html`` and ``pipeline/js.html``.

26
Example
27
-------
28 29 30 31 32

If you have specified the CSS-groups “screen” and “print” and a JavaScript-group
with the name “scripts”, you would use the following code to output them all ::

   {% load compressed %}
Timothée Peignier committed
33 34 35 36 37 38 39 40 41
   {% compressed_css 'colors' %}
   {% compressed_js 'stats' %}

Collect static
==============

Pipeline integrates with staticfiles, you just need to setup ``STATICFILES_STORAGE`` to ::

    STATICFILES_STORAGE = 'pipeline.storage.PipelineStorage'
Chris Reeves committed
42

Timothée Peignier committed
43 44 45
Then when you run ``collectstatic`` command, your CSS and your javascripts will be compressed in the same time ::

    $ python oslo/manage.py collectstatic
46 47 48 49 50


Middleware
==========

Chris Reeves committed
51
To enable HTML compression add ``pipeline.middleware.MinifyHTMLMiddleware``,
52 53
to your ``MIDDLEWARE_CLASSES`` settings.

Alexis Svinartchouk committed
54
Ensure that it comes after any middleware which modifies your HTML, like ``GZipMiddleware`` ::
55 56

   MIDDLEWARE_CLASSES = (
57
      'django.middleware.gzip.GZipMiddleware',
58
      'pipeline.middleware.MinifyHTMLMiddleware',
59
   )
60 61 62 63 64 65 66

Cache manifest
==============

Pipeline provide a way to add your javascripts and stylesheets files to a
cache-manifest via `Manifesto <http://manifesto.readthedocs.org/>`_.

Timothée Peignier committed
67
To do so, you just need to add manifesto app to your ``INSTALLED_APPS``.
68 69 70 71 72 73 74 75 76 77 78 79


Jinja
=====

Pipeline also includes Jinja2 support and is used almost identically to the Django Template tags implementation.
You just need to pass ``pipeline.jinja2.ext.PipelineExtension`` to your Jinja2 environment.

Templates
---------

Unlike the Django template tag implementation the Jinja2 implementation uses different templates, so if you wish to override them please override pipeline/css.jinja and pipeline/js.jinja.