Commit 74cbc804 by Timothée Peignier

improve compressors documentation and add compilers documentation

parent 8793b3a9
.. _ref-compilers:
=========
Compilers
=========
Coffee Script compiler
======================
The Coffee Script compiler use `Coffee Script <http://jashkenas.github.com/coffee-script/>`_
to compile your javascripts.
To use it add this to your ``COMPRESS_COMPILERS`` ::
COMPRESS_COMPILERS = (
'compress.compilers.coffee.CoffeeScriptCompiler',
)
``COMPRESS_COFFEE_SCRIPT_BINARY``
---------------------------------
Command line to execute for coffee program.
You will most likely change this to the location of coffee on your system.
Defaults to ``'/usr/local/bin/coffee'``.
``COMPRESS_COFFEE_SCRIPT_ARGUMENTS``
------------------------------------
Additional arguments to use when coffee is called.
Defaults to ``''``.
LESS compiler
=============
The LESS compiler use `LESS <http://lesscss.org/>`_
to compile your stylesheets.
To use it add this to your ``COMPRESS_COMPILERS`` ::
COMPRESS_COMPILERS = (
'compress.compilers.less.LessCompiler',
)
``COMPRESS_LESS_BINARY``
------------------------
Command line to execute for lessc program.
You will most likely change this to the location of lessc on your system.
Defaults to ``'/usr/local/bin/lessc'``.
``COMPRESS_LESS_ARGUMENTS``
---------------------------
Additional arguments to use when lessc is called.
Defaults to ``''``.
SASS compiler
=============
The SASS compiler use `SASS <http://sass-lang.com/>`_
to compile your stylesheets.
To use it add this to your ``COMPRESS_COMPILERS`` ::
COMPRESS_COMPILERS = (
'compress.compilers.sass.SASSCompiler',
)
``COMPRESS_SASS_BINARY``
------------------------
Command line to execute for sass program.
You will most likely change this to the location of sass on your system.
Defaults to ``'/usr/local/bin/sass'``.
``COMPRESS_SASS_ARGUMENTS``
---------------------------
Additional arguments to use when sass is called.
Defaults to ``''``.
Write your own compiler class
=============================
To write your own compiler class, for example want to implement other types
of compilers.
All you need to do is to create a class that inherits from ``compress.compilers.CompilerBase``
and implements ``match_file`` and ``compile_file`` when needed.
Finally, specify it in the tuple of compilers ``COMPRESS_COMPILERS`` in the settings.
Example
-------
A custom compiler for a imaginary compiler called jam ::
from compress.compilers import CompilerBase
class JamCompiler(CompilerBase):
output_extension = 'js'
def match_file(self, filename):
return path.endswith('.jam')
def compile_file(self, content):
return jam.compile(content)
.. _ref-compressors:
===========
Compressors
===========
Template tags
=============
If you need to change the output of the HTML-tags generated from the templatetags,
this can be done by overriding the templates ``compress/css.html`` and ``compress/js.html``.
YUI Compressor compressor
=========================
The YUI compressor use `yui-compressor <http://developer.yahoo.com/yui/compressor/>`_
for compressing javascript and stylesheets.
To us it for your stylesheets add this to your ``COMPRESS_CSS_COMPRESSORS`` ::
COMPRESS_CSS_COMPRESSORS = (
'compress.compressors.yui.YUICompressor',
)
To use it for your javascripts add this to your ``COMPRESS_JS_COMPRESSORS`` ::
COMPRESS_JS_COMPRESSORS = (
'compress.compressors.yui.YUICompressor',
)
``COMPRESS_YUI_BINARY``
-----------------------
Command line to execute for the YUI program.
You will most likely change this to the location of yui-compressor on your system.
Defaults to ``'/usr/local/bin/yuicompressor'``.
``COMPRESS_YUI_CSS_ARGUMENTS``
------------------------------
Additional arguments to use when compressing CSS.
Defaults to ``''``.
``COMPRESS_YUI_JS_ARGUMENTS``
-----------------------------
Additional arguments to use when compressing JavaScript.
Defaults to ``''``.
Closure Compiler compressor
===========================
The Closure compressor use `Google Closure Compiler <http://code.google.com/closure/compiler/>`_
to compress javascripts.
To use it add this to your ``COMPRESS_JS_COMPRESSORS`` ::
COMPRESS_JS_COMPRESSORS = (
'compress.compressors.closure.ClosureCompressor',
)
``COMPRESS_CLOSURE_BINARY``
---------------------------
Command line to execute for the Closure Compiler program.
You will most likely change this to the location of closure on your system.
Default to ``'/usr/local/bin/closure'``
``COMPRESS_CLOSURE_ARGUMENTS``
------------------------------
Additional arguments to use when closure is called.
Default to ``''``
UglifyJS compressor
===================
The UglifyJS compressor use `UglifyJS <https://github.com/mishoo/UglifyJS/>`_ to
compress javascripts.
To use it add this to your ``COMPRESS_JS_COMPRESSORS`` ::
COMPRESS_JS_COMPRESSORS = (
'compress.compressors.uglifyjs.UglifyJSCompressor',
)
``COMPRESS_UGLIFYJS_BINARY``
----------------------------
Command line to execute for the Closure Compiler program.
You will most likely change this to the location of closure on your system.
Defaults to ``'/usr/local/bin/uglifyjs'``.
``COMPRESS_UGLIFYJS_ARGUMENTS``
-------------------------------
Additional arguments to use when uglifyjs is called.
Default to ``''``
JSMin compressor
================
The jsmin compressor use Douglas Crockford jsmin tool to
compress javascripts.
To use it add this to your ``COMPRESS_JS_COMPRESSORS`` ::
COMPRESS_JS_COMPRESSORS = (
'compress.compressors.jsmin.JSMinCompressor',
)
CSSTidy compressor
==================
The CSStidy compressor use `CSStidy <http://csstidy.sourceforge.net/>`_ to compress
stylesheets.
To us it for your stylesheets add this to your ``COMPRESS_CSS_COMPRESSORS`` ::
COMPRESS_CSS_COMPRESSORS = (
'compress.compressors.csstidy.CSSTidyCompressor',
)
``COMPRESS_CSSTIDY_BINARY``
---------------------------
Command line to execute for csstidy program.
You will most likely change this to the location of csstidy on your system.
Defaults to ``'/usr/local/bin/csstidy'``
``COMPRESS_CSSTIDY_ARGUMENTS``
------------------------------
Additional arguments to use when csstidy is called.
Default to ``'--template=highest'``
Write your own compressor class
===============================
To write your own compressor class, for example want to implement other types
of compressors.
All you need to do is to create a class that inherits from ``compress.compressors.CompressorBase``
and implements ``compress_css`` and/or a ``compress_js`` when needed.
Finally, specify it in the tuple of compressors ``COMPRESS_CSS_COMPRESSORS`` or
``COMPRESS_JS_COMPRESSORS`` (see :doc:`configuration` for more information) in the settings.
Example
-------
A custom compressor for a imaginary compressor called jam ::
from compress.compressors import CompressorBase
class JamCompressor(CompressorBase):
def compress_js(self, js):
return jam.compress(js)
def compress(self, css):
return jam.compress(css)
......@@ -250,66 +250,3 @@ some horsepower to google which leads us as hinted in the example above to the n
external urls is currently only available for javascript. There's currently no
reason to have external css files (Yes there are css frameworks as well on the net
but they are often very small or generated to fit your needs)
YUI Compressor settings
=======================
``COMPRESS_YUI_BINARY``
-----------------------
Command line to execute for the YUI program.
You will most likely change this to the location of yui-compressor on your system.
Defaults to ``'/usr/local/bin/yuicompressor'``.
``COMPRESS_YUI_CSS_ARGUMENTS``
------------------------------
Additional arguments to use when compressing CSS.
Defaults to ``''``.
``COMPRESS_YUI_JS_ARGUMENTS``
-----------------------------
Additional arguments to use when compressing JavaScript.
Defaults to ``''``.
Closure Compiler settings
=========================
``COMPRESS_CLOSURE_BINARY``
---------------------------
Command line to execute for the Closure Compiler program.
You will most likely change this to the location of closure on your system.
Default to ``'/usr/local/bin/closure'``
``COMPRESS_CLOSURE_ARGUMENTS``
------------------------------
Additional arguments to use when closure is called.
Default to ``''``
UglifyJS settings
=================
``COMPRESS_UGLIFYJS_BINARY``
----------------------------
Command line to execute for the Closure Compiler program.
You will most likely change this to the location of closure on your system.
Defaults to ``'/usr/local/bin/uglifyjs'``.
``COMPRESS_UGLIFYJS_ARGUMENTS``
-------------------------------
Additional arguments to use when uglifyjs is called.
Default to ``''``
.. _ref-customization:
=============
Customization
=============
``django-compress`` can be customized an a couple of ways.
If you need to change the output of the HTML-tags generated from the templatetags,
this can be done by overriding the templates ``compress/css.html`` and ``compress/js.html``.
You can also write your own compressor-class, if you for example want to implement
other types of compressors.
All you need to do is to create a class that inherits from ``compress.compressors.CompressorBase``
and implements ``compress_css`` and/or a ``compress_js`` when needed.
Finally, specify it in the tuple of compressors ``COMPRESS_CSS_COMPRESSORS`` or
``COMPRESS_JS_COMPRESSORS`` (see :doc:`configuration` for more information) in the settings.
Example
=======
A custom compressor for a imaginary compressor called jam ::
from compress.compressors import CompressorBase
class JamCompressor(CompressorBase):
def compress_js(self, js):
return jam.compress(js)
def compress(self, css):
return jam.compress(css)
......@@ -48,7 +48,8 @@ Table Of Contents
usage
configuration
versioning
customization
compressors
compilers
farfutureexpires
backwardsincompatiblechanges
......
......@@ -4,8 +4,12 @@
Versioning
==========
There are several ways for generating version strings. Basically, two types are available.
These are: mtime version strings and hash version strings.
There are several ways for generating version strings. Basically, three types are available.
These are:
* `mtime <#modification-time-version>`_
* `hash <#hash-version>`_
* `git <#git-version>`_
Modification time version
=========================
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment