Simple client-side dependency management for your django project.
Project description
Django client-side dependencies app
Manage client-side JS / CSS dependencies for your django project.
- Version: 0.3.1
- Author: powderflask
- Source: https://github.com/powderflask/django-client-side
- MIT License
OVERVIEW:
- Maintain client-side dependencies in one place (i.e., not scattered in templates).
- Provides testable, executable client-side app dependencies set.
- Template tags used to pull JS / CSS dependencies into templates.
- Local static resources and/or from CDN.
- Use any client-side build tools or none - demo app uses npm as JS package manager and build tool.
- conditional dependencies for different build environments
Dependencies:
- python 3
- django
Quick start
pip install https://github.com/powderflask/django-client-side.git
-
Add
client_side
toINSTALLED_APPS
INSTALLED_APPS = [ ... 'client_side', ]
-
define client-side dependency set (see tests.dependencies for example)
-
in settings.py, configure
CLIENT_SIDE_DEPENDENCIES
setting:CLIENT_SIDE_DEPENDENCIES = 'myproject.client_side.dependencies.DEPENDENCIES' # dotted-path to your dependency sets
(may be a dotted-path to a
DependencySets
object or specify theDependencySets
object directly in settings.) -
Use
{% stylesheet <name> %}
and{% javascript <name> %}
in your templates to pull in sets of dependencies -
Update your client-side dependency sets any time without ever touching your templates!
Guide
Define Client-Side Components
from client_side.component import Component, DependencySets, Script, Stylesheet
Define a Component
for each dependency, with zero or more Script
elemenets and/or zero or more Stylesheet
elements:
component = Component(
Script(url="https://example.com/component.js", sri="sha384-js-sri-here"),
Stylesheet(url="https://example.com/component.css", sri="sha384-css-sri-here"),
)
Swap components for different environments, pass static=True
for dependencies loaded from static
files:
lib_common = Component(
Script(url="lib/common.js" if settings.DEBUG else "lib/common.min.js", static=True),
Stylesheet(
url="lib/common.css" if settings.DEBUG else "lib/common.min.css", static=True
),
)
Group Components into Logical Dependency Sets
Define one or more DependencySets
with logical component groups:
DEPENDENCIES = DependencySets(
core=(component, lib_common,),
debug=(debug_toolbar, hijack),
)
Include DependencySets in Templates
{% load dependency_tags %}
...
{% stylesheet 'core' %}
...
{% javascript 'core' %}
{% if debug %}
{% javascript 'debug' %}
{% endif %}
Acknowledgments
Special thanks to BC Hydro, Chartwell, and all Contributors
For Developers
> pip install -r reqirements_dev.txt
Tests
> pytest
> tox
Code Style
> isort
> black
> flake8
Versioning
- Semantic Versioning
> bumpver
Build / Deploy Automation
- invoke
> invoke -l
- GitHub Actions (see .github/workflows)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for django_client_side-0.3.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0508a69b092a14603fc1efff1e5cfe3933e2fc39a17fc87253aec1174a82263e |
|
MD5 | 58669ee160f71736bd7d249ef7ebe1ae |
|
BLAKE2b-256 | a825cde21ca8aa41ac51e47c8f1896705e33c0c98fdc552d41de38d665a5a095 |