django-vendor-files


Namedjango-vendor-files JSON
Version 0.3 PyPI version JSON
download
home_pagehttps://github.com/aipescience/django-vendor-files
SummaryA small extension to download css and js vendor files from CDNs and host them locally.
upload_time2022-01-11 12:10:36
maintainerJochen Klar
docs_urlNone
authorJochen Klar
requires_python
licenseApache-2.0
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            django-download-vendor-files
============================

Setup
-----

Install using pip:

```bash
pip install django-vendor-files
```

Add `vendor_files` to `INSTALLED_APPS` in your Django settings:

```python
INSTALLED_APPS = (
    ...
    'vendor_files',
)
```

Put the `vendor` directory in `STATICFILES_DIRS` in your Django settings:

```
STATICFILES_DIRS = (
    os.path.join(BASE_DIR, 'vendor/'), 
    ...
)
```
Remarks:
- stay first if you wont load vendor libs first
- stay second after you own static if you wish ovveride (patch) vendor lib 


Add a `VENDOR` setting to your Django settings, and add your vendor files with URL and SNI, e.g.:

```python
VENDOR = {
    'jquery': {
        'url': 'https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/',
        'js': [
            {
                # final url will be: https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js
                'path': 'jquery.min.js', 
                'sri': 'sha512-894YE6QWD5I59HgZOGReFYm4dnWc1Qt5NtvYSaNcOP+u1T9qYdvdihz0PPSiiqn/+/3e7Jo4EaG7TubfWGUrMQ==',
            }
        ]
    },
    'bootstrap': {
        'url': 'https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/',
        'js': [
            {
                'path': 'js/bootstrap.min.js',
                'sri': 'sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa',
            }
        ],
        'css': [
            {
                'path': 'css/bootstrap.min.css',
                'sri': 'sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u',
            }
        ]
    }
}
```

Usage
-----

Put `{% load vendor_tags %}` at the top of your Django template and the vendor tag , e.g.: `{% vendor 'jquery' %}`, somewhere in your HTML:

```html
{% load staticfiles %}
{% load vendor_tags %}

<!DOCTYPE html>
<html>
    <head>
        <title>{{ request.site.name }}</title>
        ...
        {% vendor 'jquery' %}
        {% vendor 'bootstrap' %}
    </head>
```

Extended tags, extract only js or css (can be usefull example for [django-compressor](https://github.com/django-compressor/django-compressor)):
```html
{% vendor 'jquery' 'js' %}
# or you can use
{% vendor_js 'jquery' %}

{% vendor 'jquery' 'css' %}
# or you can use
{% vendor_css 'jquery' %}
```

Then, you have 2 options:

1) To use a CDN, put `VENDOR_CDN = True` in your Django settings and the vendor tag will be replaced by a `<link>` or `<script>` tag using the URLs in the settings.

2) To use a local copy, put `VENDOR_CDN = False` (or nothing at all) in your Django settings and the vendor tag will be replaced by a `<link>` or `<script>` tag using your `STATIC_PATH`. The files can be downloaded:

    ```
    python ./manage.py download_vendor_files
    ```



            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/aipescience/django-vendor-files",
    "name": "django-vendor-files",
    "maintainer": "Jochen Klar",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "mail@jochenklar.de",
    "keywords": "",
    "author": "Jochen Klar",
    "author_email": "mail@jochenklar.de",
    "download_url": "https://files.pythonhosted.org/packages/17/41/30e969deff2b010538952c9fed971b8d88f49aa140a7a70edfffd6e63146/django-vendor-files-0.3.tar.gz",
    "platform": "",
    "description": "django-download-vendor-files\n============================\n\nSetup\n-----\n\nInstall using pip:\n\n```bash\npip install django-vendor-files\n```\n\nAdd `vendor_files` to `INSTALLED_APPS` in your Django settings:\n\n```python\nINSTALLED_APPS = (\n    ...\n    'vendor_files',\n)\n```\n\nPut the `vendor` directory in `STATICFILES_DIRS` in your Django settings:\n\n```\nSTATICFILES_DIRS = (\n    os.path.join(BASE_DIR, 'vendor/'), \n    ...\n)\n```\nRemarks:\n- stay first if you wont load vendor libs first\n- stay second after you own static if you wish ovveride (patch) vendor lib \n\n\nAdd a `VENDOR` setting to your Django settings, and add your vendor files with URL and SNI, e.g.:\n\n```python\nVENDOR = {\n    'jquery': {\n        'url': 'https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/',\n        'js': [\n            {\n                # final url will be: https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js\n                'path': 'jquery.min.js', \n                'sri': 'sha512-894YE6QWD5I59HgZOGReFYm4dnWc1Qt5NtvYSaNcOP+u1T9qYdvdihz0PPSiiqn/+/3e7Jo4EaG7TubfWGUrMQ==',\n            }\n        ]\n    },\n    'bootstrap': {\n        'url': 'https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/',\n        'js': [\n            {\n                'path': 'js/bootstrap.min.js',\n                'sri': 'sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa',\n            }\n        ],\n        'css': [\n            {\n                'path': 'css/bootstrap.min.css',\n                'sri': 'sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u',\n            }\n        ]\n    }\n}\n```\n\nUsage\n-----\n\nPut `{% load vendor_tags %}` at the top of your Django template and the vendor tag , e.g.: `{% vendor 'jquery' %}`, somewhere in your HTML:\n\n```html\n{% load staticfiles %}\n{% load vendor_tags %}\n\n<!DOCTYPE html>\n<html>\n    <head>\n        <title>{{ request.site.name }}</title>\n        ...\n        {% vendor 'jquery' %}\n        {% vendor 'bootstrap' %}\n    </head>\n```\n\nExtended tags, extract only js or css (can be usefull example for [django-compressor](https://github.com/django-compressor/django-compressor)):\n```html\n{% vendor 'jquery' 'js' %}\n# or you can use\n{% vendor_js 'jquery' %}\n\n{% vendor 'jquery' 'css' %}\n# or you can use\n{% vendor_css 'jquery' %}\n```\n\nThen, you have 2 options:\n\n1) To use a CDN, put `VENDOR_CDN = True` in your Django settings and the vendor tag will be replaced by a `<link>` or `<script>` tag using the URLs in the settings.\n\n2) To use a local copy, put `VENDOR_CDN = False` (or nothing at all) in your Django settings and the vendor tag will be replaced by a `<link>` or `<script>` tag using your `STATIC_PATH`. The files can be downloaded:\n\n    ```\n    python ./manage.py download_vendor_files\n    ```\n\n\n",
    "bugtrack_url": null,
    "license": "Apache-2.0",
    "summary": "A small extension to download css and js vendor files from CDNs and host them locally.",
    "version": "0.3",
    "project_urls": {
        "Homepage": "https://github.com/aipescience/django-vendor-files"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "53694f73bd63aed765ed0e4245f10bc6305db04efdf8f11ca40699c499c99c20",
                "md5": "5f75240f118c29449c8162368f46c944",
                "sha256": "e404a6aef9daf274d851fae5db03d9a02e58722ef1fd50cd77bb19c9b5367312"
            },
            "downloads": -1,
            "filename": "django_vendor_files-0.3-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "5f75240f118c29449c8162368f46c944",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 5325,
            "upload_time": "2022-01-11T12:10:34",
            "upload_time_iso_8601": "2022-01-11T12:10:34.813260Z",
            "url": "https://files.pythonhosted.org/packages/53/69/4f73bd63aed765ed0e4245f10bc6305db04efdf8f11ca40699c499c99c20/django_vendor_files-0.3-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "174130e969deff2b010538952c9fed971b8d88f49aa140a7a70edfffd6e63146",
                "md5": "a7295a47251b14e263580291de67d2ee",
                "sha256": "9f19af52293140d8aee983cc5523e45810cf37398e332d6b6d0fee034c809c97"
            },
            "downloads": -1,
            "filename": "django-vendor-files-0.3.tar.gz",
            "has_sig": false,
            "md5_digest": "a7295a47251b14e263580291de67d2ee",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 4269,
            "upload_time": "2022-01-11T12:10:36",
            "upload_time_iso_8601": "2022-01-11T12:10:36.510660Z",
            "url": "https://files.pythonhosted.org/packages/17/41/30e969deff2b010538952c9fed971b8d88f49aa140a7a70edfffd6e63146/django-vendor-files-0.3.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2022-01-11 12:10:36",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "aipescience",
    "github_project": "django-vendor-files",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "django-vendor-files"
}
        
Elapsed time: 0.21383s