MCPcopy Create free account
hub / github.com/StackStorm/st2 / _render

Function _render

st2common/st2common/util/param.py:202–233  ·  view source on GitHub ↗

Render the node depending on its type

(node, render_context)

Source from the content-addressed store, hash-verified

200
201
202def _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
236def _resolve_dependencies(G):

Callers 1

_resolve_dependenciesFunction · 0.85

Calls 2

json_encodeFunction · 0.90
json_decodeFunction · 0.90

Tested by

no test coverage detected