cyberdelia/django-pipeline — pull request #287 by miki725 (2013-12-05 23:22:06+00:00)
Title: Additional PIPELINE_CSS and PIPELINE_JS can be specified in apps (#197)

In this pull request I implemented the ability to specify additional PIPELINE_CSS and PIPELINE_JS settings within individual apps within a specified module (default is `compressed` to avoid name collision with `pipeline`).

For example, if you have the following global (within the project settings) `PIPELINE_CSS`:

```
# django settings.py
PIPELINE_CSS = {
'colors': {
'source_filenames': (
'css/core.css',
'css/colors/*.css',
'css/layers.css'
),
'output_filename': 'css/colors.css',
'extra_context': {
'media': 'screen,projection',
},
},
}
```

And you have an app called `fooapp`, you can add a module `compressed` (file `compressed.py`) within the app with the following:

```
# compressed.py within the app
PIPELINE_CSS = {
'rainbows': {
'source_filenames': (
'css/rainbow.css',
),
'output_filename': 'css/rainbow.css',
},
}
```

Which will result in the following equivalent global setting:

```
# global equivalent
PIPELINE_CSS = {
'colors': {
'source_filenames': (
'css/core.css',
'css/colors/*.css',
'css/layers.css'
),
'output_filename': 'css/colors.css',
'extra_context': {
'media': 'screen,projection',
},
},
'fooapp_rainbows': {
'source_filenames': (
'css/rainbow.css',
),
'output_filename': 'css/rainbow.css',
},
}
```

The rational of using a Python module instead of let's say a `json` file is that a Python file allows to add some custom logic which a static file would not allow. For the example, the following becomes possible:

```
# compressed.py within the app
from django.conf import settings
PIPELINE_CSS = {
'rainbows': {
'source_filenames': (
'css/rainbow{}.css'.format('_debug' if settings.DEBUG else ''),
),
'output_filename': 'css/rainbow.css',
},
}
```

This implementation also allows to customize its functionality by using the following new settings:

* `PIPELINE_APP_MODULE` - the name of the module where the `PIPELINE_CSS` and `PIPELINE_JS` will be searched for
* `PIPELINE_NAMESPACE_APPS` - if the key/name of the group rule should be namespaced under an app to avoid name-collisions. The first example above renamed/namespaced the group from `raindows` to `fooapp_rainbows`.
* `PIPELINE_NAMESPACE_FORMULA` - the exact formula of how the group key should be renamed

Also within the commit are updates to the docs as well as some sanity unittests.

**Note:** This is same functionality as pull request [218](https://github.com/cyberdelia/django-pipeline/pull/218) however its refactored to a newer pipeline version.