Skip to content

Commit

Permalink
fix: HelpOut Extended Member Summary Titling ( Fixes #202 )
Browse files Browse the repository at this point in the history
  • Loading branch information
James Brundage committed Oct 13, 2024
1 parent 00ffbe5 commit 55dfbda
Showing 1 changed file with 32 additions and 8 deletions.
40 changes: 32 additions & 8 deletions Extensions/HelpOut.SaveMarkdownHelp.ExtendedTypes.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,12 @@ $punctuationNotDashOrUnderscore = '[\p{P}-[\-_]]'
# go over each extended type
foreach ($extendedType in $extendedTypeNames) {
# and get the actual type data
$actualTypeData = Get-TypeData -TypeName $extendedType
$actualTypeData = Get-TypeData -TypeName $extendedType

# We will want to keep track of methods and properties in order,
# so we don't have to sort or resolve them later.
$methodsByName = [Ordered]@{}
$propertiesByName = [Ordered]@{}

$memberFiles =
@(foreach ($member in $actualTypeData.Members.Values) {
Expand Down Expand Up @@ -81,9 +86,22 @@ foreach ($extendedType in $extendedTypeNames) {
).md"

# .Save it,
$markdownHelp.Save($etsDocPath)
# and remove the temporary function (it would have gone out of scope anyways)
$memberFile = $markdownHelp.Save($etsDocPath)
# and remove the temporary function (it would have gone out of scope anyways).
$ExecutionContext.SessionState.PSVariable.Remove("function:$($temporaryFunctionName)")

# Emit the member file
$memberFile

if ($getSetNothing) {
if (-not $propertiesByName[$member.Name]) {
$propertiesByName[$member.Name] = $memberFile
} else {
$propertiesByName[$member.Name] = @($propertiesByName[$member.Name]) + $memberFile
}
} else {
$methodsByName[$member.Name] = $memberFile
}
}


Expand Down Expand Up @@ -119,21 +137,27 @@ foreach ($extendedType in $extendedTypeNames) {
"### Script Properties"
[Environment]::NewLine
# and be sorted by property name.
foreach ($memberFile in $propertyMemberFiles | Sort-Object { $_.Name -replace $getSetFile}) {
"* [$(@($memberFile.Name -split '[\p{P}-[_]]')[-2])]($($memberFile.Name))"
foreach ($memberKeyValue in $propertiesByName.GetEnumerator()) {
# If there are multiple files for a property, it's got a get and a set.
if ($memberKeyValue.Value -is [array]) {
"* [get_$($memberKeyValue.Key)]($($memberKeyValue.Value[0].Name))"
"* [set_$($memberKeyValue.Key)]($($memberKeyValue.Value[1].Name))"
} else {
"* [get_$($memberKeyValue.Key)]($($memberKeyValue.Value.Name))"
}
}
[Environment]::NewLine
}
# Methods should come after properties.
if ($methodMemberFiles) {
"### Script Methods"
[Environment]::NewLine
# and will be sorted alphabetically.
foreach ($memberFile in $methodMemberFiles) {
"* [$(@($memberFile.Name -split '[\p{P}-[_]]')[-2])]($($memberFile.Name))"
foreach ($memberKeyValue in $methodsByName.GetEnumerator()) {
"* [$($memberKeyValue.Key)()]($($memberKeyValue.Value.Name))"
}
}
}

) -join ([Environment]::NewLine)

$ExtendedTypeDocContent | Set-Content -Path $ExtendedTypeDocFile
Expand Down

0 comments on commit 55dfbda

Please sign in to comment.