Skip to content

Commit

Permalink
feat: Template.HTML.Command.Input ( Fixes #1076 )
Browse files Browse the repository at this point in the history
Inner docs and fixing parameter set name
  • Loading branch information
James Brundage committed Mar 28, 2024
1 parent df86874 commit 055bc5d
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions Languages/HTML/Templates/Input/HTML-Template-Command-Input.ps.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Template function HTML.Command.Input {
[CmdletBinding(DefaultParameterSetName='None')]
param(
# The Command Metadata. This can be provided via the pipeline from Get-Command.
[vfp(Mandatory,ParameterSetName='ParameterMetadata')]
[vfp(Mandatory,ParameterSetName='CommandMetadata')]
[Management.Automation.CommandMetadata]
$CommandMetadata,

Expand Down Expand Up @@ -95,7 +95,7 @@ Template function HTML.Command.Input {
$ElementMap = [Ordered]@{
'Name' = 'h2'
'Synopsis' = 'p'
'Description' = 'p'
'Description' = 'p'
'Example' = 'code'
'Link' = 'p'
'Notes' = 'p'
Expand Down Expand Up @@ -168,6 +168,7 @@ Template function HTML.Command.Input {
}


# Then copy the parameters
$myParameterCopy = [Ordered]@{} + $PSBoundParameters
$elementOrder =
@(if ($elementMap -is [Collections.IDictionary]) {
Expand All @@ -177,8 +178,10 @@ Template function HTML.Command.Input {
})



$ItemsInContainer = @(
# Many parameters will be turned directly into elements,
# using the -ElementMap and -ElementAttributeMap
foreach ($potentialElement in $elementOrder) {
if ($myParameterCopy.($potentialElement)) {
$ElementSplat = [Ordered]@{
Expand All @@ -192,25 +195,30 @@ Template function HTML.Command.Input {
}
}

if ($parameter -is [Collections.IDictionary]) {
# Any parameters should be turned into input elements.
if ($parameter -is [Collections.IDictionary]) {
$parameter.Values | Template.HTML.Parameter.Input
} elseif ($Parameter) {
$Parameter | Template.HTML.Parameter.Input
})
}
)

# Now we want to put all of the items into a container.
$ContainerContent =
@(foreach ($itemInContainer in $ItemsInContainer) {
# If we have an item element, wrap it in that element.
if ($ItemElement) {
Template.HTML.Element -Name $ItemElement -Content $itemInContainer -Attribute $ItemAttribute
} else {
$itemInContainer
}
}) -join $ItemSeparator
}) -join $ItemSeparator # If we have an item separator, join the items with it.

# If we have a container element, wrap the all the items in that element.
if ($ContainerElement) {
Template.HTML.Element -Name $ContainerElement -Content $ContainerContent -Attribute $ContainerAttribute
} else {
$ContainerContent
$ContainerContent # Otherwise, return the items directly.
}
}
}

0 comments on commit 055bc5d

Please sign in to comment.