Skip to content

Commit 4cb135a

Browse files
xoofxCopilot
andcommitted
Fix pipe argument docs
Co-authored-by: Copilot <[email protected]>
1 parent d56dc4e commit 4cb135a

File tree

3 files changed

+39
-38
lines changed

3 files changed

+39
-38
lines changed

issue-followup-plan.md

Lines changed: 9 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22

33
This cleanup pass closed 55 old issues that were stale, already answered, resolved in current Scriban, or outside the scope of core Scriban.
44

5-
Issues `#625`, `#453`, and `#529` are fixed locally by the changes in this pass.
5+
Issues `#625`, `#453`, `#529`, and `#209` are fixed locally by the changes in this pass.
66

7-
The 8 issues below remain open because they were either reproduced on current head, still point to incorrect documentation, or need an explicit design decision before any code change is worth doing.
7+
Issue `#553` is being closed without a code change because `{{~ ... }}` shows the same indentation-trimming behavior at top level, so this does not appear to be a caller-indent regression specific to function rendering.
8+
9+
The 6 issues below remain open because they need an explicit design decision before any code change is worth doing, or are low-priority cleanup items better closed later.
810

911
Default stance for the next pass:
1012

@@ -14,35 +16,8 @@ Default stance for the next pass:
1416

1517
## 1. Concrete docs and bug fixes
1618

17-
### #553 Whitespace control inside of functions affects auto-indent of caller
18-
19-
Status: reproduced.
20-
21-
Evidence:
22-
23-
- `{{~ ... }}` inside a called function still perturbs the caller's auto-indent/output layout.
24-
25-
Suggested action:
26-
27-
- Isolate callee whitespace trimming from caller indentation state.
28-
- Add regression tests for function calls with and without `{{~ ... }}` inside the callee body.
29-
3019
## 2. Docs cleanup that should be narrowed
3120

32-
### #209 Is the documentation out of date?
33-
34-
Status: still broadly true, but too broad.
35-
36-
Evidence:
37-
38-
- `site/docs/runtime/scriptobject.md` still says pipe calls pass the previous value as the last argument, which is outdated or at least misleading.
39-
- #625 is another concrete example of doc drift.
40-
41-
Suggested action:
42-
43-
- Either narrow this issue to a short checklist of specific doc fixes or close it after fixing the concrete doc items already identified.
44-
- Do not leave this as a permanent catch-all docs issue.
45-
4621
## 3. Feature and design decisions before implementation
4722

4823
### #188 array.sort only works with simple members (can't use nested members)
@@ -130,10 +105,8 @@ Suggested action:
130105

131106
## Suggested review order
132107

133-
1. #553
134-
2. #209
135-
3. #188 and #405 together
136-
4. #368
137-
5. #513
138-
6. #284
139-
7. #446
108+
1. #188 and #405 together
109+
2. #368
110+
3. #513
111+
4. #284
112+
5. #446

site/docs/runtime/scriptobject.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,8 @@ This function can be imported into a ScriptObject:
107107
Console.WriteLine(result);
108108
```
109109

110-
> Notice that when using a function with pipe calls like `{{ "{{" }}description | string.strip {{ "}}" }}`, the last argument passed to the `string.strip` function is the result of the previous pipe.
111-
> That's a reason why you will notice in all builtin functions in scriban that they usually take the most relevant parameter as a last parameter instead of the first parameter, to allow proper support for pipe calls.
110+
> Notice that when using a function with pipe calls like `{{ "{{" }}description | string.strip {{ "}}" }}`, the result of the previous pipe becomes the first explicit argument passed to `string.strip`.
111+
> For example, `{{ "{{" }} date | format "dd.MM" {{ "}}" }}` calls `format(date, "dd.MM")` (or `format(context, date, "dd.MM")` for methods that declare a leading `TemplateContext`).
112112
113113
> **NOTICE**
114114
>

src/Scriban.Tests/TestRuntime.cs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -609,6 +609,14 @@ public static string T(TemplateContext context, object input, params object[] va
609609
}
610610
}
611611

612+
public static class ImportedPipeOrderFunctions
613+
{
614+
public static string Format(DateTime input, string formatString)
615+
{
616+
return input.ToString(formatString, CultureInfo.InvariantCulture);
617+
}
618+
}
619+
612620
[Test]
613621
public void TestFunctionArrayEachAndFunctionCall()
614622
{
@@ -760,6 +768,26 @@ public void TestFunctionWithTemplateContextAndObjectParams()
760768
}
761769
}
762770

771+
[Test]
772+
public void TestImportedFunctionPipeValueUsesFirstArgument()
773+
{
774+
var template = Template.Parse(@"{{ date | format ""dd.MM"" }}");
775+
Assert.False(template.HasErrors);
776+
777+
var context = new TemplateContext();
778+
var scriptObject = new ScriptObject();
779+
scriptObject.Import(typeof(ImportedPipeOrderFunctions));
780+
context.PushGlobal(scriptObject);
781+
context.PushGlobal(new ScriptObject
782+
{
783+
["date"] = new DateTime(2024, 2, 3),
784+
});
785+
786+
var result = template.Render(context);
787+
788+
Assert.AreEqual("03.02", result);
789+
}
790+
763791
[Test]
764792
public void TestInvalidConvertToInt()
765793
{

0 commit comments

Comments
 (0)