Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/nosamanuel/cottonmouth
Pure-Python HTML generation
https://github.com/nosamanuel/cottonmouth
Last synced: 4 months ago
JSON representation
Pure-Python HTML generation
- Host: GitHub
- URL: https://github.com/nosamanuel/cottonmouth
- Owner: nosamanuel
- License: bsd-3-clause
- Created: 2013-07-10T19:54:28.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2021-04-12T04:07:49.000Z (almost 4 years ago)
- Last Synced: 2024-08-08T15:47:30.414Z (6 months ago)
- Language: Python
- Size: 12.7 KB
- Stars: 15
- Watchers: 2
- Forks: 4
- Open Issues: 11
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-python-html - nosamanuel/cottonmouth - Python HTML generation (Libraries / General HTML Generation)
- awesome-python-html - nosamanuel/cottonmouth - Python HTML generation (Libraries / General HTML Generation)
README
cottonmouth
===========Pure-Python HTML generation, inspired by [Hiccup][1].
```python
from cottonmouth.html import render
from cottonmouth.tags import html, head, body, title, meta, link, h1def welcome(user=None, **context):
return ['p', 'Welcome' + (' back!' if user else '!')]content = (
# Feel free to use raw 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
The Site
Welcome to the site!
Welcome!
```
### 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'render(['.foo', {'class': ['bar', 'baz']}])
'
# u'
```### Installation
pip install cottonmouth
### Testing
python setup.py test
### License
BSD Copyright 2013, Noah Seger
[1]: https://github.com/weavejester/hiccup