Skip to content

Commit 9d311de

Browse files
Merge pull request #96 from StartAutomating/PSSVG-Expansion
PSSVG 0.2.8
2 parents b7a0d44 + 970e998 commit 9d311de

File tree

322 files changed

+29001
-20572
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

322 files changed

+29001
-20572
lines changed

.github/workflows/TestAndPublish.yml

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -383,32 +383,34 @@ jobs:
383383
384384
if ($releaseExists) {
385385
"::warning::Release '$($releaseExists.Name )' Already Exists" | Out-Host
386-
return
386+
$releasedIt = $releaseExists
387+
} else {
388+
$releasedIt = Invoke-RestMethod -Uri $releasesURL -Method Post -Body (
389+
[Ordered]@{
390+
owner = '${{github.owner}}'
391+
repo = '${{github.repository}}'
392+
tag_name = $targetVersion
393+
name = $ExecutionContext.InvokeCommand.ExpandString($ReleaseNameFormat)
394+
body =
395+
if ($env:RELEASENOTES) {
396+
$env:RELEASENOTES
397+
} elseif ($imported.PrivateData.PSData.ReleaseNotes) {
398+
$imported.PrivateData.PSData.ReleaseNotes
399+
} else {
400+
"$($imported.Name) $targetVersion"
401+
}
402+
draft = if ($env:RELEASEISDRAFT) { [bool]::Parse($env:RELEASEISDRAFT) } else { $false }
403+
prerelease = if ($env:PRERELEASE) { [bool]::Parse($env:PRERELEASE) } else { $false }
404+
} | ConvertTo-Json
405+
) -Headers @{
406+
"Accept" = "application/vnd.github.v3+json"
407+
"Content-type" = "application/json"
408+
"Authorization" = 'Bearer ${{ secrets.GITHUB_TOKEN }}'
409+
}
387410
}
388411
389412
390-
$releasedIt = Invoke-RestMethod -Uri $releasesURL -Method Post -Body (
391-
[Ordered]@{
392-
owner = '${{github.owner}}'
393-
repo = '${{github.repository}}'
394-
tag_name = $targetVersion
395-
name = $ExecutionContext.InvokeCommand.ExpandString($ReleaseNameFormat)
396-
body =
397-
if ($env:RELEASENOTES) {
398-
$env:RELEASENOTES
399-
} elseif ($imported.PrivateData.PSData.ReleaseNotes) {
400-
$imported.PrivateData.PSData.ReleaseNotes
401-
} else {
402-
"$($imported.Name) $targetVersion"
403-
}
404-
draft = if ($env:RELEASEISDRAFT) { [bool]::Parse($env:RELEASEISDRAFT) } else { $false }
405-
prerelease = if ($env:PRERELEASE) { [bool]::Parse($env:PRERELEASE) } else { $false }
406-
} | ConvertTo-Json
407-
) -Headers @{
408-
"Accept" = "application/vnd.github.v3+json"
409-
"Content-type" = "application/json"
410-
"Authorization" = 'Bearer ${{ secrets.GITHUB_TOKEN }}'
411-
}
413+
412414
413415
414416
if (-not $releasedIt) {
@@ -443,10 +445,9 @@ jobs:
443445
$fileBytes = [IO.File]::ReadAllBytes($file.FullName)
444446
$releasedFiles[$file.Name] =
445447
Invoke-RestMethod -Uri "${releaseUploadUrl}?name=$($file.Name)" -Headers @{
446-
"Accept" = "application/vnd.github+json"
447-
"ContentType" = "application/octet-stream"
448+
"Accept" = "application/vnd.github+json"
448449
"Authorization" = 'Bearer ${{ secrets.GITHUB_TOKEN }}'
449-
} -Body $fileBytes
450+
} -Body $fileBytes -ContentType Application/octet-stream
450451
$releasedFiles[$file.Name]
451452
}
452453
}
@@ -586,3 +587,4 @@ jobs:
586587
uses: StartAutomating/HelpOut@master
587588
env:
588589
NoCoverage: true
590+
GIT_TOKEN: ${{secrets.GITHUB_TOKEN}}

Assets/PSSVG.svg

Lines changed: 5 additions & 5 deletions
Loading

CHANGELOG.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,27 @@
1+
### 0.2.8:
2+
3+
* General Improvements:
4+
* General Event support on every command with -On (Fixes #91)
5+
* Reduced Warnings in GitHub Action (Fixes #94)
6+
* New Commands:
7+
* SVG.ANSI (Fixes #82)
8+
* SVG.StyleSheet (Fixes #83)
9+
* SVG.GoogleFont (Fixes #84)
10+
* Demystifying Path syntax
11+
* SVG.ArcPath (Fixes #80)
12+
* SVG.CurvePath (Fixes #81)
13+
* SVG.LinePath (Fixes #90)
14+
* Pipeline improvements:
15+
* Allowing -Content to be provided from the pipeline
16+
* Removing 'Attributes' parameter alias (Fixes #85)
17+
* Command Improvements
18+
* SVG.Sprial can -ScaleX/-ScaleY (Fixes #77)
19+
* Example Updates
20+
* New Examples
21+
* Examples avoid tag-style syntax (Fixes #95)
22+
23+
---
24+
125
### 0.2.7:
226
* Adding SVG.Star (Fixes #68)
327
* Fixing OutputPath issue (Fixes #67)

Commands/Common/Write-SVG.ps1

Lines changed: 42 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,16 @@
2929
[PSObject]
3030
$Content,
3131

32+
# A dictionary or object containing event handlers.
33+
# Each key or property name will be the name of the event
34+
# Each value will be the handler.
35+
[Parameter(ValueFromPipelineByPropertyName)]
36+
$On,
37+
3238
# An output path.
3339
[Parameter(ValueFromPipelineByPropertyName)]
3440
[string]
35-
$OutputPath
41+
$OutputPath
3642
)
3743

3844
begin {
@@ -55,7 +61,7 @@
5561
"$($prop.Name):$($kv.Value)"
5662
}) -join ';'
5763
}
58-
}
64+
}
5965

6066
$elementText = "<$elementName "
6167
:nextParameter foreach ($kv in $Attribute.GetEnumerator()) {
@@ -89,6 +95,28 @@
8995
}
9096
}
9197

98+
if ($On) {
99+
$eventNames = @(
100+
if ($on -is [Collections.IDictionary]) {
101+
$on.Keys
102+
} else {
103+
$on.psobject.properties.name
104+
}
105+
)
106+
foreach ($eventName in $eventNames) {
107+
$svgEventName = $eventName -replace '^On' -replace '^[_-]'
108+
$eventValue = if ($on -is [Collections.IDictionary]) {
109+
$on[$eventName]
110+
} else {
111+
$on.$eventName
112+
}
113+
$elementText +=
114+
"on" + $svgEventName.ToLower() + "=`"" + $(
115+
[Web.HttpUtility]::HtmlAttributeEncode($eventValue)
116+
) + '" '
117+
}
118+
}
119+
92120
if ($elementName -eq 'svg') {
93121
$elementText += 'xmlns:xlink="http://www.w3.org/1999/xlink" xmlns="http://www.w3.org/2000/svg"'
94122
}
@@ -103,10 +131,7 @@
103131
if ($attr.Key -eq 'SVG.IsCData' -and $attr.Value -eq 'true') {
104132
$isCData = $true
105133
}
106-
}
107-
if ($ElementName -eq 'text') {
108-
$null = $null
109-
}
134+
}
110135

111136
$elementText += ">"
112137
$elementText +=
@@ -115,7 +140,7 @@
115140
($pieceOfContent -as [xml.xmlelement]) -and
116141
($pieceOfContent -notmatch '^\s{0,}\<')
117142
) {
118-
[Security.SecurityElement]::Escape("$content")
143+
[Security.SecurityElement]::Escape("$pieceOfContent")
119144
}
120145
elseif ($pieceOfContent.Outerxml) {
121146
$pieceOfContent.Outerxml
@@ -141,16 +166,23 @@
141166
$elementText
142167
}
143168

144-
if ($OutputPath) {
169+
$myParams = @{} + $PSBoundParameters
170+
if ($myParams['OutputPath']) {
145171
$unresolvedOutput = $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath($OutputPath)
146172
if ($unresolvedOutput -and $svgOutput.ParentNode.Save) {
147173
$svgOutput.ParentNode.PreserveWhitespace = $true
174+
$memoryStream = [io.memorystream]::new()
175+
$streamWriter = [io.streamWriter]::new($memoryStream)
148176
$writerSettings = [Xml.XmlWriterSettings]::new()
149177
$writerSettings.Encoding = [Text.Encoding]::UTF8
150178
$writerSettings.Indent = $true
151-
$writer = [Xml.XmlWriter]::Create("$unresolvedOutput", $writerSettings)
152-
$svgOutput.ParentNode.Save($writer)
179+
$writer = [Xml.XmlWriter]::Create($streamWriter, $writerSettings)
180+
$svgOutput.ParentNode.Save($writer)
181+
[Text.Encoding]::UTF8.GetString($memoryStream.ToArray()) |
182+
Set-Content -Path $OutputPath -Encoding UTF8
153183
$writer.Dispose()
184+
$streamWriter.Dispose()
185+
$memoryStream.Dispose()
154186
Get-Item $OutputPath
155187
} elseif ($unresolvedOutput -and $svgOutput) {
156188
$svgOutput | Set-Content -Path $OutputPath

0 commit comments

Comments
 (0)