Kid 0.9.3 Release Notes
- Re-applied a patch from ticket [66] that fix a bug where comments caused errors when in base templates.
- Changed all of the lesscode.org links into kid-templating.org
- Added and updated a few tests
- Removed the NamespaceStack.set method and made NamespaceStack.pop return the deleted value.
- Set balanced blocks to be off by default.
- Updated the parser to better handle interpolation of non-string types in comments. Reported in #182
Kid 0.9.2 Release Notes
Enhancements
- Updated to current version of ez_setup.py.
- Improved importer.py, resolving tickets #103 (FutureWarnings) and #137 (using new import hooks).
- The testing code can now figure out what testing modules to run dynamically. In addition, the code also determines which functions are tests dynamically. Tests that need pylib are skipped for those that don't have it. If you run 'python test_kid.py' now you should be seeing more tests executed.
- Removed the revision history from the language and and instead include a pointer to the Release Notes.
API Changes
- Allow the kid command to accept XML piped into it's stdin when '-' is used as the filename.
- Patch from #143. The load_template() function accepts an 'ns'keyword argument to pre-populate the template module namespace with global variables. Thanks!
- Created an API to replace the various ways that configuration options are currently set.
- Allow the XML function to take a new keword parameter (xmlns) that sets the default namespace for a fragment.
Add Support For Python 2.5
- Added support for xml.etree, which is the ElementTree packaged with Python 2.5. Running 'make test' only checks xml.etree currently.
- The __future__ imports have been moved to the top of the module to play nicely in Python 2.5. I have also added 2.5 to the makefile so it will be tested before each release.
- makefile regression test includes Python 2.5.
Kid 0.9.1 Release Notes
Bug Fixes
Layout Templates
The parameters passed to a template with a py:layout were not visible in named template functions or match templates.
A small bug existed in Python 2.3 where the dict.update() method was being called incorrectly. Python 2.4 allows a list of tuples to be passed to update(), whereas Python 2.3 does not.
py:match
The logic to apply the template matches has been reworked. This was due to the discovery of some odd behavior when using multiple template inheritence.
Enhancements
Layout Templates
A template type or name can now be dynamically passed into a template to be used as the layout template.
Kid 0.9 Release Notes
Language and API Changes
Layout Templates
There is a new feature in Kid for a template to specify a layout template to which match templates, named template definitions, and template parameters will be applied. This is useful for applying a generic set of headers, menus, footers, etc. to a many pages without duplicating large amounts of code in each page. More information and examples can be found in the py:layout section of the Language Specification.
Convenience Functions
Kid Template instances now provide convenience funcitons defined(name) and value_of(name).
Invisible Comments
XML comments starting with a ! character will not appear in the serialized output of a template.
Enhancements
Command line scripts now work on Windows
On Windows, the kid and kidc console commands can now be used as conveniently as on Unix, since the Kid installer creates kid.exe and kidc.exe launchers in the Python Scripts directory.
Kid 0.6 Release Notes
There has been significant change in version 0.6. This includes enhancements and modifications to the template language and python interface.
Language and API Changes
The following changes are likely to impact existing code and templates. Where possible, we have tried to maintain backward compatibility but that wasn't possible in all cases.
The Upgrade Script can be used to bring 0.5 templates up to 0.6 syntax.
Kid Namespace Change
The Kid namespace has changed from http://naeblis.cx/ns/kid# to http://purl.org/kid/ns#. The naeblis.cx domain is privately owned and could expire some time in the future. purl.org is a system for establishing and maintaining "persistent" URIs.
A temporary hack has been put in place to substitute references to the old namespace URI with the new namespace URI. A warning is output when this occurs. This will be removed in a couple of months so it is recommended that templates be upgraded as soon as possible.
py:omit is now py:strip
Due to initial confusion many experienced with the name py:omit, it has been renamed py:strip. The term "omit" was often read as "omit the element and all descendants". The new term "strip" seems to better indicate the semantic: "strip the start and end tag but process descendants."
Python Expression Substitution Syntax
The syntax of brace expansions has been modified match more closely with existing Python substitution syntax. In 0.5 python expressions enclosed in curly braces ({}) were evaluated and their results substituted. In 0.6, the rules have changed as follows:
- $$ is an escape; it is replaced with a single $.
- $name substitutes a variable value.
- ${expr} substitutes the result of evaluating any python expression.
See Python Expression Substitution in the Language Reference.
Enhancements
cElementTree Support
Kid now uses cElementTree if it is available. Preliminary tests show moderate performance increases. In most cases, we're seeing template parse and execution time increase by about 15%. The poor increase (relative to other cET/ET numbers) is due to the fact that we're not using cElementTree's native parser as it doesn't support comments or processing instructions. The plan is to lobby the effbot organization to add these features (hint, hint: send patches) so that we can get the huge increases people are seeing elsewhere.
Kid automatically determines whether cElementTree is available and uses it if so. If cElementTree is not available, Kid falls back on Python ElementTree. If you want to turn off use of cElementTree, you can set the environment variable KID_NOCET to 1.
Death of Comment Wart
In versions of Kid prior to 0.6, the first line of an embedded Python code block had to be a Python comment (#). This was due to Python's whitespace semantics. Christoph determined a process for establishing the correct indent levels without requiring a comment as the first line.
Starting in Kid 0.6, a comment is no longer required to be the first line in a <?python?> processing instruction. It is also possible to have single line code blocks:
<?python x = 10 ?>
Improved Template API
The Python interfaces have been reworked significantly and now are very similar to Cheetah's. There are two preferred methods for accessing a template.
The Template Class
The first method existed in 0.5 but was not documented well. If you have enabled the kid import hooks, then you can import a template and create an instance of the template by accessing the Template class exposed by the module:
import kid ; kid.enable_import() import mytemplate template = mytemplate.Template(foo='bar', bling=1) print template.serialize()
The primary difference from 0.5 is that template variables are passed to the Template constructor instead of to the individual execution methods (serialize, generate, write, pull).
It is also possible to set template variables after the template instance is created by simply assigning to template object instance:
template = mytemplate.Template() template.foo = 'bar' template.bling = 1 print str(template)
Here we see another small addition: template instances implement __str__ and __unicode__ built-ins. These methods are equivalent to calling serialize(encoding='utf-8') and serialize(encoding='utf-16'), respectively.
The kid.Template function
The kid.Template function works much like Template class constructors but takes an additional parameter that allows the template to be loaded from a file, string, or module name. It is sometimes easier to manage templates as files on disk rather than as python modules.
Example:
from kid import Template # create a template from file template = Template(file='mytemplate.kid', foo='bar', bling=1) # create a template from string template = Template(source="<p>${foo}</p>", foo='bar') # create a template from a python module name template = Template(name='templates.mytemplate', foo='bar')
This last form is sometimes useful because it doesn't require the kid import hook to be enabled and it also allows template names to be specified at run-time.
See kid.Template function in the User's Guide for more info.
Match Templates / Filters
Match Templates are a cross between XSLT's match templates and JSP tag libraries. They allow a set of filters to be put in place that matches infoset items generated by a template so that output can be modified.
While match templates provide a general purpose mechanism for transforming XML content, it is especially useful in a couple of situations which have driven the design:
- Creating tag libraries that inject new tags into an XML vocabulary.
- Applying headers/footers without inserting place-holders into the source document/template.
See Match Templates in the Language Reference for more information.
Template Inheritance
Templates now support multiple inheritance of template functions (py:def) and match templates (py:match). A template indicates that it extends one or more other templates by setting the py:extends attribute on the root element:
<?xml version='1.0' encoding='utf-8'?> <html py:extends="'common.kid', 'forms.kid'" ...
py:extends may contain template modules, Template classes, or strings specifying template paths relative to current template file.
See Template Reuse in the Language Reference for more information.
Dynamic Attribute Generation (py:attrs)
A new py:attrs attribute has been added that allows attributes to be specified using a dictionary.
See Dynamic Attributes in the Language Reference for more information.
Upgrade Script
Due to the amount of changes in template syntax, a migration script is provided that can upgrade kid 0.5 templates to 0.6 syntax. This includes changing the namespace, py:strip, and new expression substitution syntax.
The script can be found in the source distribution as misc/upgrade-0.6.py. The script can take multiple file names and upgrades each in-place while preserving a backup. For instance:
$ python upgrade-0.6.py path/to/template.kid Upgraded: template.kid...
On posix systems, you can upgrade a bunch of kid templates under the current working directory with the following command:
$ find . -name '*.kid' | xargs python upgrade-0.6.py Upgraded: template1.kid... Upgraded: template2.kid... Upgraded: template3.kid... Upgraded: template4.kid...