예제 #1
0
 def resolve_template(self, template):
     """Accepts a template object, path-to-template or list of paths"""
     if isinstance(template, (list, tuple)):
         return genshi_loader.select_template(template)
     elif isinstance(template, basestring):
         return genshi_loader.get_template(template)
     else:
         return template
예제 #2
0
def render_to_stream (template_name, dictionary = None,
                      context_instance = None,
                      use_text_template = False):
	"""Render a template and data into a Genshi markup stream."""
	if dictionary is None:
		dictionary = {}

	if use_text_template:
		cls = NewTextTemplate
	else:
		cls = MarkupTemplate
	if isinstance (template_name, (list, tuple)):
		template = select_template (template_name, cls = cls)
	else:
		template = get_template (template_name, cls = cls)
		
	if context_instance:
		context_instance.update (dictionary)
	else:
		context_instance = Context (dictionary)
		
	return template.generate (context_instance)