Skip to content

Commit ef221c1

Browse files
Merge pull request #62 from StartAutomating/ConvertTo-PSSVG-Fix
Convert to pssvg fix
2 parents 6837480 + 58cb8e5 commit ef221c1

File tree

8 files changed

+64
-15
lines changed

8 files changed

+64
-15
lines changed

Assets/PSSVG.svg

Lines changed: 3 additions & 3 deletions
Loading

CHANGELOG.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
### 0.2.5:
2+
* ConvertTo-PSSVG improvements:
3+
* Better at handling malformed XML (#59)
4+
* Better at handling file input (#60, #61)
5+
6+
---
7+
18
### 0.2.4:
29
* Adding ConvertTo-PSSVG (Fixes #53)
310
* Updated Logo to use PowerShell Chevron (Fixes #52)
@@ -62,4 +69,4 @@
6269
* The script used to generate every SVG element (fixes #8)
6370
* [A github page](https://PSSVG.start-automating.com) (fixes #9)
6471

65-
---
72+
---

Commands/Common/ConvertTo-PSSVG.ps1

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@ function ConvertTo-PSSVG
1414
.EXAMPLE
1515
ConvertTo-PSSVG -InputObject "<svg><circle cx='5' cy='5' r='3'></svg>"
1616
#>
17-
param(
18-
[Parameter(Mandatory)]
17+
param(
18+
[Parameter(Mandatory,ValueFromPipeline,ValueFromPipelineByPropertyName)]
19+
[Alias('Fullname')]
1920
$InputObject
2021
)
2122

@@ -24,7 +25,7 @@ function ConvertTo-PSSVG
2425
filter ToPSSVG {
2526
if ($_.LocalName -eq '#whitespace') { return }
2627
if ($_.LocalName -eq '#text') {
27-
"'$($_.Value -replace "'", "''")'"
28+
(' ' * (4 * $indentDepth)) + "'$($_.Value -replace "'", "''")'"
2829
} elseif ($_.LocalName) {
2930
$xin = $_
3031
$svgCmdName = if ($xin.LocalName -ne 'SVG') {
@@ -67,17 +68,27 @@ function ConvertTo-PSSVG
6768
}
6869

6970
process {
71+
$originalInputObject = $InputObject
7072
# If the input looks like a URL
7173
if ($InputObject -match '^https{0,1}://')
7274
{
7375
# go get it
7476
$InputObject = Invoke-RestMethod -Uri $InputObject
77+
if ($InputObject -is [string]) {
78+
$InputObject = ($InputObject -replace '^[^<]+') -as [xml]
79+
}
7580
} elseif ($InputObject -isnot [xml] -and
7681
$InputObject -isnot [Xml.XmlDocument] -and
77-
(-not $InputObject -as [xml])
82+
(-not ($InputObject -as [xml]))
7883
) {
7984
# If it's not XML and won't be XML, try loading it from a file.
80-
$resolvedPath = $ExecutionContext.SessionState.Path.GetResolvedPSPathFromPSPath($InputObject)
85+
$resolvedPath =
86+
if ($InputObject -is [IO.FileInfo]) {
87+
$InputObject.FullName
88+
} else {
89+
$ExecutionContext.SessionState.Path.GetResolvedPSPathFromPSPath($InputObject)
90+
}
91+
8192
if (-not $resolvedPath) { return }
8293
if ($resolvedPath) {
8394
$inputObject = [xml][IO.File]::ReadAllText($resolvedPath)
@@ -89,7 +100,7 @@ function ConvertTo-PSSVG
89100

90101
# If the input isn't XML at this point, error out.
91102
if ($InputObject -isnot [xml] -and $InputObject -isnot [Xml.XmlDocument]) {
92-
Write-Error "Could not convert input to XML"
103+
Write-Error "Could not convert input '$originalInputObject' to XML"
93104
return
94105
}
95106

PSSVG.psd1

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
@{
2-
ModuleVersion = '0.2.4'
2+
ModuleVersion = '0.2.5'
33
Guid = '77696e6e-0252-43f2-b914-2dfa63953c60'
44
CompanyName = 'Start-Automating'
55
Copyright = '2022 Start-Automating'
@@ -14,6 +14,13 @@
1414
ProjectURI = 'https://github.com/StartAutomating/PSSVG'
1515
LicenseURI = 'https://github.com/StartAutomating/PSSVG/blob/main/LICENSE'
1616
ReleaseNotes = @'
17+
### 0.2.5:
18+
* ConvertTo-PSSVG improvements:
19+
* Better at handling malformed XML (#59)
20+
* Better at handling file input (#60, #61)
21+
22+
---
23+
1724
### 0.2.4:
1825
* Adding ConvertTo-PSSVG (Fixes #53)
1926
* Updated Logo to use PowerShell Chevron (Fixes #52)

PSSVG.tests.ps1

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,20 @@ describe PSSVG {
2626
}
2727
}
2828
}
29+
30+
context 'Converting SVGs' {
31+
it 'Can convert SVGs to PSSVG' {
32+
ConvertTo-PSSVG https://raw.githubusercontent.com/StartAutomating/PSSVG/main/Assets/PSSVG.svg |
33+
ForEach-Object {
34+
$_.GetType() | Should -Be ([scriptblock])
35+
}
36+
37+
Get-ChildItem -Path $PSScriptRoot -Filter *.svg |
38+
Select-Object -First 1 |
39+
ConvertTo-PSSVG |
40+
ForEach-Object {
41+
$_.GetType() | Should -Be ([scriptblock])
42+
}
43+
}
44+
}
2945
}

docs/Assets/PSSVG.svg

Lines changed: 3 additions & 3 deletions
Loading

docs/CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
### 0.2.5:
2+
* ConvertTo-PSSVG improvements:
3+
* Better at handling malformed XML (#59)
4+
* Better at handling file input (#60, #61)
5+
6+
---
7+
18
### 0.2.4:
29
* Adding ConvertTo-PSSVG (Fixes #53)
310
* Updated Logo to use PowerShell Chevron (Fixes #52)
@@ -63,3 +70,4 @@
6370
* [A github page](https://PSSVG.start-automating.com) (fixes #9)
6471

6572
---
73+

docs/ConvertTo-PSSVG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ ConvertTo-PSSVG -InputObject .\a.svg
4242
4343
> **Position**: 1
4444
45-
> **PipelineInput**:false
45+
> **PipelineInput**:true (ByValue, ByPropertyName)
4646
4747

4848

0 commit comments

Comments
 (0)