Last active

A quick concept of a pythonic templating language based on Zen Coding, with inspiration from HAML and SASS.

  • Download Gist
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
#### Template (proposed, unnamed language)
title= {{ title }}
def navbar(links):
#### Output (HTML)
<!DOCTYPE html>
<link rel='stylesheet' href='my_stylesheet.css' />
<script src='my_script.js'></script>
<title>My Page Title</title>
<div class='container'>
<div class='navbar'>
<li class='navbar-link'>
<a href='/'>Home</a>
<li class='navbar-link'>
<a href='/about'>About</a>
<li class='navbar-link'>
<a href='/faq'>FAQ</a>
#### Context (Python)
title = 'My Page Title'
main_menu_links = (
('/', 'home'),
('/about', 'about')
('/faq', 'faq')

The first idea here that I believe is unique is that I'd like to be able to switch between nesting HTML via indentation level (a'la HAML and JADE) and Zen Coding's syntax. The following snippets:




would produce the same output:


The second is that I'd like to be able to leverage Zen Coding's syntax in conjunction with Python's iterators. While Zen allowed you to create multiple elements by specifying a multiplier (e.g., ul>li*5 would get you 5 li elements under a ul), generators don't know their own length.


The iterlinks() method in the above would accept a generator or 2-tuples and iterate over them until they it was exhausted. The ? character signifies that the element in the chain is to be iterated without specifying the number of iterations as Zen Coding would require.

Just in case this goes somewhere, a nod to Stickyworld for their blog post The war on curly braces and angle brackets, which I found on Reddit's /r/python/ and inspired me to consider what I want in a templating language.

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.