datasette-css-properties
Extremely experimental Datasette output plugin using CSS properties, inspired by Custom Properties as State by Chris Coyier.
Installation
Install this plugin in the same environment as Datasette.
$ datasette install datasette-css-properties
Usage
Once installed, this plugin adds a .css output format to every query result. This will return the first row in the query as a valid CSS file, defining each column as a custom property:
Example: https://latest-with-plugins.datasette.io/fixtures/roadside_attractions.css produces:
:root {
--pk: '1';
--name: 'The Mystery Spot';
--address: '465 Mystery Spot Road, Santa Cruz, CA 95065';
--latitude: '37.0167';
--longitude: '-122.0024';
}
If you link this stylesheet to your page you can then do things like this;
<link rel="stylesheet" href="https://latest-with-plugins.datasette.io/fixtures/roadside_attractions.css">
<style>
.attraction-name:after { content: var(--name); }
</style>
<p class="attraction-name">Attraction name: </p>
Values will be quoted as CSS strings by default. If you want to return a "raw" value without the quotes - for example to set a CSS property that is numeric or a color, you can specify that column name using the ?_raw=column-name parameter. This can be passed multiple times.
Consider this example query:
select
'#' || substr(sha, 0, 6) as [custom-bg]
from
commits
order by
author_date desc
limit
1;
This returns the first 6 characters of the most recently authored commit with a # prefix. The .css output rendered version looks like this:
:root {
--custom-bg: '#97fb1';
}
Adding ?_raw=custom-bg to the URL produces this instead:
:root {
--custom-bg: #97fb1;
}
This can then be used as a color value like so:
h1 {
background-color: var(--custom-bg);
}
Development
To set up this plugin locally, first checkout the code. Then create a new virtual environment:
cd datasette-css-properties
python3 -mvenv venv
source venv/bin/activate
Or if you are using pipenv:
pipenv shell
Now install the dependencies and tests:
pip install -e '.[test]'
To run the tests:
pytest
Metadata
Release files for datasette-css-properties 0.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 | Actions |
|---|---|---|---|---|
| datasette-css-properties-0.2.tar.gz | 3.6 kB | Without provenance | Details for datasette-css-properties-0.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| datasette_css_properties-0.2-py3-none-any.whl | Python 3 | none | any | Details for datasette_css_properties-0.2-py3-none-any.whl |
Total release size: 7.2 kB
Release files / datasette-css-properties-0.2.tar.gz
| Download URL | datasette-css-properties-0.2.tar.gz |
|---|---|
| Size | 3.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d40593f149f6b5d0cbde5a159a9393e6ffd22a7fb04464f88f26df92dcea86ec
|
|
BLAKE2b-256 checksum How to use checksums |
4cab0132b715bf3660def1b256804313595e63c3e6030f4d300ae44aa2f7f2d4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.3.0 pkginfo/1.6.1 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.55.1 CPython/3.9.1
|
Release files / datasette_css_properties-0.2-py3-none-any.whl
| Download URL | datasette_css_properties-0.2-py3-none-any.whl |
|---|---|
| Size | 3.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
b8da3521221ced08394607099dc709052c42b96b70f19457b7d87c406d1bc27c
|
|
BLAKE2b-256 checksum How to use checksums |
5fa48a710e32c0e6bb3002cb0c00b672af73885a3b2a50b45713e6320f66eefb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.3.0 pkginfo/1.6.1 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.55.1 CPython/3.9.1
|
Security for datasette-css-properties 0.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.