| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,5 +1,5 @@ | |||
| 1 | 1 | <?xml version="1.0" encoding="utf-16"?> | |
| 2 | - <!-- Generated with EZOut 1.8.6: Install-Module EZOut or https://github.com/StartAutomating/EZOut --> | ||
| 2 | + <!-- Generated with EZOut 1.8.7: Install-Module EZOut or https://github.com/StartAutomating/EZOut --> | ||
| 3 | 3 | <Configuration> | |
| 4 | 4 | <ViewDefinitions> | |
| 5 | 5 | <View> | |
@@ -262,6 +262,52 @@ | |||
| 262 | 262 | </TableRowEntries> | |
| 263 | 263 | </TableControl> | |
| 264 | 264 | </View> | |
| 265 | + <View> | ||
| 266 | + <Name>YAML</Name> | ||
| 267 | + <ViewSelectedBy> | ||
| 268 | + <TypeName>YAML</TypeName> | ||
| 269 | + </ViewSelectedBy> | ||
| 270 | + <CustomControl> | ||
| 271 | + <CustomEntries> | ||
| 272 | + <CustomEntry> | ||
| 273 | + <CustomItem> | ||
| 274 | + <ExpressionBinding> | ||
| 275 | + <ScriptBlock>$moduleName = 'PipeScript' | ||
| 276 | + | ||
| 277 | + do { | ||
| 278 | + $lm = Get-Module -Name $moduleName -ErrorAction Ignore | ||
| 279 | + if (-not $lm) { continue } | ||
| 280 | + if ($lm.FormatPartsLoaded) { break } | ||
| 281 | + $wholeScript = @(foreach ($formatFilePath in $lm.exportedFormatFiles) { | ||
| 282 | + foreach ($partNodeName in Select-Xml -LiteralPath $formatFilePath -XPath "/Configuration/Controls/Control/Name[starts-with(., '$')]") { | ||
| 283 | + $ParentNode = $partNodeName.Node.ParentNode | ||
| 284 | + "$($ParentNode.Name)={ | ||
| 285 | + $($ParentNode.CustomControl.CustomEntries.CustomEntry.CustomItem.ExpressionBinding.ScriptBlock)}" | ||
| 286 | + } | ||
| 287 | + }) -join [Environment]::NewLine | ||
| 288 | + New-Module -Name "${ModuleName}.format.ps1xml" -ScriptBlock ([ScriptBlock]::Create(($wholeScript + ';Export-ModuleMember -Variable *'))) | | ||
| 289 | + Import-Module -Global | ||
| 290 | + $onRemove = [ScriptBlock]::Create("Remove-Module '${ModuleName}.format.ps1xml'") | ||
| 291 | + | ||
| 292 | + if (-not $lm.OnRemove) { | ||
| 293 | + $lm.OnRemove = $onRemove | ||
| 294 | + } else { | ||
| 295 | + $lm.OnRemove = [ScriptBlock]::Create($onRemove.ToString() + '' + [Environment]::NewLine + $lm.OnRemove) | ||
| 296 | + } | ||
| 297 | + $lm | Add-Member NoteProperty FormatPartsLoaded $true -Force | ||
| 298 | + | ||
| 299 | + } while ($false) | ||
| 300 | + | ||
| 301 | + | ||
| 302 | + | ||
| 303 | + & ${PipeScript_Format-YAML} -inputObject $_ | ||
| 304 | + </ScriptBlock> | ||
| 305 | + </ExpressionBinding> | ||
| 306 | + </CustomItem> | ||
| 307 | + </CustomEntry> | ||
| 308 | + </CustomEntries> | ||
| 309 | + </CustomControl> | ||
| 310 | + </View> | ||
| 265 | 311 | </ViewDefinitions> | |
| 266 | 312 | <Controls> | |
| 267 | 313 | <Control> | |
@@ -1258,5 +1304,184 @@ $BackgroundColor | |||
| 1258 | 1304 | </CustomEntries> | |
| 1259 | 1305 | </CustomControl> | |
| 1260 | 1306 | </Control> | |
| 1307 | + <Control> | ||
| 1308 | + <Name>${PipeScript_Format-YAML}</Name> | ||
| 1309 | + <CustomControl> | ||
| 1310 | + <CustomEntries> | ||
| 1311 | + <CustomEntry> | ||
| 1312 | + <CustomItem> | ||
| 1313 | + <ExpressionBinding> | ||
| 1314 | + <ScriptBlock> | ||
| 1315 | + <# | ||
| 1316 | + .SYNOPSIS | ||
| 1317 | + Formats objects as YAML | ||
| 1318 | + .DESCRIPTION | ||
| 1319 | + Formats an object as YAML. | ||
| 1320 | + .EXAMPLE | ||
| 1321 | + Format-Yaml -InputObject @("a", "b", "c") | ||
| 1322 | + .EXAMPLE | ||
| 1323 | + @{a="b";c="d";e=@{f=@('g')}} | Format-Yaml | ||
| 1324 | + #> | ||
| 1325 | + [Management.Automation.Cmdlet("Format","Object")] | ||
| 1326 | + [ValidateScript({return $true})] | ||
| 1327 | + param( | ||
| 1328 | + # The InputObject. | ||
| 1329 | + [Parameter(ValueFromPipeline)] | ||
| 1330 | + [PSObject] | ||
| 1331 | + $inputObject, | ||
| 1332 | + | ||
| 1333 | + # If set, will make a YAML header by adding a YAML Document tag above and below output. | ||
| 1334 | + [Alias('YAMLDocument')] | ||
| 1335 | + [switch] | ||
| 1336 | + $YamlHeader | ||
| 1337 | + ) | ||
| 1338 | + | ||
| 1339 | + begin { | ||
| 1340 | + $toYaml = { | ||
| 1341 | + param( | ||
| 1342 | + [Parameter(ValueFromPipeline,Position=0)]$Object, | ||
| 1343 | + [Object]$Parent, | ||
| 1344 | + [Object]$GrandParent, | ||
| 1345 | + [int]$Indent = 0) | ||
| 1346 | + | ||
| 1347 | + begin { $n = 0; $mySelf = $myInvocation.MyCommand.ScriptBlock } | ||
| 1348 | + process { | ||
| 1349 | + $n++ | ||
| 1350 | + if ($Object -eq $null) { return } | ||
| 1351 | + | ||
| 1352 | + if ($Parent -and $Parent -is [Collections.IList]) { | ||
| 1353 | + if ($Parent.IndexOf($Object) -gt 0) { ' ' * $Indent } | ||
| 1354 | + '- ' | ||
| 1355 | + } | ||
| 1356 | + | ||
| 1357 | + #region Primitives | ||
| 1358 | + if ( $Object -is [string] ) { # If it's a string | ||
| 1359 | + if ($object -match '\n') { # see if it's a multline string. | ||
| 1360 | + "|" # If it is, emit the multiline indicator | ||
| 1361 | + $indent +=2 | ||
| 1362 | + foreach ($l in $object -split '(?>\r\n|\n)') { # and emit each line indented | ||
| 1363 | + [Environment]::NewLine | ||
| 1364 | + ' ' * $indent | ||
| 1365 | + $l | ||
| 1366 | + } | ||
| 1367 | + $indent -=2 | ||
| 1368 | + } elseif ("$object".Contains('*')) { | ||
| 1369 | + "'$($Object -replace "'","''")'" | ||
| 1370 | + } else { | ||
| 1371 | + $object | ||
| 1372 | + } | ||
| 1373 | + | ||
| 1374 | + if ($Parent -is [Collections.IList]) { # If the parent object was a list | ||
| 1375 | + [Environment]::NewLine # emit a newline. | ||
| 1376 | + } | ||
| 1377 | + return # Once the string has been emitted, return. | ||
| 1378 | + } | ||
| 1379 | + if ( [int], [float], [bool] -contains $Object.GetType() ) { # If it is an [int] or [float] or [bool] | ||
| 1380 | + "$Object".ToLower() # Emit it in lowercase. | ||
| 1381 | + if ($Parent -is [Collections.IList]) { | ||
| 1382 | + [Environment]::NewLine | ||
| 1383 | + } | ||
| 1384 | + return | ||
| 1385 | + } | ||
| 1386 | + #endregion Primitives | ||
| 1387 | + | ||
| 1388 | + #region KVP | ||
| 1389 | + if ( $Object -is [Collections.DictionaryEntry] -or $object -is [Management.Automation.PSPropertyInfo]) { | ||
| 1390 | + if ($Parent -isnot [Collections.IList] -and | ||
| 1391 | + ($GrandParent -isnot [Collections.IList] -or $n -gt 1)) { | ||
| 1392 | + [Environment]::NewLine + (" " * $Indent) | ||
| 1393 | + } | ||
| 1394 | + if ($object.Key -and $Object.Key -is [string]) { | ||
| 1395 | + $Object.Key +": " | ||
| 1396 | + } elseif ($object.Name -and $object.Name -is [string]) { | ||
| 1397 | + $Object.Name +": " | ||
| 1398 | + } | ||
| 1399 | + } | ||
| 1400 | + | ||
| 1401 | + if ( $Object -is [Collections.DictionaryEntry] -or $Object -is [Management.Automation.PSPropertyInfo]) { | ||
| 1402 | + & $mySelf -Object $Object.Value -Parent $Object -GrandParent $parent -Indent $Indent | ||
| 1403 | + return | ||
| 1404 | + } | ||
| 1405 | + #endregion KVP | ||
| 1406 | + | ||
| 1407 | + | ||
| 1408 | + #region Nested | ||
| 1409 | + if ($parent -and ($Object -is [Collections.IDictionary] -or $Object -is [PSObject])) { | ||
| 1410 | + $Indent += 2 | ||
| 1411 | + } | ||
| 1412 | + elseif ($object -is [Collections.IList]) { | ||
| 1413 | + $allPrimitive = 1 | ||
| 1414 | + foreach ($Obj in $Object) { | ||
| 1415 | + $allPrimitive = $allPrimitive -band ( | ||
| 1416 | + $Obj -is [string] -or | ||
| 1417 | + $obj -is [int] -or | ||
| 1418 | + $obj -is [float] -or | ||
| 1419 | + $obj -is [bool] | ||
| 1420 | + ) | ||
| 1421 | + } | ||
| 1422 | + if ($parent -and -not $allPrimitive) { | ||
| 1423 | + $Indent += 2 | ||
| 1424 | + } | ||
| 1425 | + } | ||
| 1426 | + | ||
| 1427 | + | ||
| 1428 | + if ( $Object -is [Collections.IDictionary] ) { | ||
| 1429 | + $Object.GetEnumerator() | | ||
| 1430 | + & $mySelf -Parent $Object -GrandParent $Parent -Indent $Indent | ||
| 1431 | + } elseif ($Object -is [Collections.IList]) { | ||
| 1432 | + | ||
| 1433 | + [Environment]::NewLine + (' ' * $Indent) | ||
| 1434 | + | ||
| 1435 | + $Object | | ||
| 1436 | + & $mySelf -Parent $Object -GrandParent $Parent -Indent $Indent | ||
| 1437 | + | ||
| 1438 | + } elseif ($Object.PSObject.Properties) { | ||
| 1439 | + $Object.psobject.properties | | ||
| 1440 | + & $mySelf -Parent $Object -GrandParent $Parent -Indent $Indent | ||
| 1441 | + } | ||
| 1442 | + | ||
| 1443 | + if ($Object -is [Collections.IDictionary] -or $Object -is [PSCustomObject] -or $Object -is [Collections.IList]) { | ||
| 1444 | + if ($Parent -is [Collections.IList]) { [Environment]::NewLine } | ||
| 1445 | + $Indent -= 2; | ||
| 1446 | + } | ||
| 1447 | + #endregion Nested | ||
| 1448 | + } | ||
| 1449 | + } | ||
| 1450 | + $inputWasNotPiped = $PSBoundParameters.InputObject -as [bool] | ||
| 1451 | + $allInputObjects = @() | ||
| 1452 | + } | ||
| 1453 | + | ||
| 1454 | + process { | ||
| 1455 | + if ($inputWasNotPiped) { | ||
| 1456 | + '' + $(if ($YamlHeader) { '---' + [Environment]::NewLine }) + ( | ||
| 1457 | + (& $toYaml -object $inputObject) -join '' -replace | ||
| 1458 | + "$([Environment]::NewLine * 2)", [Environment]::NewLine | ||
| 1459 | + ) + $(if ($YamlHeader) { [Environment]::NewLine + '---'}) | ||
| 1460 | + } else { | ||
| 1461 | + $allInputObjects += $inputObject | ||
| 1462 | + } | ||
| 1463 | + } | ||
| 1464 | + | ||
| 1465 | + end { | ||
| 1466 | + if (-not $allInputObjects) { return } | ||
| 1467 | + if ($allInputObjects.Length -eq 1) { | ||
| 1468 | + '' + $(if ($YamlHeader) { '---' + [Environment]::NewLine}) + ( | ||
| 1469 | + (& $toYaml -object $inputObject) -join '' -replace | ||
| 1470 | + "$([Environment]::NewLine * 2)", [Environment]::NewLine | ||
| 1471 | + ) + $(if ($YamlHeader) { [Environment]::NewLine + '---'}) | ||
| 1472 | + } else { | ||
| 1473 | + '' + $(if ($YamlHeader) { '---' + [Environment]::NewLine}) + ( | ||
| 1474 | + (& $toYaml -object $allInputObjects) -join '' -replace | ||
| 1475 | + "$([Environment]::NewLine * 2)", [Environment]::NewLine | ||
| 1476 | + ) + $(if ($YamlHeader) { [Environment]::NewLine + '---'}) | ||
| 1477 | + } | ||
| 1478 | + } | ||
| 1479 | + </ScriptBlock> | ||
| 1480 | + </ExpressionBinding> | ||
| 1481 | + </CustomItem> | ||
| 1482 | + </CustomEntry> | ||
| 1483 | + </CustomEntries> | ||
| 1484 | + </CustomControl> | ||
| 1485 | + </Control> | ||
| 1261 | 1486 | </Controls> | |
| 1262 | 1487 | </Configuration> | |
| Back | FazBrowse Home | New Git URL |
0 commit comments