예제 #1
0
파일: template.py 프로젝트: dgym/cystache
 def _render(self, context, output, rs):
     old_template = context_manager._set_current_template(self)
     old_context = context_manager._set_current_context(context)
     try:
         for block in self.section.blocks:
             block.render(context, output, rs)
     finally:
         context_manager._set_current_template(old_template)
         context_manager._set_current_context(old_context)
예제 #2
0
파일: blocks.py 프로젝트: howow/cystache
 def _render(self, context, output, rs):
     value = context.get(self.tag)
     use_return = False
     if callable(value):
         value = value(self.template.source[self.inner_start : self.inner_end])
         use_return = True
         if isinstance(value, basestring):
             template = self.template.__class__(value, self.template.loader)
             template.compile(self.otag, self.ctag)
             value = template.render(context)
     if value:
         if hasattr(value, "__iter__") and not isinstance(value, dict):
             for v in value:
                 inner_context = Context(v, context)
                 old_context = context_manager._set_current_context(inner_context)
                 try:
                     for block in self.blocks:
                         block.render(inner_context, output, rs)
                 finally:
                     context_manager._set_current_context(old_context)
         elif use_return:
             output.write(as_string(value))
         else:
             inner_context = Context(value, context)
             old_context = context_manager._set_current_context(inner_context)
             try:
                 for block in self.blocks:
                     block.render(inner_context, output, rs)
             finally:
                 context_manager._set_current_context(old_context)