Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Management command for downloading HTMX #87

Closed
jordaneremieff opened this issue Jul 3, 2021 · 4 comments
Closed

Management command for downloading HTMX #87

jordaneremieff opened this issue Jul 3, 2021 · 4 comments

Comments

@jordaneremieff
Copy link

In my project I've created a management command based on https://github.com/adamchainz/django-htmx/blob/main/example/download_htmx.py.

Would it be desirable to include a management command directly in this project for this purpose?

@adamchainz
Copy link
Owner

No the project deliberately doesn't bundle htmx or provide any way of doing so, since there are too many ways you might want to embed htmx - from a CDN, your own static files, or via a JS bundler npm, and with or without extensions. The download script there is to make the example app more manageable and you're free to adapt it.

@adamchainz
Copy link
Owner

I reconsidered this after several further requests over the years. #428 has a possible implementation.

@kryskool
Copy link

Hi @kytta @adamchainz

if HTMX is an integral part of our development project, it seems useful to me to declare it as a parameter, as Django compressor does

to perform this operation we need to add these news settings:

  • HTMX_VERSION
  • HTMX_EXTENSIONS
  • HTMX_STATIC_ROOT
  • HTMX_STATIC_URL

All news settings have the prefix HTMX_

HTMX_VERSION = "1.9.11"

Indicate the htmx version to download

HTMX_EXTENSIONS = [
    "htmx.js",  # mandatory for django-htmx
    "ext/debug.js",  # mandatory for django-htmx
    "ext/event-header.js",  # mandatory for django-htmx
    "https://github.com/orgname/repos/main/src/",
    "https://raw.githubusercontent.com/bigskysoftware/htmx-extensions/main/src/head-support/head-support.js",
    "https://unpkg.com/browse/htmx-ext@0.1.5/dist/csrf-token.js",
]

By default HTMX_EXTENSIONS have these values:

  • htmx.js
  • ext/debug.js
  • ext/event-header.js

we need to define where to store the download files

HTMX_STATIC_ROOT = "static_htmx/"
# or
HTMX_STATIC_ROOT = "/opt/django_tuto/static_htmx/"

HTMX_STATIC_ROOT is the original folder to collect the HTMX files with command downloadhtmx or htmx download

HTMX_STATIC_URL = "htmx"

by default the static URL for htmx STATIC_URL + HTMX_STATIC_URL

After call the download hmtx command, we can call the collectstatic command.

STATICFILES_DIRS = [
    ...
    (HTMX_STATIC_URL, HTMX_STATIC_ROOT),
]

On the html template we can use these to include the htmx files

<script src="{% static 'htmx/myjsfile.js' %}"></script> 

With these settings, no need to pass extra arguments on the command line.

just execute commands in this order

python manage.py downloadhtmx (or htmx download)
python manage.py collectstatic

What do you think ?

@adamchainz
Copy link
Owner

Decided against this in #428. It’s a lot easier to write a script in your project that downloads all your third-party JS/CSS assets, using curl or similar, like the example project does since #468. That way there’s no needless “abstraction” through settings or need for maintaining a database of extension URLs.

@adamchainz adamchainz closed this as not planned Won't fix, can't repro, duplicate, stale Aug 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants