blob: 92c63bf58c556954ab7490ff97cb8f99bc53d0e2 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
The `sourcepath()` function determines the path of the currently executed
ucode script file, optionally only the directory portion.
By specifying the a depth parameter, the owning files of functions further
up the call stack can be determined.
Returns a string containing the path (or directory) of the running ucode
source file.
Returns `null` if the path is indeterminate.
-- Testcase --
{%
let output = render("files/include/level1.uc");
// replace dynamic testfiles path with placeholder for stable output
output = replace(output, TESTFILES_PATH, "...");
print(output);
%}
-- End --
-- File include/level1.uc --
This is the 1st level include.
{% include("level2.uc") %}
-- End --
-- File include/level2.uc --
This is the 2nd level include.
{% include("level3.uc") %}
-- End --
-- File include/level3.uc --
This is the 3rd level include.
{% for (let depth in [0, 1, 2, 3]): %}
Depth {{ depth }}:
Path: {{ sourcepath(depth, false) || "indeterminate" }}
Directory: {{ sourcepath(depth, true) || "indeterminate" }}
{% endfor %}
-- End --
-- Expect stdout --
This is the 1st level include.
This is the 2nd level include.
This is the 3rd level include.
Depth 0:
Path: .../include/level3.uc
Directory: .../include
Depth 1:
Path: .../include/level2.uc
Directory: .../include
Depth 2:
Path: .../include/level1.uc
Directory: .../include
Depth 3:
Path: indeterminate
Directory: indeterminate
-- End --
|