Hyperscript dump is a simple python library for turning python data into raw _hyperscript.
- Install using pip:
pip install hyperscript-dump- Import and use
build_hyperscriptwhere needed
from hyperscript_dump import build_hyperscriptbuild_hyperscript turns python data into raw hyperscript.
build_hyperscript(data, name='myData')will return hyperscript like:
"""
init
set global myData to {'key': 'value'}
then remove me
end
"""build_hyperscript has a set of additional keyword arguments to configure its behavior.
Type: bool | Default: False
Keeps the element the hyperscript is on in the DOM after initializing if True.
Type: bool | Default: False
Sets the data as a property on the element rather than a hyperscript variable. Useful when needing to access data on a different element that isn't an attribute.
Note: The scope kwarg is ignored when this is True.
Type: bool | Default: True
"Camelizes" dictionary keys from snake case (snake_case) to camel case (camelCase) to fit JavaScript naming conventions.
Type: bool | Default: False
Each key value pair in a dictionary is assigned as a separate variable, rather than as a single object.
Note: Requires data to be a dictionary.
Type: str | Default: global
Determines the scope of the hyperscript variable (global, element, or local).
Type: str, None | Default: init
Specifies the event that triggers assignment. The hyperscript "on" keyword should not need be provided. When set to none only the hyperscript assignment statements will be returned.
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.
Type: bool | Default: False
Logs the set variable name(s) and value(s).
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'
This project is licensed under the MIT License - see the LICENSE file for details.