Mercurial > genshi > mirror
comparison markup/plugin.py @ 21:b4d17897d053 trunk
* Include paths are now interpreted relative to the path of the including template. Closes #3.
* The filename is now included as first item in the `pos` tuple of stream events.
* Simplified the "basic" example so that it actually ''is'' basic.
* Added a more complex example using nested relative includes in [source:/trunk/examples/includes/ examples/includes].
author | cmlenz |
---|---|
date | Tue, 20 Jun 2006 13:05:37 +0000 |
parents | 49364e784c47 |
children | b4f78c05e5c9 |
comparison
equal
deleted
inserted
replaced
20:cc92d74ce9e5 | 21:b4d17897d053 |
---|---|
1 # -*- coding: utf-8 -*- | 1 # -*- coding: utf-8 -*- |
2 # | 2 # |
3 # Copyright (C) 2006 Mattew Good | 3 # Copyright (C) 2006 Matthew Good |
4 # All rights reserved. | 4 # All rights reserved. |
5 # | 5 # |
6 # This software is licensed as described in the file COPYING, which | 6 # This software is licensed as described in the file COPYING, which |
7 # you should have received as part of this distribution. The terms | 7 # you should have received as part of this distribution. The terms |
8 # are also available at http://trac.edgewall.com/license.html. | 8 # are also available at http://trac.edgewall.com/license.html. |
32 """Find a template specified in python 'dot' notation.""" | 32 """Find a template specified in python 'dot' notation.""" |
33 divider = templatename.rfind('.') | 33 divider = templatename.rfind('.') |
34 if divider >= 0: | 34 if divider >= 0: |
35 package = templatename[:divider] | 35 package = templatename[:divider] |
36 basename = templatename[divider + 1:] + '.html' | 36 basename = templatename[divider + 1:] + '.html' |
37 fullpath = resource_filename(package, basename) | 37 templatename = resource_filename(package, basename) |
38 dirname, templatename = os.path.split(fullpath) | |
39 self.loader.search_path.append(dirname) # Kludge | |
40 | 38 |
41 return self.loader.load(templatename) | 39 return self.loader.load(templatename) |
42 | 40 |
43 def render(self, info, format='html', fragment=False, template=None): | 41 def render(self, info, format='html', fragment=False, template=None): |
44 """Renders the template to a string using the provided info.""" | 42 """Render the template to a string using the provided info.""" |
45 return self.transform(info, template).render(method=format) | 43 return self.transform(info, template).render(method=format) |
46 | 44 |
47 def transform(self, info, template): | 45 def transform(self, info, template): |
48 "Render the output to Elements" | 46 """Render the output to an event stream.""" |
49 if not isinstance(template, Template): | 47 if not isinstance(template, Template): |
50 template = self.load_template(template) | 48 template = self.load_template(template) |
51 | 49 |
52 data = {} | 50 data = {} |
53 if self.get_extra_vars: | 51 if self.get_extra_vars: |