Convert Python data structures into Hyperscript-compatible code blocks.
Project description
Django Hyperscript
This package is intended to simplify the process of dumping data from Django into Hyperscript by providing two template tags with options for customizing the output.
Installation
- Install using pip:
pip install hyperscript-dump
- Add
django_hyperscripttoINSTALLED_APPSin your Django project'ssettings.py:
# settings.py
INSTALLED_APPS = [
...,
'django_hyperscript',
]
- Load the tag library in the necessary templates:
{% load hyperscript %}
Usage
build_hyperscript turns python data into raw Hyperscript.
Configuration
build_hyperscript has a set of additional keyword arguments to configure its behavior.
preserve
Type: bool | Default: False
Keeps the element the Hyperscript is on in the DOM after initializing if True.
camelize
Type: bool | Default: True
"Camelizes" dictionary keys from snake case (snake_case) to camel case (camelCase) to fit JavaScript naming conventions.
scope
Type: str | Default: global
Determines the scope of the Hyperscript variable (global, element, or local).
event
Type: str | Default: init
Specifies the event that triggers assignment. The Hyperscript "on" keyword should not need be provided.
Note: If preserve is False (which it is by default), the element will not be removed until after the event is fired and values are set.
debug
Type: bool | Default: False
Logs the set variable name(s) and value(s).
Final example
build_hyperscript(data, 'myData', preserve=True, camelize=False, scope='element')
assuming data is {"my_value": 25}, the tag would output
"init set element my_data to {'my_value': 25} end"
In this example:
- The Hyperscript remains in the DOM since
preserveisTrue - The keys within the dumped data remain in snake case since
camelizeisFalse - The variable is scoped to the element the Hyperscript belongs to since
scopeis set to'element' - The output is just the raw Hyperscript text since
wrapis set toFalse
License
This project is licensed under the MIT License - see the LICENSE file for details.
Project details
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file hyperscript_dump-1.0.0.tar.gz.
File metadata
- Download URL: hyperscript_dump-1.0.0.tar.gz
- Upload date:
- Size: 4.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8ceb2a9c655399e11bf739f0f017536d4ab487ed8ef3ebb3111e4e4274cdfd60
|
|
| MD5 |
c358e404911ed51c7406492684d812ba
|
|
| BLAKE2b-256 |
e5ec1f10661f14ade5e8c004a4faa8f3e96e9192dcbfa46b17dee81599c55590
|
File details
Details for the file hyperscript_dump-1.0.0-py3-none-any.whl.
File metadata
- Download URL: hyperscript_dump-1.0.0-py3-none-any.whl
- Upload date:
- Size: 4.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
317feda6af6e9ea9271d1a6144f7b7d89d14e5a1cb765734399d22ca82367b3e
|
|
| MD5 |
73ddf911f110c9f5393c693cce53f76f
|
|
| BLAKE2b-256 |
cdd7b38e5ae1a9374afcc15f9491e9249946664ab9f719bb7c2d0ddd7d426b46
|