Edgewall Software

Changes between Version 6 and Version 7 of GenshiFaq


Ignore:
Timestamp:
Jul 7, 2006, 9:26:24 PM (13 years ago)
Author:
cmlenz
Comment:

Minor fixes

Legend:

Unmodified
Added
Removed
Modified
  • GenshiFaq

    v6 v7  
    2222== Why XML-based? ==
    2323
    24 Most template engines for web applications are character-stream based: they know nothing about the format of the text that is being generated. They simply substitute variable expressions, and provide some kind of directives for looping, conditionals, etc. Thus they can be used to generate any kind of textual output, be it HTML, plain text emails, program code, or really anything else.
     24Most template engines for web applications are character-stream based: they know nothing about the format of the response body that is being generated. They simply substitute variable expressions, and provide some directives for looping, conditionals, etc. Thus they can be used to generate any kind of textual output, be it HTML, plain text emails, program code, or really anything else.
    2525
    26 However, 99% of the templates used by web applications generate some kind of XML/HTML-based markup. So we believe that web applications can benefit from a template engine that “knows what it's doing” when it comes to markup. You don't need to worry about generating output that is not well-formed, nor do you need to worry about accidentially not escaping some data, thereby greatly reducing the risk for introducing [http://de.wikipedia.org/wiki/Cross_Site_Scripting XSS] attack vectors. Furthermore, your templates look a lot more like the targetted output format: an HTML template looks like HTML, a template for an RSS feed looks like RSS. Directives in text-based template languages often result in rather messy templates, or produce excessive amounts of unnecessary white space.
     26However, 99% of the templates used by web applications generate some kind of XML/HTML-based markup. We believe that web applications can benefit from a template engine that “knows what it's doing” when it comes to markup. You don't need to worry about generating output that is not well-formed, nor do you need to worry about accidentially not escaping some data, thereby greatly reducing the risk for introducing [http://de.wikipedia.org/wiki/Cross_Site_Scripting XSS] attack vectors. Furthermore, your templates look a lot more like the targetted output format: an HTML template looks like HTML, a template for an RSS feed looks like RSS. Directives in text-based template languages often result in rather messy templates, or produce excessive amounts of unnecessary white space.
    2727
    28 In addition, text-based templates don't even work all that well for many text formats. Imagine you want to generate a plain text email or an [http://www.ietf.org/rfc/rfc2445.txt iCalendar] file. How do you deal with important concerns such as line-wrapping and white-space in your templates? You may be better off using a specialized formatter.
     28In addition, text-based templates don't even work all that well for many text formats. Imagine you want to generate a plain text email or an [http://www.ietf.org/rfc/rfc2445.txt iCalendar] file. How do you deal with important concerns such as line-wrapping and white-space in your templates? You may be better off using specialized formatters.
    2929
    3030== So then why not just use Kid? ==
     
    3232We think that Kid represents a huge step forward for XML-based templating in Python. [http://kid.lesscode.org/language.html#match-templates-py-match Match templates] and the generator-based processing model are extremely powerful concepts.
    3333
    34 But arguably Kid also has some basic design problems. For exampe, Kid generates Python code from templates, which adds a lot of complexity to the code and can make the process of locating and fixing template errors a true nightmare. A syntax error in a template expression will cause an exception that points somewhere in the generated code. In addition, as Kid is based on [http://effbot.org/zone/element-index.htm ElementTree], and the !ElementTree API doesn't provide location information for parse events, exceptions reported by Kid often don't include information about what part of the template caused the error.
     34But arguably Kid also has some basic design problems. For example, Kid generates Python code from templates, which adds a lot of complexity to the code and can make the process of locating and fixing template errors a true nightmare. A syntax error in a template expression will cause an exception that points somewhere in the generated code. In addition, as Kid is based on [http://effbot.org/zone/element-index.htm ElementTree], and the !ElementTree API doesn't provide location information for parse events, exceptions reported by Kid often don't include information about what part of the template caused the error.
    3535
    3636We felt these problems would best be addressed by developing a new engine form scratch, as opposed to trying to “fix” Kid.
     
    4040Markup executes templates directly, there's no code generation phase. Expressions are evaluated in a more forgiving way by walking the AST. Template variables are stored on a stack, which means that some variable set in a loop deep in the template won't leak into the rest of the template. And even though Markup doesn't generate Python code for templates, it generally performs better than Kid (up to 2x in our tests).
    4141
    42 Markup does not depend on !ElementTree. It uses Expat for parsing XML, and is based on streaming slightly abstracted parse events through the processing pipeline. It uses XInclude (instead of Kids' `py:extends`) to allow template authors to factor out common bits. For match templates, it uses XPath expressions instead of the !ElementTree API.
     42Markup does not depend on !ElementTree. It uses Expat for parsing XML, and is based on streaming slightly abstracted parse events through the processing pipeline. It uses XInclude – instead of Kids' `py:extends` – to allow template authors to factor out common bits. For match templates, it uses XPath expressions instead of the !ElementTree API.
    4343
    4444== What other stuff is in the toolkit? ==