-
Notifications
You must be signed in to change notification settings - Fork 139
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Optionally overlay/insert via function
The insert overlay action has an optional 'via' kwarg, which receives the left node and produces the right node, similar to the replace overlay action.
- Loading branch information
1 parent
a787f84
commit cfc93af
Showing
5 changed files
with
171 additions
and
11 deletions.
There are no files selected for viewing
40 changes: 40 additions & 0 deletions
40
pkg/yamltemplate/filetests/ytt-library/overlay/insert-into-array-via.tpltest
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#@ load("@ytt:overlay", "overlay") | ||
|
||
--- | ||
#@ def test1_left(): | ||
- item: 1 | ||
- item: 2 | ||
- item: 3 | ||
#@ end | ||
|
||
--- | ||
#@ def test1_right(): | ||
#@overlay/match by=lambda i, l, r: "item" in l, expects=3 | ||
#@overlay/insert before=True, via=lambda l: {"from_item": l["item"], "before": True} | ||
- {} | ||
#@overlay/match by=lambda i, l, r: "item" in l, expects=3 | ||
#@overlay/insert after=True, via=lambda l: {"from_item": l["item"], "after": True} | ||
- {} | ||
#@ end | ||
|
||
--- | ||
test1: #@ overlay.apply(test1_left(), test1_right()) | ||
|
||
+++ | ||
|
||
test1: | ||
- from_item: 1 | ||
before: true | ||
- item: 1 | ||
- from_item: 1 | ||
after: true | ||
- from_item: 2 | ||
before: true | ||
- item: 2 | ||
- from_item: 2 | ||
after: true | ||
- from_item: 3 | ||
before: true | ||
- item: 3 | ||
- from_item: 3 | ||
after: true |
48 changes: 48 additions & 0 deletions
48
pkg/yamltemplate/filetests/ytt-library/overlay/insert-into-doc-via.tpltest
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#@ load("@ytt:template", "template") | ||
#@ load("@ytt:overlay", "overlay") | ||
|
||
#@ def test1_left(): | ||
--- | ||
item: 1 | ||
--- | ||
item: 2 | ||
--- | ||
item: 3 | ||
#@ end | ||
|
||
#@ def test1_right(): | ||
#@overlay/match by=lambda i, l, r: "item" in l, expects=3 | ||
#@overlay/insert before=True, via=lambda l: {"from_item": l["item"], "before": True} | ||
--- | ||
#@overlay/match by=lambda i, l, r: "item" in l, expects=3 | ||
#@overlay/insert after=True, via=lambda l: {"from_item": l["item"], "after": True} | ||
--- | ||
#@ end | ||
|
||
--- #@ template.replace(overlay.apply(test1_left(), test1_right())) | ||
|
||
+++ | ||
|
||
from_item: 1 | ||
before: true | ||
--- | ||
item: 1 | ||
--- | ||
from_item: 1 | ||
after: true | ||
--- | ||
from_item: 2 | ||
before: true | ||
--- | ||
item: 2 | ||
--- | ||
from_item: 2 | ||
after: true | ||
--- | ||
from_item: 3 | ||
before: true | ||
--- | ||
item: 3 | ||
--- | ||
from_item: 3 | ||
after: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters