The :meth:`jinja2.Environment.compile_expression` method returns an instance of this object. It encapsulates the expression-like access to the template with an expression it wraps.
| 1169 | |
| 1170 | |
| 1171 | class TemplateExpression(object): |
| 1172 | """The :meth:`jinja2.Environment.compile_expression` method returns an |
| 1173 | instance of this object. It encapsulates the expression-like access |
| 1174 | to the template with an expression it wraps. |
| 1175 | """ |
| 1176 | |
| 1177 | def __init__(self, template, undefined_to_none): |
| 1178 | self._template = template |
| 1179 | self._undefined_to_none = undefined_to_none |
| 1180 | |
| 1181 | def __call__(self, *args, **kwargs): |
| 1182 | context = self._template.new_context(dict(*args, **kwargs)) |
| 1183 | consume(self._template.root_render_func(context)) |
| 1184 | rv = context.vars['result'] |
| 1185 | if self._undefined_to_none and isinstance(rv, Undefined): |
| 1186 | rv = None |
| 1187 | return rv |
| 1188 | |
| 1189 | |
| 1190 | @implements_iterator |
no outgoing calls
no test coverage detected
searching dependent graphs…