-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial commit. Testing and working locally on Django 2.2.
- Loading branch information
0 parents
commit dc1cb78
Showing
8 changed files
with
135 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
*__pycache__/ | ||
*.pyc | ||
*.egg-info/ | ||
.DS_Store | ||
build/ | ||
dist/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
The Changelog | ||
============= | ||
|
||
1.0.0 (27.11.2019) | ||
~~~~~~~~~~~~~~~~~~ | ||
* Initial release |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2019 Tim Kamanin | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
include *.txt | ||
include *.md | ||
recursive-include docs * |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# django-flexible-manifest-staticfiles | ||
|
||
This extendion to django.contrib.staticfiles.storage.ManifestStaticFilesStorage allows you to specify a list of file patterns that should be ignored/excluded from being versioned and added to the manifest. You can also specify it the other way around and say which files should be included. | ||
|
||
This allows you to add versioned naming to only static files of your choosing. For example, you may want CSS and JS files to be versioned, but not fonts, images or other assets. | ||
|
||
I've written and tested this against Django 2.2. Your mileage elsewhere may vary! | ||
|
||
## Installation | ||
|
||
Use pip: | ||
|
||
```shell | ||
pip install django-flexible-manifest-staticfiles | ||
``` | ||
|
||
## Setup | ||
|
||
Set in your `settings.py`: | ||
|
||
```python | ||
STATICFILES_STORAGE = 'django_flexible_manifest_staticfiles.storages.ForgivingManifestStaticFilesStorage' | ||
``` | ||
|
||
## Usage | ||
|
||
Set in your `settings.py` you can set two settings: | ||
|
||
- `STATICFILES_VERSIONED_INCLUDE` - This is a list of patterns you want to be included. Only files that match at least one of these patterns will be included. If you omit this setting, then all files are included by default. | ||
- `STATICFILES_VERSIONED_EXCLUDE` - Any file matching any of these patterns will be excluded from being versioned. | ||
|
||
Note that the complete path relative to the `static` directory is available for matching against. | ||
|
||
## Examples | ||
|
||
This would only version `.css` and `.js` files, but would exclude minified files: | ||
|
||
```python | ||
STATICFILES_VERSIONED_INCLUDE = ['.css$', '.js$'] | ||
STATICFILES_VERSIONED_EXCLUDE = ['min.css$', 'min.js$'] | ||
``` | ||
|
||
This would version all files asides from `.jpg` files: | ||
|
||
```python | ||
STATICFILES_VERSIONED_EXCLUDE = ['.jpg$'] | ||
``` | ||
|
||
This would only version things in your `/static/scripts`: | ||
|
||
```python | ||
STATICFILES_VERSIONED_INCLUDE = ['scripts/.*$'] | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
__version__ = "1.0.0" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import os | ||
import re | ||
|
||
from collections import OrderedDict | ||
|
||
from django.conf import settings | ||
from django.contrib.staticfiles.storage import ManifestStaticFilesStorage | ||
from django.contrib.staticfiles.utils import matches_patterns | ||
from django.core.files.base import ContentFile | ||
|
||
class FlexibleManifestStaticFilesStorage(ManifestStaticFilesStorage): | ||
|
||
whitelisted_patterns = getattr(settings, "STATICFILES_VERSIONED_INCLUDE", ['.*']) | ||
blacklisted_patterns = getattr(settings, "STATICFILES_VERSIONED_EXCLUDE", []) | ||
|
||
def _post_process(self, paths, adjustable_paths, hashed_files): | ||
|
||
filtered_paths = OrderedDict() | ||
|
||
for name, val in paths.items(): | ||
if any(re.search(wp, name) for wp in self.whitelisted_patterns): | ||
if not any(re.search(wp, name) for wp in self.blacklisted_patterns): | ||
filtered_paths[name] = val | ||
|
||
return super()._post_process(filtered_paths, adjustable_paths, hashed_files) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#!/usr/bin/env python | ||
|
||
from os.path import exists | ||
from setuptools import setup, find_packages | ||
|
||
from django_flexible_manifest_staticfiles import __version__ | ||
|
||
setup( | ||
name='django-flexible-manifest-staticfiles', | ||
version=__version__, | ||
author='Tom Anthony', | ||
author_email='[email protected]', | ||
packages=find_packages(), | ||
scripts=[], | ||
url='https://github.com/TomAnthony/django-flexible-manifest-staticfiles', | ||
license='MIT', | ||
description='An extension of Django ManifestStaticFilesStorage that allows ignoring (excluding) specified files from being versioned, such as images or fonts.', | ||
long_description=open('README.md').read(), | ||
install_requires=[], | ||
) |