Английская Википедия:Genshi (templating language)

Материал из Онлайн справочника
Перейти к навигацииПерейти к поиску

Шаблон:Infobox software Genshi is a template engine for XML-based vocabularies written in Python. Genshi is used to easily insert generated output into XML-based languages, usually HTML, and reuse elements between documents. Genshi's syntax is based on Kid, but its architecture is different. Genshi aims to implement some of its functionality while processing templates faster, by dynamically processing templates using a stream based API, instead of compiling templates to Python code.[1]

Genshi can be used with several Python web frameworks, such as CherryPy,[2][3] TurboGears,[4] Pylons[5] and web2py.[6] Genshi was the default templating language for TurboGears from versions 1.1[7] to 2.3.8.[8]

Genshi markup

Genshi makes use of namespaces to embed instructions into HTML. A typical instruction is given as an attribute, with a Python expression inside the quotes. For example, the following will render a paragraph that shows 4:

<html xmlns="http://www.w3.org/1999/xhtml" xmlns:py="http://genshi.edgewall.org/">
    <body>
        <p py:content="2 + 2">This will be replaced with 4</p>
    </body>
</html>

Because of the use of namespaces, Genshi can be used in WYSIWYG HTML editors.[9][10]

Differences between Kid and Genshi

  • Genshi directly interprets templates (unlike Kid, which generates Python code)[11]
  • Genshi uses XInclude for template reuse[11]
  • Genshi adds attributes Kid does not have, like py:choose[11]
  • Genshi templates are easier to debug, because it tracks template source file names and line numbers, and errors from Genshi's interpreter produce more comprehensible stack traces than from Kid's generated code.[11]

References

Шаблон:Reflist

External links