tagout
A small, pythonic, HTML/XML writer.
Installation
$ pip install tagout
Usage
This example shows how to use component functions to easily compose a document.
import contextlib
import sys
import io
from tagout import Document, class_names
@contextlib.contextmanager
def layout(doc):
"""Site layout component that allows transclusion of content."""
doc.write('<!DOCTYPE html>')
with doc.tag('html', lang='en'):
with doc.tag('head'):
with doc.tag('meta', charset='utf-8'):
pass
with doc.tag('meta', name='viewport', content='width=device-width, initial-scale=1, shrink-to-fit=no'):
pass
with doc.tag(
'link',
rel='stylesheet',
href='https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css',
integrity='sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh',
crossorigin='anonymous'
):
pass
with doc.tag('title'):
doc.text('tagout')
with doc.tag('body'):
with doc.tag('div', _class='container'):
# transclude content
yield
def module_component(doc, module):
"""Site module name list item component."""
is_private = module.startswith('_')
# the `class_names` utility function can be used to conditionally add class names
with doc.tag('li', _class=class_names({'text-danger': is_private})):
doc.text(module)
def write_doc(stream):
doc = Document(stream, self_closing=True)
with layout(doc):
# the layout component is a context manager and allows for transclusion
# the leading underscore will be removed from keyword attributes
# this is useful for the `class` attribute since it happens to be a python keyword
with doc.tag('h1', _class='text-primary'):
doc.text('<tagout>')
with doc.tag('p'):
doc.text('A small, pythonic, HTML/XML writer.')
with doc.tag('h2'):
doc.text('Modules')
with doc.tag('ul'):
# loops can be used to generate multiple components
for module in sys.modules:
# the module component takes in data
module_component(doc, module)
if __name__ == '__main__':
# the document can be written to a file-like object
with open('index.html', 'w') as output_file:
write_doc(output_file)
# the document can be written to an io.StringIO instance to get a string
output_string = io.StringIO()
write_doc(output_string)
print(output_string.getvalue())
Metadata
Release files for tagout 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| tagout-1.0.0.tar.gz | 3.8 kB | Without provenance | Details for tagout-1.0.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| tagout-1.0.0-py3-none-any.whl | Python 3 | none | any | Details for tagout-1.0.0-py3-none-any.whl |
Total release size: 8.6 kB
Release files / tagout-1.0.0.tar.gz
| Download URL | tagout-1.0.0.tar.gz |
|---|---|
| Size | 3.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
bb8e869080852622a07c40f84d2cde7a5aec9bd0e875cacf8b03080235727728
|
|
BLAKE2b-256 checksum How to use checksums |
60b40b16e483e57cc42b0ea597ccf23528ef6b725f788e6c05a75ea614ff2dab
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.8.2
|
Release files / tagout-1.0.0-py3-none-any.whl
| Download URL | tagout-1.0.0-py3-none-any.whl |
|---|---|
| Size | 4.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
75649ac256ca516e3d03329612bc56a1561409c42a64e00cc6b37d0c8dc42ad3
|
|
BLAKE2b-256 checksum How to use checksums |
ebb6edaa7a60c49761aa10b3d39de64b2d7423444a62c10e3f0c5a261389602c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.8.2
|
Security for tagout 1.0.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.