@@ -121,13 +121,12 @@ function ConvertSVGMetadataToParameterAttribute {
121121 elseif ($hadColor ) {
122122 " [ValidateScript({`$ _ -in '$validSet ' -or `$ _ -match '\#[0-9a-f]{3}' -or `$ _ -match '\#[0-9a-f]{6}' -or `$ _ -notmatch '\W'})]"
123123 }
124- elseif ($validSet -and -not $hadUnknown ) {
124+ elseif ($validSet -and -not $hadUnknown -and -not ( $validSet -match ' \p{P} ' ) ) {
125125 $tabCompletionRedundant = $true
126126 " [ValidateSet('$validSet ')]"
127127 }
128128
129- if ($setDescriptors -and -not $tabCompletionRedundant ) {
130- $null = $null
129+ if ($setDescriptors -and -not $tabCompletionRedundant ) {
131130' [ArgumentCompleter({
132131 param ( $commandName,$parameterName,$wordToComplete,$commandAst,$fakeBoundParameters )
133132' + "
@@ -240,8 +239,15 @@ function ImportSvgAttribute {
240239 foreach ($attrInGroup in $groupedAttributes.Group ) {
241240 if ($attrMetadata [$attrInGroup ]) {
242241 if (-not $allAttributeData [$attrInGroup ]) {
243- $allAttributeData += @ {
244- $attrInGroup = $attrMetadata [$attrInGroup ].Properties
242+ $allAttributeData += @ {
243+ $attrInGroup =
244+ if ($attrMetadata [$attrInGroup ].properties -isnot [Object []]) {
245+ $attrMetadata [$attrInGroup ].Properties
246+ } else {
247+ foreach ($ht in $attrMetadata [$attrInGroup ].properties) {
248+ if ($ht.AppliesTo -contains $elementOrSetName ) { $ht ;break }
249+ }
250+ }
245251 }
246252 }
247253 if (-not $allAttributeHelp [$attrInGroup ]) {
@@ -306,7 +312,14 @@ function ImportSvgElementAttribute {
306312 }
307313 }
308314 if ($attrMetadata [$attributeName ]) {
309- $attributeData [$attributeName ] = $attrMetadata [$attributeName ].Properties
315+ $attributeData [$attributeName ] =
316+ if ($attrMetadata [$attributeName ].properties -isnot [Object []]) {
317+ $attrMetadata [$attributeName ].Properties
318+ } else {
319+ foreach ($ht in $attrMetadata [$attributeName ].properties) {
320+ if ($ht.AppliesTo -contains $elementOrSetName ) { $ht ;break }
321+ }
322+ }
310323 }
311324 }
312325 elseif ($attributeName -and $elementAttributeLine -match $attributeHelpLine ) {
@@ -368,9 +381,6 @@ function InitializeSvgAttributeData {
368381 }
369382 }
370383 }
371- $null = $null
372-
373-
374384
375385 $attrsFound = [Ordered ]@ {}
376386 foreach ($match in $findSvgAttr.Matches ($savedMarkdown [$attributeListUri ])) {
@@ -398,18 +408,32 @@ function InitializeSvgAttributeData {
398408 Write-Warning " $SVGAttributeUri : $_ "
399409 }).Content
400410 ))
401- } elseif ($markdownNotFound [$attrUri ]) {
402- $null = $null
403411 }
404412
405413 if (-not $savedMarkdown [$attrUri ]) {
406414 continue
407415 }
408416
409417 $attributeTables = @ ($savedMarkdown [$attrUri ] | ? < HTML_StartOrEndTag> - Tag table)
410- $attributeProperties = [ Ordered ] @ {}
418+ $allAttributeProperties = @ ()
411419 for ($ati = 0 ; $ati -lt $attributeTables.Count ; $ati ++ ) {
420+ $appliesToElements = @ ()
421+ if ($attributeTables.Count -gt 2 ) {
422+ $previousHeading = $savedMarkdown [$attrUri ] | ? < Markdown_Heading> - RightToLeft - Count 1 - StartAt $attributeTables [$ati ].Index
423+ $previousHeadingEnd = $previousHeading.Index + $previousHeading.Length
424+ $appliesToElements = @ ($findSvgElement.Matches (
425+ $previousHeading.Value
426+ ))
427+ if ($appliesToElements ) {
428+ $appliesToElements = @ (foreach ($appliesTo in $appliesToElements ) {
429+ $appliesTo.Groups [' e' ].Value
430+ })
431+ }
432+ }
433+
434+ $attributeProperties = [Ordered ]@ {}
412435 if ($attributeTables [$ati ] -match ' properties' ) {
436+
413437 $attrTable =
414438 $savedMarkdown [$attrUri ].Substring(
415439 $attributeTables [$ati ].Index, $attributeTables [$ati + 1 ].Index + $attributeTables [$ati + 1 ].Length - $attributeTables [$ati ].Index
@@ -441,7 +465,10 @@ function InitializeSvgAttributeData {
441465 if ($attributeProperties [' Default value' ] -eq ' None' ) {
442466 $attributeProperties.Remove (' Default Value' )
443467 }
444- break
468+ if ($appliesToElements ) {
469+ $attributeProperties [' AppliesTo' ] = $appliesToElements
470+ }
471+ $allAttributeProperties += $attributeProperties
445472 }
446473
447474 }
@@ -463,7 +490,13 @@ function InitializeSvgAttributeData {
463490 }
464491 }
465492 )
466- Properties = $attributeProperties
493+ Properties = $ (
494+ if ($allAttributeProperties.Count -eq 1 ) {
495+ $allAttributeProperties [0 ]
496+ } else {
497+ $allAttributeProperties
498+ }
499+ )
467500 }
468501 }
469502}
@@ -502,6 +535,20 @@ foreach ($svgElement in $svgElements.elements.psobject.properties) {
502535
503536$examplesRoot = Join-Path $PSScriptRoot Examples
504537
538+ $knownParameterAliases = @ {
539+ ' Dur' = ' Duration'
540+ }
541+
542+ $destFolder = Join-Path $PSScriptRoot " Commands"
543+ $destFolder = Join-Path $destFolder " Standard"
544+
545+ if (-not (Test-Path $destFolder )) {
546+ $createdFolder = New-Item $destFolder - Type Directory - Force
547+ if (-not $createdFolder ) {
548+ Write-Error " Could not create $destFolder "
549+ return
550+ }
551+ }
505552
506553foreach ($elementKV in $svgElementData.GetEnumerator ()) {
507554 $docsLink = " https://pssvg.start-automating.com/SVG.$ ( $elementKV.Key ) "
@@ -549,11 +596,19 @@ foreach ($elementKV in $svgElementData.GetEnumerator()) {
549596 }
550597
551598 $parameters [' Data' ] = @ (
552- " # A dictionary containing data. This data will be embedded in data- attributes."
553- " [Collections.IDictionary]"
599+ " # A dictionary containing data. This data will be embedded in data- attributes."
554600 " [Parameter(ValueFromPipelineByPropertyName)]"
601+ " [Collections.IDictionary]"
555602 ' $Data'
556603 )
604+
605+ $parameters [' Attribute' ] = @ (
606+ " # A dictionary of attributes. This can set any attribute not exposed in other parameters."
607+ " [Parameter(ValueFromPipelineByPropertyName)]"
608+ " [Alias('Attributes')]"
609+ " [Collections.IDictionary]"
610+ ' $Attribute = [Ordered]@{}'
611+ )
557612
558613 foreach ($attrName in $elementKV.Value.AttributeNames ) {
559614 $paramName = [regex ]::Replace($attrName , ' \W(?<w>\w+)' , {
@@ -595,12 +650,18 @@ foreach ($elementKV in $svgElementData.GetEnumerator()) {
595650
596651 if ($elementData ) {
597652 foreach ($dataKv in $elementData.GetEnumerator ()) {
653+ if ($dataKv.Key -eq ' AppliesTo' ) { continue }
598654 " [Reflection.AssemblyMetaData('SVG.$ ( $dataKv.Key ) ', '$ ( $dataKv.Value.ToString ().Replace(" '" , " ''" )) ')]"
599655 if ($dataKv.Key -eq ' Value' -and $dataKv.Value ) {
600656 $dataKv.Value | ConvertSVGMetadataToParameterAttribute
601657 }
602658 }
603- }
659+ }
660+
661+ if ($knownParameterAliases [$paramName ]) {
662+ " [Alias('$ ( $knownParameterAliases [$paramName ] -replace " '" , " ''" -join " ','" ) ')]"
663+ }
664+
604665 " `$ $paramName "
605666 )
606667 }
@@ -637,9 +698,17 @@ $OutputPath
637698 }
638699 if (-not $elementName ) { return }
639700
701+ if (-not $attribute [$paramCopy.Keys ]) {
702+ $attribute += $paramCopy
703+ } else {
704+ foreach ($pc in $paramCopy.GetEnumerator ()) {
705+ $attribute [$pc.Key ] = $pc.Value
706+ }
707+ }
708+
640709 $writeSvgSplat = @ {
641710 ElementName = $elementName
642- Attribute = $paramCopy
711+ Attribute = $attribute
643712 }
644713
645714 if ($content ) {
@@ -656,15 +725,18 @@ $OutputPath
656725 Write-SVG @writeSvgSplat
657726 }
658727
659- if (-not $parameters ) { continue }
660- $destination = Join-Path $PSScriptRoot " $ ( $newPipeScriptSplat.functionName ) .ps1"
728+ if (-not $parameters ) { continue }
729+ $destination = Join-Path $destFolder " $ ( $newPipeScriptSplat.functionName ) .ps1"
730+
731+
732+
661733 $newScript = New-PipeScript @newPipeScriptSplat
662- if (-not $newScript ) {
663- $null = $null
734+ if ($newScript ) {
735+ $newScript |
736+ Set-Content - Path $destination
737+ Get-Item - Path $destination
664738 }
665- $newScript |
666- Set-Content - Path $destination
667- Get-Item - Path $destination
739+
668740}
669741
670742Write-Progress " Getting Element Data" " $elementName " - Id $id - Completed
0 commit comments