Simple and smart template engine to generate HTML/XML
Project description
Shrubbery is a Smart Html Renderer Using Blocks to Bind Expressions Repeatedly. You can also think of it as the “world’s easiest templating engine”. Templates hold no logic whatsoever, with nodes being repeated as needed by the replacement data. Here’s a simple example:
>>> from shrubbery.template import Template >>> template = """ ... <ul> ... <li>{todo.task}: {todo.description}</li> ... </ul>""" >>> t = Template(template)
We can pass a single value as the todo expression:
>>> data = {"todo": {"task": "Work", ... "description": "Finish article for GRL."}} >>> print t.process(data).prettify() <ul> <li> Work: Finish article for GRL. </li> </ul>
Nothing to see here. Let’s pass a list instead, with more tasks:
>>> data = {"todo": [{"task": "Work", ... "description": "Finish article for GRL."}, ... {"task": "Play", ... "description": "Finish next version of Shrubbery"}]} >>> print t.process(data).prettify() <ul> <li> Work: Finish article for GRL. </li> <li> Play: Finish next version of Shrubbery </li> </ul>
We can even pass a nested list:
>>> data = {"todo": [{"task": "Work", ... "description": "Finish article for GRL."}, ... {"task": "Play", ... "description": ["Finish next version of Shrubbery", ... "Eat some pretzels"]}]} >>> print t.process(data).prettify() <ul> <li> Work: Finish article for GRL. </li> <li> Play: Finish next version of Shrubbery </li> <li> Play: Eat some pretzels </li> </ul>
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
shrubbery-0.2.tar.gz
(4.6 kB
view hashes)
Built Distribution
shrubbery-0.2-py2.5.egg
(9.4 kB
view hashes)