<img src="https://github.com/LucLor06/django-hyperscript/blob/main/django-hyperscript.png?raw=true" width=200>
# 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
1. Install using pip:
```bash
pip install django-hyperscript
```
2. Add `django_hyperscript` to `INSTALLED_APPS` in your Django project's `settings.py`:
```python
# settings.py
INSTALLED_APPS = [
...,
'django_hyperscript',
]
```
3. Load the tag library in the necessary templates:
```django
{% load hyperscript %}
```
---
## Usage
### `hs_dump`
Dumps data into a single Hyperscript variable.
```django
{% hs_dump data 'myData' %}
```
assuming `data` is `{"foo": "bar"}`, the tag would output
```html
<div _="
init
set global myData to {'foo': 'bar'}
then remove me
end"></div>
```
### `hs_expand`
Expands a dictionary into Hyperscript variables.
```django
{% hs_expand data %}
```
assuming `data` is `{"foo": "bar", "baz": "qux"}`, the tag would output
```html
<div _="
init
set global foo to bar
set global baz to qux
then remove me
end"></div>
```
---
## Configuration
Both `hs_dump` and `hs_expand` have a set of additional keyword arguments to configure their behavior.
### `show`
*Type*: `bool` | *Default*: `False`
Removes Hyperscript from the DOM after initializing if `True`.
### `translate`
*Type*: `bool` | *Default*: `True`
"Translates" 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).
### `wrap`
*Type*: `bool` | *Default*: `True`
Wraps the Hyperscript in a `<div>` if `True`, otherwise returns the raw Hyperscript text.
**Note:** If both **`wrap`** and **`show`** are `False`, the element will *not* be removed and the Hyperscript attribute and value will be removed from the element.
## Final example
```django
{% hs_dump data 'my_data' show=True translate=False scope='element' wrap=False %}
```
assuming `data` is `{"my_value": 25}`, the tag would output
```python
"init set element my_data to {'my_value': 25} end"
```
In this example:
- The Hyperscript remains in the DOM since **`show`** is `True`
- The keys within the dumped data remain in snake case since **`translate`** is `False`
- The variable is scoped to the element the Hyperscript belongs to since **`scope`** is set to `'element'`
- The output is just the raw Hyperscript text since **`wrap`** is set to `False`
---
## License
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
Raw data
{
"_id": null,
"home_page": "https://github.com/LucLor06/django-hyperscript",
"name": "django-hyperscript",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.6",
"maintainer_email": null,
"keywords": "django hyperscript template-tags frontend backend-integration",
"author": "Lucas Lorenz",
"author_email": "LukeLorenzBA@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/f9/27/43bca1061b5af2c493dc689ddb2d94d4f19989e190651751898bb64eda35/django_hyperscript-1.0.2.tar.gz",
"platform": null,
"description": "<img src=\"https://github.com/LucLor06/django-hyperscript/blob/main/django-hyperscript.png?raw=true\" width=200>\r\n\r\n# Django Hyperscript\r\n\r\nThis 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.\r\n\r\n---\r\n## Installation\r\n\r\n1. Install using pip:\r\n```bash\r\npip install django-hyperscript\r\n```\r\n\r\n2. Add `django_hyperscript` to `INSTALLED_APPS` in your Django project's `settings.py`:\r\n```python\r\n# settings.py\r\n\r\nINSTALLED_APPS = [\r\n ...,\r\n 'django_hyperscript',\r\n]\r\n```\r\n\r\n3. Load the tag library in the necessary templates:\r\n```django\r\n{% load hyperscript %}\r\n```\r\n\r\n---\r\n## Usage\r\n\r\n### `hs_dump`\r\n\r\nDumps data into a single Hyperscript variable.\r\n```django\r\n{% hs_dump data 'myData' %}\r\n```\r\nassuming `data` is `{\"foo\": \"bar\"}`, the tag would output\r\n```html\r\n<div _=\"\r\ninit\r\n set global myData to {'foo': 'bar'} \r\n then remove me \r\nend\"></div>\r\n```\r\n### `hs_expand`\r\n\r\nExpands a dictionary into Hyperscript variables.\r\n```django\r\n{% hs_expand data %}\r\n```\r\n\r\nassuming `data` is `{\"foo\": \"bar\", \"baz\": \"qux\"}`, the tag would output\r\n```html\r\n<div _=\"\r\ninit \r\n set global foo to bar \r\n set global baz to qux \r\n then remove me\r\nend\"></div>\r\n```\r\n\r\n---\r\n## Configuration\r\n\r\nBoth `hs_dump` and `hs_expand` have a set of additional keyword arguments to configure their behavior.\r\n\r\n### `show`\r\n*Type*: `bool` | *Default*: `False`\r\n\r\nRemoves Hyperscript from the DOM after initializing if `True`.\r\n\r\n### `translate`\r\n*Type*: `bool` | *Default*: `True`\r\n\r\n\"Translates\" dictionary keys from snake case (snake_case) to camel case (camelCase) to fit JavaScript naming conventions.\r\n\r\n### `scope`\r\n*Type*: `str` | *Default*: `global`\r\n\r\nDetermines the scope of the Hyperscript variable (global, element, or local).\r\n\r\n### `wrap`\r\n*Type*: `bool` | *Default*: `True`\r\n\r\nWraps the Hyperscript in a `<div>` if `True`, otherwise returns the raw Hyperscript text.\r\n\r\n**Note:** If both **`wrap`** and **`show`** are `False`, the element will *not* be removed and the Hyperscript attribute and value will be removed from the element. \r\n\r\n## Final example\r\n```django\r\n{% hs_dump data 'my_data' show=True translate=False scope='element' wrap=False %}\r\n```\r\nassuming `data` is `{\"my_value\": 25}`, the tag would output\r\n```python\r\n\"init set element my_data to {'my_value': 25} end\"\r\n```\r\nIn this example:\r\n- The Hyperscript remains in the DOM since **`show`** is `True`\r\n- The keys within the dumped data remain in snake case since **`translate`** is `False`\r\n- The variable is scoped to the element the Hyperscript belongs to since **`scope`** is set to `'element'`\r\n- The output is just the raw Hyperscript text since **`wrap`** is set to `False`\r\n\r\n---\r\n## License\r\n\r\nThis project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.\r\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Custom Django template tags for integrating Hyperscript with Django templates.",
"version": "1.0.2",
"project_urls": {
"Documentation": "https://github.com/LucLor06/django-hyperscript#readme",
"Homepage": "https://github.com/LucLor06/django-hyperscript",
"Source": "https://github.com/LucLor06/django-hyperscript",
"Tracker": "https://github.com/LucLor06/django-hyperscript/issues"
},
"split_keywords": [
"django",
"hyperscript",
"template-tags",
"frontend",
"backend-integration"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "8741334538db28fcb292ff27cef6c1cb9d6f26dbfb5fbd14ab7046c9c6e8639b",
"md5": "2b6d3ff7139551a72d2cef0f99214124",
"sha256": "8cf96a01e2b41517121cd185c49a79b00a9348da7d7581e2fdc033cdac634e8b"
},
"downloads": -1,
"filename": "django_hyperscript-1.0.2-py3-none-any.whl",
"has_sig": false,
"md5_digest": "2b6d3ff7139551a72d2cef0f99214124",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.6",
"size": 5791,
"upload_time": "2024-11-19T18:22:56",
"upload_time_iso_8601": "2024-11-19T18:22:56.438625Z",
"url": "https://files.pythonhosted.org/packages/87/41/334538db28fcb292ff27cef6c1cb9d6f26dbfb5fbd14ab7046c9c6e8639b/django_hyperscript-1.0.2-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "f92743bca1061b5af2c493dc689ddb2d94d4f19989e190651751898bb64eda35",
"md5": "a73c6d655d7746aa7233a1bf8dc7707a",
"sha256": "adf926a7ebb767117a467c359c1fed1cdcb5e64ece91cd3bcbd0bec56909421d"
},
"downloads": -1,
"filename": "django_hyperscript-1.0.2.tar.gz",
"has_sig": false,
"md5_digest": "a73c6d655d7746aa7233a1bf8dc7707a",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.6",
"size": 5205,
"upload_time": "2024-11-19T18:22:58",
"upload_time_iso_8601": "2024-11-19T18:22:58.067302Z",
"url": "https://files.pythonhosted.org/packages/f9/27/43bca1061b5af2c493dc689ddb2d94d4f19989e190651751898bb64eda35/django_hyperscript-1.0.2.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-11-19 18:22:58",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "LucLor06",
"github_project": "django-hyperscript",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "django-hyperscript"
}