Render the node depending on its type
(node, render_context)
| 200 | |
| 201 | |
| 202 | def _render(node, render_context): |
| 203 | """ |
| 204 | Render the node depending on its type |
| 205 | """ |
| 206 | if "template" in node: |
| 207 | complex_type = False |
| 208 | |
| 209 | if isinstance(node["template"], list) or isinstance(node["template"], dict): |
| 210 | node["template"] = json_encode(node["template"]) |
| 211 | |
| 212 | # Finds occurrences of "{{variable}}" and adds `to_complex` filter |
| 213 | # so types are honored. If it doesn't follow that syntax then it's |
| 214 | # rendered as a string. |
| 215 | node["template"] = re.sub( |
| 216 | r'"{{([A-z0-9_-]+)}}"', r"{{\1 | to_complex}}", node["template"] |
| 217 | ) |
| 218 | LOG.debug("Rendering complex type: %s", node["template"]) |
| 219 | complex_type = True |
| 220 | |
| 221 | LOG.debug("Rendering node: %s with context: %s", node, render_context) |
| 222 | |
| 223 | result = ENV.from_string(str(node["template"])).render(render_context) |
| 224 | |
| 225 | LOG.debug("Render complete: %s", result) |
| 226 | |
| 227 | if complex_type: |
| 228 | result = json_decode(result) |
| 229 | LOG.debug("Complex Type Rendered: %s", result) |
| 230 | |
| 231 | return result |
| 232 | if "value" in node: |
| 233 | return node["value"] |
| 234 | |
| 235 | |
| 236 | def _resolve_dependencies(G): |
no test coverage detected