Skip to content

Commit c1127f2

Browse files
committed
POC deferrable epp function
This function will detect when it's passed a deferred function and will effectively defer itself rather than rendering a template directly. It does this by either returning a deferred inline_epp function with the template source and variables compiled into the catalot, or by rendering directly with epp and just returning that output.
1 parent b97c657 commit c1127f2

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

functions/deferrable_epp.pp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# This function returns either a rendered template or a deferred function to render at runtime.
2+
# If any of the values in the variables hash are deferred, then the template will be deferred.
3+
#
4+
# Note: this function requires all parameters to be explicitly passed in. It cannot expect to
5+
# use facts, class variables, and other variables in scope. This is because when deferred, we
6+
# have to explicitly pass the entire scope to the client.
7+
#
8+
function stdlib::deferrable_epp(String $template, Hash $variables) >> Variant[String, Deferred] {
9+
if $variables.any |$key, $value| { $value.is_a(Deferred) } {
10+
Deferred(
11+
'inline_epp',
12+
[find_template($template).file, $variables],
13+
)
14+
}
15+
else {
16+
epp($template, $variables)
17+
}
18+
}
19+

0 commit comments

Comments
 (0)