cyberdelia/django-pipeline — pull request #218 by miki725 (2013-05-14 05:39:10+00:00)
Title: Additional settings within apps (#197)

In this pull request I implemented the ability to specify additional settings within the 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`:

```
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:

```
# django settings.py
PIPELINE_CSS = {
'rainbows': {
'source_filenames': (
'css/rainbow.css',
),
'output_filename': 'css/rainbow.css',
},
}
```

Which will result in the following equivalent global setting:

```
# compressed.py within the app
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.