===========
Pure-Python HTML generation, inspired by [Hiccup][1].
```python
from cottonmouth.html import render
from cottonmouth.tags import html, head, body, title, meta, link, h1
def welcome(user=None, **context):
return ['p', 'Welcome' + (' back!' if user else '!')]
content = (
# Feel free to use raw HTML
'<!doctype html>',
# Tags are represented as sequences with a tag name at the head
[html,
# Or just use strings instead of the default tag symbols
['head',
[title, 'The Site'],
# Attributes are passed as a dict immediately after the tag
[meta, {'charset': 'utf-8'}],
[link, dict(rel='stylesheet', type='text/css',
href='static/layout.css')]],
[body,
# You can also call tags as functions with the content as
# the first argument and attributes as `kwargs`
[header, h1(u'The Website', id='header')],
# Use "#id.class" shortcuts to easily create `div` elements
['#map.pretty-map'],
# Functions will be called with context and the results rendered
['#main', welcome]]]
)
render(*content, user=None)
```
Equivalent output:
```html
<!doctype html>
<html>
<head>
<title>The Site</title>
<meta content="text/html;charset=utf-8" http-equiv="content-type">
<link href="static/layout.css" type="text/css" rel="stylesheet">
</head>
<body>
<h1 id="header">Welcome to the site!</h1>
<div id="map" class="pretty-map"></div>
<div id="main">
<p>Welcome!</p>
</div>
</body>
</html>
```
### Classes
There's a shortcut for dynamic classes: strings or iterables of classnames are automatically appended to the sugared classname!
```python
render(['.foo', {'class': 'bar baz'}])
# u'<div class="foo bar baz"></div>'
render(['.foo', {'class': ['bar', 'baz']}])
# u'<div class="foo bar baz"></div>'
```
### Installation
pip install cottonmouth
### Testing
python setup.py test
### License
BSD Copyright 2013, Noah Seger
[1]: https://github.com/weavejester/hiccup
Metadata
Release files for cottonmouth 0.2.2
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 | |
|---|---|---|---|---|
| cottonmouth-0.2.2.tar.gz | 4.6 kB | Without provenance | Details |
Release files / cottonmouth-0.2.2.tar.gz
| Download URL | cottonmouth-0.2.2.tar.gz |
|---|---|
| Size | 4.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d3c5f30bf27b28870e05ba9078abb7aeb2ec0745c73ce3920dba20c11c49b424
|
|
BLAKE2b-256 checksum How to use checksums |
86b6f32e288b52edac07ae9b0403a80275dc279638d2930ea64d2ba52a2f9673
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for cottonmouth 0.2.2
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.