Skip to main content

Python template engine.

Project description

Backslant
=========

Is a template engine built in completely other way then before.

First - you can use all python and you must use it if you want something more
then just tags.

Second - it completely iterative. You can feed iterators or generators as input and get iterative output.

Third - it works through imports. If you want to get template just import it and use. If you want include
other template - import it. If you want template in some dir, import it! Like ```from . import other_template```.
Use absolute or relative imports.

So, with this principles in mind, you can try this proof of concept thing, due it is not complete:

import backslant

sys.meta_path.insert(0, backslant.PymlFinder('./templates', hook='backslant_import'))
from backslant_import.home import index

for chunk in index.render(title='The Real Thing'):
print(chunk)

And templates/home/index.bs:

html
head
title
- yield options['title']
body
div.content#content
h1#header "Header"

You can define a function:

- def render_form(method):
form method=method
input(type="text" value="123")

End call it:

h1
- yield from render_form('POST')

Yes, its this simple, you just use python constructions. And for now inheritance of templates
you can made just with function.

base.bs:

!doctype/ html
html
head
title "Page Title"
body
h1{'class': ' '.join(['main', 'content'], 'ng-app': 'Application'}
| Page Header
div.content
- yield from options['content_block']()
div.footer
| Backslant © 2015

index.bs:

- from . import base
- def content():
- for i in range(10):
p
- yield 'Paragraph {}'.format(i)
- yield from base.render(content_block=content)

I think about adding something like ruby blocks or something to made this a bit more simpler, but
what can be simple then functions define and call?

But we have syntax sugar for this:

:call base.render(*options)
:content_block
- for i in range(10):
p
- yield 'Paragraph {}'.format(i)
:footer_block
p "Index page"

Arguments - you can use arg=`parentised python expression or variable name` or `tag.class {'a': 5, 'b': ' '.join(options.classes)}` form.

I have completed examples with flask and http.server in examples folder. And you can compare perfomance with jinja2. Its almost equal.

I will complete feature set soon, stay tuned.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

backslant-0.2.0.tar.gz (6.9 kB view details)

Uploaded Source

Built Distribution

backslant-0.2.0-py3-none-any.whl (13.2 kB view details)

Uploaded Python 3

File details

Details for the file backslant-0.2.0.tar.gz.

File metadata

  • Download URL: backslant-0.2.0.tar.gz
  • Upload date:
  • Size: 6.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for backslant-0.2.0.tar.gz
Algorithm Hash digest
SHA256 1c88fc7ad878bad7f5e22659b7d3114164822911fcf84a2a98ae2a17fb53d7dd
MD5 cff59f98777130baf2f6bd5259814044
BLAKE2b-256 fe4c0129a18efb5f8735e862fccc05dd32bae6e2226995de086b9974fa5fe7ff

See more details on using hashes here.

File details

Details for the file backslant-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for backslant-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f4f9a1fced81f62701c37dfd04d4dad97e28e6c88d518851f6eb57a67a44a6b3
MD5 a9fd89f2b39323976a150594c9403738
BLAKE2b-256 d38bd78429ee4715222e4640093b5b88ab0a5cf131e3b3a843b556be3d188c50

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page