-
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: PipeScript.Module.WebSite.UseLayout ( Fixes #1084 )
- Loading branch information
James Brundage
committed
Mar 24, 2024
1 parent
ed63b9a
commit 36a421d
Showing
1 changed file
with
64 additions
and
0 deletions.
There are no files selected for viewing
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,64 @@ | ||
param( | ||
[PSObject] | ||
$Layout, | ||
|
||
[PSObject] | ||
$Parameter | ||
) | ||
|
||
if (-not $layout -or $layout -eq 'Default') { | ||
$Layout = $PSLanguage.HTML.Templates.'HTML.Default.Layout' | ||
} | ||
|
||
if ($layout -is [string]) { | ||
$Layout = $ExecutionContext.SessionState.InvokeCommand.GetCommand($layout, 'All') | ||
} | ||
|
||
|
||
|
||
|
||
if ($layout -is [Management.Automation.ApplicationInfo]) { | ||
$layoutArguments = @() + $Parameter | ||
& $layout @layoutArguments | ||
} else { | ||
$paramSplat = [Ordered]@{} | ||
if ($parameter -isnot [Collections.IDictionary]) { | ||
if ($parameter -is [object[]]) { | ||
foreach ($paramSet in $parameter) { | ||
if ($paramSet -isnot [Collections.IDictionary]) { | ||
foreach ($paramProp in $paramSet.psobject.properties) { | ||
$paramSplat[$paramProp.Name] = $paramProp.Value | ||
} | ||
$paramSet = $paramSplat | ||
} else { | ||
foreach ($kvp in $paramSet.GetEnumerator()) { | ||
$paramSplat[$kvp.Key] = $kvp.Value | ||
} | ||
} | ||
} | ||
} else { | ||
|
||
foreach ($paramProp in $parameter.psobject.properties) { | ||
$paramSplat[$paramProp.Name] = $paramProp.Value | ||
} | ||
} | ||
} else { | ||
$paramSplat += $Parameter | ||
} | ||
|
||
if ($layout.Parameters) { | ||
:nextParameter foreach ($paramName in @($paramSplat.Keys)) { | ||
if (-not $layout.Parameters[$paramName]) { | ||
foreach ($layoutParameter in $layoutParameters.Values) { | ||
if ($layoutParameter.Aliases -contains $paramName) { | ||
continue nextParameter | ||
} | ||
} | ||
Write-Verbose "Removing parameter $paramName from splat, since it is not a parameter of $layout." | ||
$paramSplat.Remove($paramName) | ||
} | ||
} | ||
} | ||
|
||
& $layout @paramSplat | ||
} |