backslant or python templates engines design guidelines
TRANSCRIPT
DO YOUR OWN JINJA2PYTHON TEMPLATES GUIDELINES
• make ad-hoc loading machinery (template loaders)
• reinvent semi programming language (filters, includes, templatetags)
• hide functions and prohibit direct usage
• make it hard to use with other template engines
• don’t help to generate HTML
FROM DJANGO.TEMPLATE.LOADER IMPORT RENDER_TO_STRING
TEMPLATE LOADING
• reinvent the wheel everytime
• dont use python one
INTEROPERABILITYCOMPATIBILITY
• We want to use this new fast and shiny new templates!
• Rails way — ok, `gem install new_shiny_project`, start to use
• Python way — no way, we need to rewrite everything! Pain and suffer, cry everywhere.
• Why? Jinja2 awaits that loaders return text, not ready to use function.
ALTERNATIVE GUIDELINESBACKSLANT
• use python import to load templates
• functions for everything
• generate HTML from jade/slim/haml like lang
• play nice with jinja2
IN ACTIONBACKSLANT
html body a(href="") 'ABOUT'
<html> <body> <a herf="/genious/link">ABOUT</a> ... </body> </html>
IN ACTIONBACKSLANT
- def input(name, label): div.pretty-input-sm2 label(for=(name)) = name input(name=(name))
- def render(about): html body a(href="") ‘ABOUT' = about form == input(‘username’, ‘Your name’)
import backslantbackslant.install_loader()
from project.templates.main import render
@app.route(‘/‘)def main(req): return backslant.string( render( about=“HELLO” ) )