Skip to content

Commit b9f74ba

Browse files
feat: Turtle.get/set_Attribute ( Fixes #247 )
1 parent cb0f1b6 commit b9f74ba

File tree

2 files changed

+61
-0
lines changed

2 files changed

+61
-0
lines changed

Types/Turtle/get_Attribute.ps1

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<#
2+
.SYNOPSIS
3+
Gets Turtle attributes
4+
.DESCRIPTION
5+
Gets attributes of the turtle.
6+
7+
These attributes apply directly to the Turtle as an `.Element`.
8+
9+
They can also be targeted to apply to an aspect of the turtle, such as it's Pattern, Path, Text, Mask, or Marker.
10+
11+
To set an attribute that targets an aspect of the turtle, prefix it with the name followed by a slash.
12+
13+
(for example `path/data-key` would set an attribute on the path)
14+
.EXAMPLE
15+
turtle attribute @{someKey='someValue'} attribute
16+
#>
17+
if (-not $this.'.Attributes') {
18+
$this | Add-Member NoteProperty '.Attributes' ([Ordered]@{}) -Force
19+
}
20+
return $this.'.Attributes'

Types/Turtle/set_Attribute.ps1

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<#
2+
.SYNOPSIS
3+
Sets Turtle attributes
4+
.DESCRIPTION
5+
Sets arbitrary attributes for the current Turtle.
6+
7+
Attributes generally apply to the topmost tag.
8+
9+
If an attribute contains a slash, it will be targeted to tags of that type.
10+
.EXAMPLE
11+
turtle attribute @{foo='bar'} attribute
12+
.EXAMPLE
13+
turtle attribute 'foo=bar' attribute
14+
#>
15+
param(
16+
[PSObject[]]
17+
$Attribute = [Ordered]@{}
18+
)
19+
20+
$myAttributes = $this.Attribute
21+
foreach ($attrSet in $Attribute) {
22+
if ($attrSet -is [Collections.IDictionary]) {
23+
foreach ($key in $attrSet.Keys) {
24+
$myAttributes[$key] = $attrSet[$key]
25+
}
26+
}
27+
elseif ($attrSet -is [string]) {
28+
if ($attrSet -match '[:=]') {
29+
$key, $value = $attrSet -split '[:=]', 2
30+
$myAttributes[$key] = $value
31+
} else {
32+
$myAttributes[$key] = ''
33+
}
34+
}
35+
elseif ($attrSet -is [PSObject]) {
36+
foreach ($key in $attrSet.psobject.properties.name) {
37+
$myAttributes[$key] = $attrSet.$key
38+
}
39+
}
40+
41+
}

0 commit comments

Comments
 (0)