Slim templates syntax for Jinja2.
This release breaks compatibility. Parsing = for Jinja Output is complex. I dropped it in favor of directly using {{ jinja_output }}.
This release(1.0) onwards, the backward syntax compatibility will be maintained.
Installation
pip install slimish_jinja
Examples of using it as Jinja2 extension(jinja_demo.py),
with Flask(flask_demo.py) and standalone(convert.py and demo.py) are bundled.
If you want to use it for any other purpose, the lexer - lexer.py and parser - parser.py are simple enough.
lexer reads the input by lines and generates tokens. parser implements a hand rolled recursive descent parser.
For quick reference, this slim::
!5
html
head
/ Inline static content.
title
- block title
|Slimish-Jinja Example
/ Self closing tag with attributes.
meta name="keywords" content="template language"
%script type="text/javascript" src="{{ ASSET_URL }}"
script
/ Empty jinja tag.
@block script
/ 'id' and 'class' shortcut.
body#home.fluid.liquid
/ Nested static content.
h1
|This is my header.
/ 'div' with 'id' and 'class' shortcut.
#contents.main
/ Empty html tag.
%div
p Dynamic {{ content }}
p
|Nested dyanmic {{ content }}
Left indent is preserved in text blocks.
p
|<a href="http://www.google.com">Google</a>
/ Dynamic attributes.
ul class="{{ user_class }}"
/ Jinja tag.
- for user in users
li {{ user.name }}
- if user.last_name
li {{ user.last_name }}
- elif user.middle_name
li {{ user.middle_name }}
- else
li No user found.
converts to::
<!doctype html>
<html>
<head>
<title>
{% block title %}
Slimish-Jinja Example
{% endblock %}
</title>
<meta content="template language" name="keywords"/>
<script>
{% block script %}{% endblock %}
</script>
</head>
<body id="home" class="fluid liquid">
<h1>
This is my header.
</h1>
<div id="contents" class="main">
<div></div>
<p>Dynamic {{ content }}</p>
<p>
Nested dyanmic {{ content }} Left indent is preserved in text blocks.
</p>
<p>
<a href="http://www.thoughtnirvana.com">ThoughtNirvana</a>
</p>
</div>
<ul class="{{ user_class }}">
{% for user in users %}
<li>{{ user.name }}</li>
{% if user.last_name %}
<li>{{ user.last_name }}</li>
{% elif user.middle_name %}
<li>{{ user.middle_name }}</li>
{% endif %}
{% else %}
<li>No user found.</li>
{% endfor %}
</ul>
</body>
</html>
Doctype delcarations.
!html
<!DOCTYPE html>
!5
<!DOCTYPE html>
!1.1
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
!strict
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
!frameset
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">
!mobile
<!DOCTYPE html PUBLIC "-//WAPFORUM//DTD XHTML Mobile 1.2//EN" "http://www.openmobilealliance.org/tech/DTD/xhtml-mobile12.dtd">
!basic
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML Basic 1.1//EN" "http://www.w3.org/TR/xhtml-basic/xhtml-basic11.dtd">
!transitional
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
!strict
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
!frameset
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">
!transitional
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
Static content
/ Inline static content.
h1 This is my header
/ Nested static content.
h1
|This is my header
/ Multiline static content.
p
|Span mutliple lines.
Left indent preserved in the output.
Dynamic content
/ Inline
h1 {{ user.title }}
/ Nested
h1
{{ user.title }}
/ Mixed with text.
h1
|The user name is {{ user.name }}
Jinja tags
- for user in users
li {{ user.name }}
- if {{ user.lastname }}
li {{ user.lastname }}
- else
li No users found
Dynamic contents in attribute
a href="{{ user.url }}" {{ user.name }}
id and classname shortcuts
#contents.main.liquid => <div id="contents" class="main liquid">
body#home.left => <body id="home" class="left">
Code comments.
/ Single slash comments.
/ Not part of the output.
p This is content.
Empty html tags
%div => <div></div>
Empty jinja tags.
@block title => {%block title %}{% endblock %}
Metadata
Release files for slimish-jinja 1.1.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 |
|---|---|---|---|---|
| slimish_jinja-1.1.2.tar.gz | 10.1 kB | Without provenance | Details for slimish_jinja-1.1.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| slimish_jinja-1.1.2-py3-none-any.whl | Python 3 | none | any | Details for slimish_jinja-1.1.2-py3-none-any.whl |
Total release size: 21.0 kB
Release files / slimish_jinja-1.1.2.tar.gz
| Download URL | slimish_jinja-1.1.2.tar.gz |
|---|---|
| Size | 10.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
23281b96b97a17cc55557dcf886e865f15aac11a27c003c4538113bb324483c8
|
|
BLAKE2b-256 checksum How to use checksums |
a75a4435818ae7828f468d9db5b8b85633fccc45538df84ae0062475a1d55c33
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.12.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.8.0 tqdm/4.29.1 CPython/3.6.3
|
Release files / slimish_jinja-1.1.2-py3-none-any.whl
| Download URL | slimish_jinja-1.1.2-py3-none-any.whl |
|---|---|
| Size | 10.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
71debf701f0f43e66a47591f33a59a90faf4cb28f2343562081558a4fd3ce554
|
|
BLAKE2b-256 checksum How to use checksums |
565cceb99f35aca169c95fa9caa8df640bac0640fd65903f7f9835f3c372d0bb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.12.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.8.0 tqdm/4.29.1 CPython/3.6.3
|
Security for slimish-jinja 1.1.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.