YATL


NameYATL JSON
Version 20230507.1 PyPI version JSON
download
home_page
SummaryYet Another Teplate Language (it has been around since 2007)
upload_time2023-05-07 23:54:09
maintainer
docs_urlNone
author
requires_python>=3.7
license
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Yet Another Template Language

This is the web2py template language described [here](http://web2py.com/books/default/chapter/29/05/the-views) made available as stand alone package so it can be used anywhere.

Basically it is pure Python within "{{" ... "}}" delimiters and blocks are terminated with "pass" if termination is not obvious. There is no indentation constraints.

For example:

```
from yatl import render, SPAN

example = """
<div> 
{{ for k in range(num): }}
<span>{{=SPAN(k, _class='number')}} is {{if k % 2 == 0:}}even{{else:}}odd{{pass}}</span>
{{ pass }}
</div>
"""

print(render(example, context=dict(num=10, SPAN=SPAN), delimiters="{{ }}"))
```

In the example SPAN is an optional helper.
Output is escaped by default unless marked up with the XML helper as in {{=XML('1 < 2')}}.
Note that the helpers included here are similar but not identical to the web2py ones.
They are 99% compatible but the implementation is different.

Any Python expressions is allowed in templates, including function and class defintions:

```
example = """
{{ def link(x): }}<a href="{{=x}}">{{=x}}</a>{{ pass }}
<ul>
  {{ for k in range(num): }}
  <li>
     {{= link('http://example.com/%s' % k) }}
  </li>
  {{ pass }}
</ul>
"""

print(render(example, context=dict(num=10), delimiters="{{ }}"))
```

## Caching

If you implement a caching reader as the one below, you mak yatl even faster:

```
CACHE = {}
def reader(filename):
    if filename in CACHE:
        return CACHE[filename]
    with open(filename) as fp;
        CACHE[filename] = content = fp.read()
    return content
      
output = yatl.render(reader(filename), path=path, reader=reader)
```


            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "YATL",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": "",
    "keywords": "",
    "author": "",
    "author_email": "Massimo Di Pierro <massimo.dipierro@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/40/0a/c9842e9125446519a6bdd47a886d0623a9a0d2c9a4ce44786b708b33338a/YATL-20230507.1.tar.gz",
    "platform": null,
    "description": "# Yet Another Template Language\n\nThis is the web2py template language described [here](http://web2py.com/books/default/chapter/29/05/the-views) made available as stand alone package so it can be used anywhere.\n\nBasically it is pure Python within \"{{\" ... \"}}\" delimiters and blocks are terminated with \"pass\" if termination is not obvious. There is no indentation constraints.\n\nFor example:\n\n```\nfrom yatl import render, SPAN\n\nexample = \"\"\"\n<div> \n{{ for k in range(num): }}\n<span>{{=SPAN(k, _class='number')}} is {{if k % 2 == 0:}}even{{else:}}odd{{pass}}</span>\n{{ pass }}\n</div>\n\"\"\"\n\nprint(render(example, context=dict(num=10, SPAN=SPAN), delimiters=\"{{ }}\"))\n```\n\nIn the example SPAN is an optional helper.\nOutput is escaped by default unless marked up with the XML helper as in {{=XML('1 < 2')}}.\nNote that the helpers included here are similar but not identical to the web2py ones.\nThey are 99% compatible but the implementation is different.\n\nAny Python expressions is allowed in templates, including function and class defintions:\n\n```\nexample = \"\"\"\n{{ def link(x): }}<a href=\"{{=x}}\">{{=x}}</a>{{ pass }}\n<ul>\n  {{ for k in range(num): }}\n  <li>\n     {{= link('http://example.com/%s' % k) }}\n  </li>\n  {{ pass }}\n</ul>\n\"\"\"\n\nprint(render(example, context=dict(num=10), delimiters=\"{{ }}\"))\n```\n\n## Caching\n\nIf you implement a caching reader as the one below, you mak yatl even faster:\n\n```\nCACHE = {}\ndef reader(filename):\n    if filename in CACHE:\n        return CACHE[filename]\n    with open(filename) as fp;\n        CACHE[filename] = content = fp.read()\n    return content\n      \noutput = yatl.render(reader(filename), path=path, reader=reader)\n```\n\n",
    "bugtrack_url": null,
    "license": "",
    "summary": "Yet Another Teplate Language (it has been around since 2007)",
    "version": "20230507.1",
    "project_urls": {
        "Bug Tracker": "https://github.com/web2py/yatl/issues",
        "Documentation": "https://py4web.com/_documentation/static/en/chapter-09.html",
        "Homepage": "https://github.com/web2py/yatl"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "0ae18418160004c90d0dc8c2b33a498de98e6802e48e7b5c84a23a1c00368be0",
                "md5": "7ac9ac6e981d8c577e74f252af70a92c",
                "sha256": "4adae698531f82940ee0ed8cb50d555229473d05ea7899aeaf7122c7c265927f"
            },
            "downloads": -1,
            "filename": "YATL-20230507.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "7ac9ac6e981d8c577e74f252af70a92c",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7",
            "size": 19335,
            "upload_time": "2023-05-07T23:54:06",
            "upload_time_iso_8601": "2023-05-07T23:54:06.918590Z",
            "url": "https://files.pythonhosted.org/packages/0a/e1/8418160004c90d0dc8c2b33a498de98e6802e48e7b5c84a23a1c00368be0/YATL-20230507.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "400ac9842e9125446519a6bdd47a886d0623a9a0d2c9a4ce44786b708b33338a",
                "md5": "98fad8212a392abfd80f73b5caf3d818",
                "sha256": "d78864f95a51066ed94bddff7d9383c52e1b61eefc20b573a3ad769b4f210bef"
            },
            "downloads": -1,
            "filename": "YATL-20230507.1.tar.gz",
            "has_sig": false,
            "md5_digest": "98fad8212a392abfd80f73b5caf3d818",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 20957,
            "upload_time": "2023-05-07T23:54:09",
            "upload_time_iso_8601": "2023-05-07T23:54:09.298650Z",
            "url": "https://files.pythonhosted.org/packages/40/0a/c9842e9125446519a6bdd47a886d0623a9a0d2c9a4ce44786b708b33338a/YATL-20230507.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-05-07 23:54:09",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "web2py",
    "github_project": "yatl",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "tox": true,
    "lcname": "yatl"
}
        
Elapsed time: 0.09851s