jezdez/django_compressor — pull request #294 by jannon (2012-07-30 22:06:19+00:00)
Title: Support for modern webdev practices/technologies

Okay here is a pull request that repackages and cleans up a couple earlier requests

### What's in this pull request

* Let tag arguments after kind (css|js) be specified in any order
* Use more standard 'as ' syntax to name the code block
* Add ability to specify options in the tag
* Ability to group files before processing
* Ability to redirect tag output to template context variable

There are tests and documentation updates as well as the code changes

#### Tag Argument Order

There's not really any need to enforce a certain arrangement of arguments in the tag so let's just let people specify them however they want after the kind parameter. So now all of these are valid:

{% compress js inline as main %}

{% compress js as main file %}

{% compress css group_first=true as base %}

#### Using 'as <name>'

Lots of things in python and django use this syntax, so it would be nice to do so as well

#### Specifying options in the tag

Just like the ```with``` tag in django, you can specify an arbitrary number of keyword/value arguments to the tag. These will get put into a dictionary and passed to the Compressor classes. Also, the default compressors add these to the options that they pass the precompilers and filters. One of the main motivations for this was to prepare for being able to specify that files should be grouped first before, say, lessc precompilation (as discussed in #30) Currently supported options:
- group_first - if 'group_first=true' is specified, files of like type will be concatenated before being handed to precompilers/filters
- deferred - if 'deferred=true' is specified AND 'as ' is specified the results of the template tag are stored in a template context variable

#### Concatenating files before processing (fixes #30)
As mentioned above, using the group_first=true tag options will concatenate files before processing. This is useful for having django_compressor work for best practices like separate mixins.less and page.less files

#### Template context variable (fixes #249)
As mentioned above, using 'deferred=true' and 'as " in the template tag will cause the output to be placed in a template context variable rather than rendered immediately. This is useful for capturing the results of the compression (the url) for use with asynchronous resource loaders (e.g. yepnope.js, require.js, etc.). In fact, if the output mode is 'file', the 'deferred' option set the template variable to be just the compressed url (without 'script' tag). If the mode is 'inline' the template variable just contains whatever the output would have been normally