#### Template (proposed, unnamed language) | |
doctype(5) | |
html>head | |
style('my_stylesheet.css') | |
script('my_script.js') | |
title= {{ title }} | |
body>div.container | |
navbar(main_menu_links) | |
def navbar(links): | |
div.navbar>ul>li.navbar-link*?>iterlinks(main_menu_links) | |
#### Output (HTML) | |
<!DOCTYPE html> | |
<html> | |
<head> | |
<link rel='stylesheet' href='my_stylesheet.css' /> | |
<script src='my_script.js'></script> | |
<title>My Page Title</title> | |
</head> | |
<body> | |
<div class='container'> | |
<div class='navbar'> | |
<ul> | |
<li class='navbar-link'> | |
<a href='/'>Home</a> | |
</li> | |
<li class='navbar-link'> | |
<a href='/about'>About</a> | |
</li> | |
<li class='navbar-link'> | |
<a href='/faq'>FAQ</a> | |
</li> | |
</ul> | |
</div> | |
</div> | |
</body> | |
</html> | |
#### Context (Python) | |
title = 'My Page Title' | |
main_menu_links = ( | |
('/', 'home'), | |
('/about', 'about') | |
('/faq', 'faq') | |
) |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
Show comment Hide comment
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:
and
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.,
The |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
Show comment Hide comment
lyndsysimon
Aug 9, 2013
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.
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. |
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:
and
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 5li
elements under aul
), 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.