{
"info": {
"author": "Guido Wesdorp",
"author_email": "johnny@johnnydebris.net",
"bugtrack_url": null,
"classifiers": [
"Development Status :: 3 - Alpha",
"Environment :: Web Environment",
"Intended Audience :: Developers",
"License :: OSI Approved :: Zope Public License",
"Operating System :: OS Independent",
"Programming Language :: Python",
"Topic :: Internet :: WWW/HTTP"
],
"description": "========\nTempless\n========\n\nThis document is valid for Templess 0.3.\n\nWhat is it?\n===========\n\nTempless is an XML templating language for Python, that is very compact and\nsimple, fast, and has a very strict seperation of logic and design. It is\ndifferent from other templating languages because instead of 'asking' for\ndata from the template, you 'tell' the template what content there is to\nrender, and the template just provides placeholders.\n\nDirectives\n==========\n\nThere are only 5 directives in Templess, all of which are defined as\nattributes on an XML node (see the examples below):\n\n * content \n When an XML node has a templess:content attribute, a lookup will be\n done in the context (see the examples below) using the value of the\n attribute as key. If the key can not be found, a KeyError is raised. If\n the value found is a string, it will be used as text content for the\n node. If the value found is a 'lazyrenderer' instance as produced by\n template.render() it will be used as new content for the element (iow,\n you can use template.render() to generate snippets of XML to be placed\n into other trees). If the value is a list node, the element's contents\n will be repeated for each element in the list, interpolating the\n current item into the elements' contents (see list interpolation\n below).\n\n * replace \n Same as content, but instead of 'filling' the node, the node gets\n replaced by the result of the interpolation.\n\n * attr \n The value of an optional templess:attr on an XML node will be split on\n ; to form pairs (strings), which are each split on space (' ') to form\n key, value pairs (so 'foo bar;baz qux' will result in two pairs,\n ('foo', 'bar'), ('baz', 'qux') of which each first item is the key and\n the second the value). For each of those pairs an attribute will be\n added to the XML node, with the key as name, and as value the result of\n a lookup in the context.\n\n * cond \n If the value of the templess:cond condition on an XML node resolves to\n false, the node is removed entirely from the document.\n\n * not\n The reverse of 'cond', this makes the node get rendered if the value\n is false only.\n\nList interpolation\n==================\n\nIf the interpolation value found for a templess:content or templess:replace\nattribute is of a string or a node type, the value will just be added to a\nnode. If the item's value is a list type, the node will be copied and the\ninterpolation will be executed repetetively for each item in the list, using\nthe node as the root and the current value as the context. For each list item\nit will respond in the following manner:\n\n * If the item value is a string type, the value will be used as the\n current element's text attribute.\n\n * If the item value is a node type, it will be attached to the node's\n children.\n\n * If the item value is a dict type, the content interpolation will recurse\n with the exact same behaviour as it has with the full template, using\n the current element as root and the current context value as context (note\n that the root context is not available anymore).\n\nWhen the nodes are all copied, they are attached to the tree if the directive\nused was templess:content, and only their contents are attached to the tree\nif the directive was templess:replace.\n\nExamples\n========\n\nAll of the examples below assume we're in a script with the following lines\nin the top somewhere:\n\n::\n\n >>> from templess import templess\n\nExample 1: simple interpolation\n-------------------------------\n\nAs a first example we'll interpolate the text 'bar' into a node 'foo' in\na simple XML document.\n\n::\n\n >>> xml = \"\"\"\\\n ... \n ... \n ... \n ... \n ... \"\"\"\n >>> context = {\n ... 'foodata': 'bar',\n ... }\n >>> t = templess.template(xml)\n >>> print t.unicode(context) \n \n bar\n \n\nOn calling 'render()' the template is searched for any Templess directives,\nand at some point finds the 't:content' one. When this happens, it will look\nin the context passed in as an argument if there's a key for the value of the\nattribute. In our case the value of the attribute is 'foodata', so it will\nlook for the key 'foodata', and will find the value 'bar'. Since this value\nis a string type, it will set it as the text value for the node, and remove\nthe attribute when it's done.\n\nNote that if the directive used would have been templess:replace, the doc\nelement would get the text contents, and the foo node would have been removed,\nso the XML would look something like ``bar``.\n\nExample 2: node interpolation\n-----------------------------\n\nIn this example we'll interpolate a new XML node into the document. This \nfunctionality provides a simple way to re-use templates.\n\nNote that (XXX currently?) the node needs to be a special Templess node to\nbe interpolated. More convenient ways to add a node (either using an\nAPI that is less Templess specific, or perhaps by allowing XML nodes from other\nlibraries) will be made available in the future.\n\n::\n\n >>> xml = \"\"\"\\\n ... \n ... \n ... \n ... \n ... \"\"\"\n >>> context = {\n ... 'foodata': templess.elnode('bar', {}, None),\n ... }\n >>> t = templess.template(xml)\n >>> print t.unicode(context) \n \n \n \n\nExactly the same happens as with a string, except that instead of setting the\ntext value of the node to the string value of the context, the element\nnode will be used as the new content of the node.\n\nA somewhat more useful example interpolates the results of another template\n(somewhat similar to macros in other systems)::\n\n >>> xml_bar = \"\"\"\\\n ... \n ... \n ... \"\"\"\n >>> context_bar = {\n ... 'bardata': 'baz',\n ... }\n >>> t_bar = templess.template(xml_bar)\n >>> xml = \"\"\"\\\n ... \n ... \n ... \n ... \n ... \"\"\"\n >>> context = {\n ... 'foodata': t_bar.render(context_bar)\n ... }\n >>> t = templess.template(xml)\n >>> print t.unicode(context)\n \n baz\n \n\nExample 3: list interpolation with string values\n------------------------------------------------\n\nIn this example we'll repeat a certain element inside the document, and\ninterpolate the contents of an array into each instance.\n\n::\n\n >>> xml = \"\"\"\\\n ... \n ... \n ... \n ... \n ... \"\"\"\n >>> context = {\n ... 'foodata': ['foo', 'bar'],\n ... }\n >>> t = templess.template(xml)\n >>> print t.unicode(context)\n \n foobar\n \n\nWhen the Templess engine notices the value is a list type, it will iterate\nthrough it, creating a clone of the node for each iteration. From there on the\ninterpolation works exactly the same as normal, but then on the clone instead\nof on the original node. When it's done iterating the list, the original will\nbe removed.\n\nNote: the interpolation of nodes (templess.node subclasses) works exactly the \nsame, also it's possible to use templess:replace the same way as before.\n\nNote: when the values of the list are not of a string type, interpolation will\nnot behave the same on the node, see the next example.\n\nExample 4: list interpolation with dict values\n----------------------------------------------\n\nIn this example we'll use dict values for the list, effectively recursing into\nthe interpolation process. The context for the recursion is the current\ncontext value (the current dict), and the root for the recursion is the\ncurrent element.\n\n::\n\n >>> xml = \"\"\"\\\n ... \n ... \n ... \n ... \n ... \"\"\"\n >>> context = {\n ... 'foodata': [\n ... {'bardata': 'baz'},\n ... {'bardata': 'qux'},\n ... ],\n ... }\n >>> t = templess.template(xml)\n >>> print t.unicode(context)\n \n bazqux\n \n\nOf course this also works the same with templess.node instances instead of\nstrings, and recurses infinitely, so you could use lists as the values, too.\nAlso behaves as you'd expect when the directive is t:replace.\n\nExample 5: conditional rendering\n--------------------------------\n\nVery simple example for conditional rendering, because it's a very simple\ndirective. The end result would be something like ````.\n\n::\n\n >>> xml = \"\"\"\\\n ... \n ... \n ... \n ... \n ... \"\"\"\n >>> context = {\n ... 'foodata': False,\n ... 'bardata': True,\n ... }\n >>> t = templess.template(xml)\n >>> print t.unicode(context)\n \n \n \n\nWhen the t:cond resolves to True, the element is left in tact, when it\nresolves to False, it's removed entirely from the document. There is a counter\ndirective called 'not', which has exactly the opposite effect from 'cond', so\ninstead of adding the node on a True value, it removes it.\n\nExample 6: setting attributes\n-----------------------------\n\nSetting attributes is also not too hard. The 'attr' directive generates\nattributes for each contained item, using the value in the context as value for\nthe attribute. If the context value resolves to False, the attribute is\nskipped (unless the value is '', then it will result in an empty attribute).\n\n::\n\n >>> xml = \"\"\"\\\n ... \n ... \n ... \n ... \n ... \"\"\"\n >>> context = {\n ... 'bardata': 'quux',\n ... 'bazdata': 'quuux',\n ... 'quxdata': False,\n ... }\n >>> t = templess.template(xml)\n >>> print t.unicode(context)\n \n \n ",
"description_content_type": null,
"docs_url": null,
"download_url": "UNKNOWN",
"downloads": {
"last_day": -1,
"last_month": -1,
"last_week": -1
},
"home_page": "http://templess.johnnydebris.net/",
"keywords": "templess",
"license": "UNKNOWN",
"maintainer": null,
"maintainer_email": null,
"name": "templess",
"package_url": "https://pypi.org/project/templess/",
"platform": "UNKNOWN",
"project_url": "https://pypi.org/project/templess/",
"project_urls": {
"Download": "UNKNOWN",
"Homepage": "http://templess.johnnydebris.net/"
},
"release_url": "https://pypi.org/project/templess/0.3/",
"requires_dist": null,
"requires_python": null,
"summary": "Templess templating system",
"version": "0.3"
},
"last_serial": 641021,
"releases": {
"0.3": [
{
"comment_text": "",
"digests": {
"md5": "10c31bac14790b91986ef7140ff77c5b",
"sha256": "e4a991b77b4b4486274bbbabae3cc8b2bb3270889c8593cab89a4eb65f03a183"
},
"downloads": -1,
"filename": "templess-0.3.tar.gz",
"has_sig": false,
"md5_digest": "10c31bac14790b91986ef7140ff77c5b",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 61070,
"upload_time": "2007-12-14T22:17:28",
"url": "https://files.pythonhosted.org/packages/02/70/146bd00e36c3aff07e0c6c844c9fc4bc7d5f658d13c03bacff16df6c532e/templess-0.3.tar.gz"
}
]
},
"urls": [
{
"comment_text": "",
"digests": {
"md5": "10c31bac14790b91986ef7140ff77c5b",
"sha256": "e4a991b77b4b4486274bbbabae3cc8b2bb3270889c8593cab89a4eb65f03a183"
},
"downloads": -1,
"filename": "templess-0.3.tar.gz",
"has_sig": false,
"md5_digest": "10c31bac14790b91986ef7140ff77c5b",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 61070,
"upload_time": "2007-12-14T22:17:28",
"url": "https://files.pythonhosted.org/packages/02/70/146bd00e36c3aff07e0c6c844c9fc4bc7d5f658d13c03bacff16df6c532e/templess-0.3.tar.gz"
}
]
}