Skip to main content

Convert Python data structures into Hyperscript-compatible code blocks.

Project description

Hyperscript Dump

Hyperscript dump is a simple python library for turning python data into raw hyperscript.


Installation

  1. Install using pip:
pip install hyperscript-dump
  1. Import and use build_hyperscript where needed
from hyperscript_dump import build_hyperscript

Usage

build_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
"""

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.

flatten

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.

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 preserve is True
  • The keys within the dumped data remain in snake case since camelize is False
  • The variable is scoped to the element the Hyperscript belongs to since scope is set to 'element'

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

hyperscript_dump-1.0.3.tar.gz (4.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

hyperscript_dump-1.0.3-py3-none-any.whl (4.4 kB view details)

Uploaded Python 3

File details

Details for the file hyperscript_dump-1.0.3.tar.gz.

File metadata

  • Download URL: hyperscript_dump-1.0.3.tar.gz
  • Upload date:
  • Size: 4.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.0

File hashes

Hashes for hyperscript_dump-1.0.3.tar.gz
Algorithm Hash digest
SHA256 422f1ebdcbfab3109d08ba80bcb8825f9568be2db6f3544760951f67f834b0bf
MD5 72c0c2601c2b3153d3805cb9cd4e5538
BLAKE2b-256 64d835c6d9fc7b6dec51854c13121d5bfb48840ee2fb12581065ec77846fe207

See more details on using hashes here.

File details

Details for the file hyperscript_dump-1.0.3-py3-none-any.whl.

File metadata

File hashes

Hashes for hyperscript_dump-1.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 d5cb1b122b5b429163fa04e2122e5cad9961ed111f01d5e14e43368fcbd7f303
MD5 1b621ac4aa5a2e9af7b8c44f7cb3d3e1
BLAKE2b-256 bd8125a64776f8f6381ab1098bc407451c30b38faedeafd7db0f9f7a70a9d785

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page