Skip to content

Commit f9f263c

Browse files
committed
Add initial commit
1 parent 5d3c4f3 commit f9f263c

File tree

989 files changed

+25122
-2
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

989 files changed

+25122
-2
lines changed

.editorconfig

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# http://editorconfig.org
2+
3+
root = true
4+
5+
[*]
6+
indent_style = space
7+
indent_size = 4
8+
trim_trailing_whitespace = true
9+
insert_final_newline = true
10+
charset = utf-8
11+
end_of_line = lf
12+
max_line_length = 88
13+
14+
[*.{json,yml,yaml,js,jsx,vue,toml}]
15+
indent_size = 2
16+
17+
[*.{html,htm,svg,xml}]
18+
indent_size = 2
19+
max_line_length = 120
20+
21+
[LICENSE]
22+
insert_final_newline = false
23+
24+
[*.{md,markdown}]
25+
indent_size = 2
26+
max_line_length = 80
27+
28+
[Makefile]
29+
indent_style = tab

.github/FUNDING.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
github: codingjoe
2+
tidelift: pypi/django-esm
3+
custom: https://www.paypal.me/codingjoe

.github/dependabot.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
version: 2
2+
updates:
3+
- package-ecosystem: pip
4+
directory: "/"
5+
schedule:
6+
interval: daily
7+
- package-ecosystem: github-actions
8+
directory: "/"
9+
schedule:
10+
interval: daily

.github/workflows/ci.yml

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
9+
jobs:
10+
11+
lint:
12+
runs-on: ubuntu-latest
13+
strategy:
14+
matrix:
15+
lint-command:
16+
- bandit -r . -x ./tests
17+
- black --check --diff .
18+
- flake8 .
19+
- isort --check-only --diff .
20+
- pydocstyle .
21+
steps:
22+
- uses: actions/checkout@v4
23+
- uses: actions/setup-python@v4
24+
with:
25+
python-version: "3.x"
26+
cache: 'pip'
27+
cache-dependency-path: 'pyproject.toml'
28+
- run: python -m pip install -e .[lint]
29+
- run: ${{ matrix.lint-command }}
30+
31+
dist:
32+
runs-on: ubuntu-latest
33+
steps:
34+
- uses: actions/checkout@v4
35+
- uses: actions/setup-python@v4
36+
with:
37+
python-version: "3.x"
38+
- run: python -m pip install --upgrade pip build wheel twine
39+
- run: python -m build --sdist --wheel
40+
- run: python -m twine check dist/*
41+
- uses: actions/upload-artifact@v3
42+
with:
43+
path: dist/*
44+
45+
pytest-python:
46+
name: PyTest
47+
needs:
48+
- lint
49+
strategy:
50+
matrix:
51+
python-version:
52+
- "3.8"
53+
- "3.9"
54+
- "3.10"
55+
- "3.12"
56+
django-version:
57+
- "4.2" # LTS
58+
runs-on: ubuntu-latest
59+
steps:
60+
- uses: actions/checkout@v4
61+
- name: Set up Python ${{ matrix.python-version }}
62+
uses: actions/setup-python@v4
63+
with:
64+
python-version: ${{ matrix.python-version }}
65+
- run: python -m pip install .[test]
66+
- run: python -m pip install django~=${{ matrix.django-version }}.0
67+
- run: python -m playwright install
68+
- run: python -m pytest
69+
- uses: codecov/codecov-action@v3
70+
with:
71+
flags: py${{ matrix.python-version }}
72+
73+
pytest-django:
74+
name: PyTest
75+
needs:
76+
- lint
77+
strategy:
78+
matrix:
79+
python-version:
80+
- "3.11"
81+
django-version:
82+
# LTS gets tested on all OS
83+
- "3.2"
84+
- "4.2"
85+
- "5.0"
86+
runs-on: ubuntu-latest
87+
steps:
88+
- uses: actions/checkout@v4
89+
- name: Set up Python ${{ matrix.python-version }}
90+
uses: actions/setup-python@v4
91+
with:
92+
python-version: ${{ matrix.python-version }}
93+
- run: python -m pip install .[test]
94+
- run: python -m pip install django~=${{ matrix.django-version }}.0
95+
- run: python -m playwright install
96+
- run: python -m pytest
97+
- uses: codecov/codecov-action@v3
98+
with:
99+
flags: dj${{ matrix.django-version }}
100+
101+
codeql:
102+
name: CodeQL
103+
needs: [ dist, pytest-python, pytest-django ]
104+
runs-on: ubuntu-latest
105+
permissions:
106+
actions: read
107+
contents: read
108+
security-events: write
109+
strategy:
110+
fail-fast: false
111+
matrix:
112+
language: [ python ]
113+
steps:
114+
- name: Checkout
115+
uses: actions/checkout@v4
116+
- name: Initialize CodeQL
117+
uses: github/codeql-action/init@v2
118+
with:
119+
languages: ${{ matrix.language }}
120+
queries: +security-and-quality
121+
- name: Autobuild
122+
uses: github/codeql-action/autobuild@v2
123+
- name: Perform CodeQL Analysis
124+
uses: github/codeql-action/analyze@v2
125+
with:
126+
category: "/language:${{ matrix.language }}"

.github/workflows/release.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: Release
2+
3+
on:
4+
release:
5+
types: [published]
6+
7+
jobs:
8+
PyPi:
9+
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v4
13+
- uses: actions/setup-python@v4
14+
with:
15+
python-version: "3.x"
16+
- run: python -m pip install --upgrade pip build wheel twine
17+
- run: python -m build --sdist --wheel
18+
- run: python -m twine upload dist/*
19+
env:
20+
TWINE_USERNAME: __token__
21+
TWINE_PASSWORD: ${{ secrets.TWINE_PASSWORD }}

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,3 +158,10 @@ cython_debug/
158158
# and can be added to the global gitignore or merged into this file. For a more nuclear
159159
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
160160
#.idea/
161+
162+
# flit_scm
163+
_version.py
164+
165+
# npm
166+
node_modules/
167+
package-lock.json

README.md

Lines changed: 67 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,67 @@
1-
# django-esm
2-
Lightweight JavaScript ESM module loader for Django.
1+
# Django ESM
2+
3+
NextGen JavaScript ESM module support for Django.
4+
5+
## Highlights
6+
7+
* easy transition
8+
* smart cache busting
9+
* no more bundling
10+
* native ESM support
11+
* local vendoring with npm
12+
13+
## Setup
14+
15+
Install the package and add it to your `INSTALLED_APPS` setting:
16+
17+
```bash
18+
pip install django-esm
19+
```
20+
21+
```python
22+
# settings.py
23+
INSTALLED_APPS = [
24+
#
25+
'django_esm',
26+
]
27+
```
28+
29+
Next, add the node_modules directory to your staticfiles finders:
30+
31+
```python
32+
# settings.py
33+
STATICFILES_DIRS = [
34+
BASE_DIR / "node_modules",
35+
]
36+
```
37+
38+
Finally, add the import map to your base template:
39+
40+
```html
41+
<!-- base.html -->
42+
<!DOCTYPE html>
43+
{% load esm %}
44+
<html lang="en">
45+
<head>
46+
<script type="importmap">{% importmap %}</script>
47+
</head>
48+
</html>
49+
```
50+
51+
That's it!
52+
Don't forget to run `npm install` and `python manage.py collectstatic`.
53+
54+
## Usage
55+
56+
You can now import JavaScript modules in your Django templates:
57+
58+
```html
59+
<!-- index.html -->
60+
61+
{% block content %}
62+
<script type="module">
63+
import "htmx.org"
64+
htmx.logAll()
65+
</script>
66+
{% endblock %}
67+
```

django_esm/__init__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
"""Lightweight JavaScript ESM module loader for Django."""
2+
3+
from . import _version # noqa
4+
5+
__version__ = _version.__version__
6+
VERSION = _version.VERSION_TUPLE

django_esm/templatetags/__init__.py

Whitespace-only changes.

django_esm/templatetags/esm.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import json
2+
3+
from django import template
4+
from django.conf import settings
5+
from django.utils.safestring import mark_safe
6+
7+
from .. import utils
8+
9+
register = template.Library()
10+
11+
12+
@register.simple_tag
13+
def importmap():
14+
return mark_safe( # nosec
15+
json.dumps(
16+
{"imports": dict(utils.parse_package_json(settings.BASE_DIR))}, indent=2
17+
)
18+
)

0 commit comments

Comments
 (0)