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
James Brundage committed Mar 24, 2024
1 parent ed63b9a commit 36a421d
Showing 1 changed file with 64 additions and 0 deletions.
64 changes: 64 additions & 0 deletions Types/PipeScript.Module.Website/UseLayout.ps1
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
}

0 comments on commit 36a421d

Please sign in to comment.