CSS & HTML on Python Easily
Project description
Chope
CSS & HTML on Python Easily.
Chope is a library that aims to provide a HTML and CSS domain-specific language (DSL) for Python. It draws inspiration from Clojure's Hiccup and Emotion.
Install
pip install chope
Syntax
Here is a basic example of Chope syntax:
from chope import *
from chope.css import *
page = html[
head[
style[
Css[
'body': dict(
background_color='linen',
font_size=pt/12
),
'.inner-div': dict(
color='maroon',
margin_left=px/40
)
]
]
],
body[
h1['Title'],
div(class_='outer-div')[
div(class_='inner-div')[
'Some content.
]
]
]
]
HTML
Declaring an element is as simple as this:
# <div>content</div>
div['content']
Element attributes can be specified like so:
# <div id="my-id" class="my-class your-class">content</div>
div(id='my-id', class_='my-class your-class')['content']
Notice the _
suffix in the class_
attribute. This suffix is necessary for any attribute names that clashes with any Python keyword.
You can also define id
and class
using CSS selector syntax:
# <div id="my-id" class="my-class your-class" title="Title">content</div>
div('#my-id.my-class.your-class', title='Title')['content']
Iterables can be used to generate a sequence of elements in the body of an element.
# <ul><li>0</li><li>1</li><li>2</li></ul>
ul[
(li[str(i)] for i in range(3))
]
CSS
The CSS syntax in Chope is simply a mapping between CSS selector strings and declarations dictionaries.
Here's how a CSS stylesheet looks like in Chope:
Css[
'h1': dict(
background_color='linen',
text_align='center'
),
'.btn.warning': dict(
opacity=0.5
),
'.btn.warning:hover': dict(
opacity=1
)
]
Which is equivalent to:
{
h1 {
background-color: linen;
text-align: center;
}
.btn.warning {
opacity: 0.5;
}
.btn.warning:hover {
opacity: 1;
}
}
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file chope-0.1.1.tar.gz
.
File metadata
- Download URL: chope-0.1.1.tar.gz
- Upload date:
- Size: 6.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.16
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | fd86f286668aef9e6b02fd9a7db31d3902c41344252747ad9cc7cc1640718a01 |
|
MD5 | 0441c80cfe0eddd815543d0e9776d8f0 |
|
BLAKE2b-256 | ea10b4b838dc7440bb88bc64549867e386e4730b66336897a9f16212c9b14145 |
File details
Details for the file chope-0.1.1-py3-none-any.whl
.
File metadata
- Download URL: chope-0.1.1-py3-none-any.whl
- Upload date:
- Size: 5.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.16
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f55633bec51deffbe6b0a5e7f79b42dd32295275158469169142d756685f54af |
|
MD5 | 5e7479ba295c1cc518f7cb59e51a1488 |
|
BLAKE2b-256 | 9ca8a0c1f4d1bf2bd58a93ddf3b72a2c84a573d7531b75a8bd7306e6f26f1655 |