Skip to content

Commit

Permalink
feat: PipeScript.Module.WebSite.UseLayout ( Fixes #1084 )
Browse files Browse the repository at this point in the history
  • Loading branch information
StartAutomating authored and StartAutomating committed Mar 24, 2024
1 parent 36a421d commit 2256892
Showing 1 changed file with 69 additions and 0 deletions.
69 changes: 69 additions & 0 deletions PipeScript.types.ps1xml
Original file line number Diff line number Diff line change
Expand Up @@ -4495,6 +4495,75 @@ $this | . {

</Script>
</ScriptMethod>
<ScriptMethod>
<Name>UseLayout</Name>
<Script>
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
&amp; $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)
}
}
}

&amp; $layout @paramSplat
}
</Script>
</ScriptMethod>
</Members>
</Type>
<Type>
Expand Down

0 comments on commit 2256892

Please sign in to comment.