Skip to content

Commit 0d9e3cd

Browse files
StartAutomatingStartAutomating
authored andcommitted
feat: Turtle.get/set_Attribute ( Fixes #247 )
1 parent b9f74ba commit 0d9e3cd

File tree

1 file changed

+69
-0
lines changed

1 file changed

+69
-0
lines changed

Turtle.types.ps1xml

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4583,6 +4583,75 @@ foreach ($arg in $this.Invocations.BoundParameters['ArgumentList']) {
45834583
}
45844584
</GetScriptBlock>
45854585
</ScriptProperty>
4586+
<ScriptProperty>
4587+
<Name>Attribute</Name>
4588+
<GetScriptBlock>
4589+
&lt;#
4590+
.SYNOPSIS
4591+
Gets Turtle attributes
4592+
.DESCRIPTION
4593+
Gets attributes of the turtle.
4594+
4595+
These attributes apply directly to the Turtle as an `.Element`.
4596+
4597+
They can also be targeted to apply to an aspect of the turtle, such as it's Pattern, Path, Text, Mask, or Marker.
4598+
4599+
To set an attribute that targets an aspect of the turtle, prefix it with the name followed by a slash.
4600+
4601+
(for example `path/data-key` would set an attribute on the path)
4602+
.EXAMPLE
4603+
turtle attribute @{someKey='someValue'} attribute
4604+
#&gt;
4605+
if (-not $this.'.Attributes') {
4606+
$this | Add-Member NoteProperty '.Attributes' ([Ordered]@{}) -Force
4607+
}
4608+
return $this.'.Attributes'
4609+
</GetScriptBlock>
4610+
<SetScriptBlock>
4611+
&lt;#
4612+
.SYNOPSIS
4613+
Sets Turtle attributes
4614+
.DESCRIPTION
4615+
Sets arbitrary attributes for the current Turtle.
4616+
4617+
Attributes generally apply to the topmost tag.
4618+
4619+
If an attribute contains a slash, it will be targeted to tags of that type.
4620+
.EXAMPLE
4621+
turtle attribute @{foo='bar'} attribute
4622+
.EXAMPLE
4623+
turtle attribute 'foo=bar' attribute
4624+
#&gt;
4625+
param(
4626+
[PSObject[]]
4627+
$Attribute = [Ordered]@{}
4628+
)
4629+
4630+
$myAttributes = $this.Attribute
4631+
foreach ($attrSet in $Attribute) {
4632+
if ($attrSet -is [Collections.IDictionary]) {
4633+
foreach ($key in $attrSet.Keys) {
4634+
$myAttributes[$key] = $attrSet[$key]
4635+
}
4636+
}
4637+
elseif ($attrSet -is [string]) {
4638+
if ($attrSet -match '[:=]') {
4639+
$key, $value = $attrSet -split '[:=]', 2
4640+
$myAttributes[$key] = $value
4641+
} else {
4642+
$myAttributes[$key] = ''
4643+
}
4644+
}
4645+
elseif ($attrSet -is [PSObject]) {
4646+
foreach ($key in $attrSet.psobject.properties.name) {
4647+
$myAttributes[$key] = $attrSet.$key
4648+
}
4649+
}
4650+
4651+
}
4652+
4653+
</SetScriptBlock>
4654+
</ScriptProperty>
45864655
<ScriptProperty>
45874656
<Name>BackgroundColor</Name>
45884657
<GetScriptBlock>

0 commit comments

Comments
 (0)