Lektor Polymorphic Type
This plugin adds a new polymorphic lektor field type, polymorphic.
The determination of the actual type implementation of the field value
is deferred until evaluation time.
A motivating use case is to support having a “body” field whose
formatting can be switched between, e.g., markdown, and html (or
some other formatted type, such as reStructuredText.)
Installation
Add lektor-polymorphic-type to your project from command line:
lektor plugins add lektor-polymorphic-type
See the Lektor plugin documentation for more information.
How It Works
If the field has a polymorphic_type option set, that value is evaluated
and the result is interpreted as the name of the final type for the
field.
If no polymorphic_type option is set for the field, then we look for a
field on the current record whose name is name of the current field
with “_type” appended.
Examples
Simple Example
Here is an example model file for a simple page, with a selectable body format:
# page.ini
[model]
name = Page
label = {{ this.title }}
[fields.title]
label = Title
type = string
[fields.body]
label = Body
type = polymorphic
[fields.body_type]
label = Body Type
type = select
choices = markdown, html, text
default = markdown
Here, the value of the body_type field on a particular page will
determine whether the body field is interpreted as being markdown,
html or text.
Contrived Example
Here is a contrived example showing the use of the polymorphic_type option:
# page.ini
[model]
name = Page
label = {{ this.title }}
[fields.title]
label = Title
type = string
[fields.body]
label = Body
type = polymorphic
polymorphic_type = 'html' if this.body.lstrip().startswith('<') else 'markdown'
In this case, the body field will be interpreted as raw HTML if the
content of that field starts with a “<”, otherwise it will be
interpreted as Markdown text.
Author
Jeff Dairiki dairiki@dairiki.org
Changelog
0.1 — 2021-02-05
No code changes.
Update development status classifier to "stable".
Test under python 3.9. Stop testing under 3.5.
0.1b1 — 2020-05-04
Initial release.
Metadata
Release files for lektor-polymorphic-type 0.1
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 |
|---|---|---|---|---|
| lektor-polymorphic-type-0.1.tar.gz | 8.9 kB | Without provenance | Details for lektor-polymorphic-type-0.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| lektor_polymorphic_type-0.1-py2.py3-none-any.whl | Python 2, Python 3 | none | any | Details for lektor_polymorphic_type-0.1-py2.py3-none-any.whl |
Total release size: 13.6 kB
Release files / lektor-polymorphic-type-0.1.tar.gz
| Download URL | lektor-polymorphic-type-0.1.tar.gz |
|---|---|
| Size | 8.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
2f348940430a9339f28f0bba80cb151ea40d4e39cf75e1f73ffed3c3b826a326
|
|
BLAKE2b-256 checksum How to use checksums |
b6f17a2ac865e2cd3ad4e11447882e19b90cac9fb5baa192296fc6cdd32085ca
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/52.0.0 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.9.0+
|
Release files / lektor_polymorphic_type-0.1-py2.py3-none-any.whl
| Download URL | lektor_polymorphic_type-0.1-py2.py3-none-any.whl |
|---|---|
| Size | 4.6 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
b5539d4badcca0ec548544341fd95e888c2fd948e57852cf096d44c39ae6fd4f
|
|
BLAKE2b-256 checksum How to use checksums |
44a56e415da4b447642a5765fee67fccbf1a76d01e5b8cc1671fde83c92e3932
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/52.0.0 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.9.0+
|
Security for lektor-polymorphic-type 0.1
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.