ketza


Nameketza JSON
Version 2.0.1 PyPI version JSON
download
home_page
SummaryA python engine for building html components
upload_time2024-01-01 19:20:35
maintainer
docs_urlNone
author
requires_python>=3.6
license
keywords html ketza web full stack
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Ketza - HTML defined in python

### Contents

- [Rationale](#rationale)
- [Basics](#basics) 
- [Example with an unordered list](#example-with-an-unordered-list)
- [Formatting](#formatting)
- [Future Intentions](#future-intentions)

## Rationale

This project provides a framework for defining reusable units of HTML in
python code, as opposed to being a runtime or a templating engine.

My intention is to provide a powerful but simple interface, allowing for 
extensibility and interplay with other technologies without headaches.

## Basics

At the core of Ketza is the `tag` function, which allows you to build a 
html element in a series of function calls as follows:
```python
from ketza import tag

main = tag("main") # Apply element name

app = main({"id": "app"}) # Apply attributes as key-value pairs

hello_world = app("Hello World!") # Apply inner string content

# hello_world is now equal to `<main id="app">Hello World!</main>`
```

However, Ketza also provides pre-defined named tags for recognised 
HTML elements based on the WHATWG living standard.
A further example is presented below, making use of predefined tags.

## Example with an unordered list

Let's say, for argument's sake, I would like to define a list like this:
```html
<ul id="list-of-three">
    <li class="list-triplet">
        Foo
    </li>
    <li class="list-triplet">
        Bar
    </li>
    <li class="list-triplet">
        Baz
    </li>
</ul>
```

This can be done as follows:
```python
from ketza import ul, li

list_of_three = ul({"id": "list-of-three"})(
    li({"class": "list-triplet"})(
        "Foo"
    ),
    li({"class": "list-triplet"})(
        "Bar"
    ),
    li({"class": "list-triplet"})(
        "Baz"
    ),
)
```

However, we can simplify this even further:
```python
from ketza import ul, li

triplet = li({"class": "list-triplet"})

list_of_three = ul({"id": "list-of-three"})(
    triplet("Foo"),
    triplet("Bar"),
    triplet("Baz")
)
```

For our purposes, this yields html which is functionally equivalent to our
intended `list-of-three`. Even so, the raw html will look more like this:

```html
<ul id="list-of-three"><li class="list-triplet">Foo</li><li class=.... 
```

While this does essentially result in pre-minified HTML output, there are 
situations which call for human-readable raw HTML. As such, the following
section shall briefly touch on formatting.

## Formatting

Ketza provides a utility function for indenting minified html:
```python
from ketza.formatters import indent 

list_of_three = indent(list_of_three)
```

The `indent` function turns this:
```html
<ul id="list-of-three"><li class="list-triplet">Foo</li><li class=.... 
```

Into this!
```html
<ul id="list-of-three">
    <li class="list-triplet">
        Foo
    </li>
    <li class="list-triplet">
        Bar
    </li>
    <li class="list-triplet">
        Baz
    </li>
</ul>
```

## Future Intentions

Though I am confident that Ketza provides the means to define 
components representing common HTML boilerplate, I am also considering
defining utilities to further streamline HTML boilerplate creation.

I am also open to feedback for how I can improve and 
extend Ketza, as well as its interoperability with other web technologies.


            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "ketza",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.6",
    "maintainer_email": "",
    "keywords": "html,ketza,web,full stack",
    "author": "",
    "author_email": "Charlie Paterson <Charlieed.paterson@googlemail.com>",
    "download_url": "https://files.pythonhosted.org/packages/3a/ce/adb1a05d13c94ce71751b8a523467910bb93739b37c28ab900750af4831b/ketza-2.0.1.tar.gz",
    "platform": null,
    "description": "# Ketza - HTML defined in python\n\n### Contents\n\n- [Rationale](#rationale)\n- [Basics](#basics) \n- [Example with an unordered list](#example-with-an-unordered-list)\n- [Formatting](#formatting)\n- [Future Intentions](#future-intentions)\n\n## Rationale\n\nThis project provides a framework for defining reusable units of HTML in\npython code, as opposed to being a runtime or a templating engine.\n\nMy intention is to provide a powerful but simple interface, allowing for \nextensibility and interplay with other technologies without headaches.\n\n## Basics\n\nAt the core of Ketza is the `tag` function, which allows you to build a \nhtml element in a series of function calls as follows:\n```python\nfrom ketza import tag\n\nmain = tag(\"main\") # Apply element name\n\napp = main({\"id\": \"app\"}) # Apply attributes as key-value pairs\n\nhello_world = app(\"Hello World!\") # Apply inner string content\n\n# hello_world is now equal to `<main id=\"app\">Hello World!</main>`\n```\n\nHowever, Ketza also provides pre-defined named tags for recognised \nHTML elements based on the WHATWG living standard.\nA further example is presented below, making use of predefined tags.\n\n## Example with an unordered list\n\nLet's say, for argument's sake, I would like to define a list like this:\n```html\n<ul id=\"list-of-three\">\n    <li class=\"list-triplet\">\n        Foo\n    </li>\n    <li class=\"list-triplet\">\n        Bar\n    </li>\n    <li class=\"list-triplet\">\n        Baz\n    </li>\n</ul>\n```\n\nThis can be done as follows:\n```python\nfrom ketza import ul, li\n\nlist_of_three = ul({\"id\": \"list-of-three\"})(\n    li({\"class\": \"list-triplet\"})(\n        \"Foo\"\n    ),\n    li({\"class\": \"list-triplet\"})(\n        \"Bar\"\n    ),\n    li({\"class\": \"list-triplet\"})(\n        \"Baz\"\n    ),\n)\n```\n\nHowever, we can simplify this even further:\n```python\nfrom ketza import ul, li\n\ntriplet = li({\"class\": \"list-triplet\"})\n\nlist_of_three = ul({\"id\": \"list-of-three\"})(\n    triplet(\"Foo\"),\n    triplet(\"Bar\"),\n    triplet(\"Baz\")\n)\n```\n\nFor our purposes, this yields html which is functionally equivalent to our\nintended `list-of-three`. Even so, the raw html will look more like this:\n\n```html\n<ul id=\"list-of-three\"><li class=\"list-triplet\">Foo</li><li class=.... \n```\n\nWhile this does essentially result in pre-minified HTML output, there are \nsituations which call for human-readable raw HTML. As such, the following\nsection shall briefly touch on formatting.\n\n## Formatting\n\nKetza provides a utility function for indenting minified html:\n```python\nfrom ketza.formatters import indent \n\nlist_of_three = indent(list_of_three)\n```\n\nThe `indent` function turns this:\n```html\n<ul id=\"list-of-three\"><li class=\"list-triplet\">Foo</li><li class=.... \n```\n\nInto this!\n```html\n<ul id=\"list-of-three\">\n    <li class=\"list-triplet\">\n        Foo\n    </li>\n    <li class=\"list-triplet\">\n        Bar\n    </li>\n    <li class=\"list-triplet\">\n        Baz\n    </li>\n</ul>\n```\n\n## Future Intentions\n\nThough I am confident that Ketza provides the means to define \ncomponents representing common HTML boilerplate, I am also considering\ndefining utilities to further streamline HTML boilerplate creation.\n\nI am also open to feedback for how I can improve and \nextend Ketza, as well as its interoperability with other web technologies.\n\n",
    "bugtrack_url": null,
    "license": "",
    "summary": "A python engine for building html components",
    "version": "2.0.1",
    "project_urls": {
        "Homepage": "https://github.com/CpaterCodes/Ketza"
    },
    "split_keywords": [
        "html",
        "ketza",
        "web",
        "full stack"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "eea4999ad0b815828547cc946efe2d733c93fd8da3f40b0f9bb05c452d7ea864",
                "md5": "7f1e281b6b1f9c2b4581194cc0779e58",
                "sha256": "8ad627d353c07a07d9d4805c9cd682b3b3775d9d1e653aae2d5b24065b1e4290"
            },
            "downloads": -1,
            "filename": "ketza-2.0.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "7f1e281b6b1f9c2b4581194cc0779e58",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.6",
            "size": 4651,
            "upload_time": "2024-01-01T19:20:34",
            "upload_time_iso_8601": "2024-01-01T19:20:34.066881Z",
            "url": "https://files.pythonhosted.org/packages/ee/a4/999ad0b815828547cc946efe2d733c93fd8da3f40b0f9bb05c452d7ea864/ketza-2.0.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "3aceadb1a05d13c94ce71751b8a523467910bb93739b37c28ab900750af4831b",
                "md5": "b220b17bc305aca979d2c04d258df01b",
                "sha256": "b1478b79b62e68e68e2faeb6a1e7b642901e447a141882b354ba139cc2b06006"
            },
            "downloads": -1,
            "filename": "ketza-2.0.1.tar.gz",
            "has_sig": false,
            "md5_digest": "b220b17bc305aca979d2c04d258df01b",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.6",
            "size": 5236,
            "upload_time": "2024-01-01T19:20:35",
            "upload_time_iso_8601": "2024-01-01T19:20:35.658034Z",
            "url": "https://files.pythonhosted.org/packages/3a/ce/adb1a05d13c94ce71751b8a523467910bb93739b37c28ab900750af4831b/ketza-2.0.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-01-01 19:20:35",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "CpaterCodes",
    "github_project": "Ketza",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "ketza"
}
        
Elapsed time: 0.50925s