Skip to content

Commit 7eaccc3

Browse files
Merge branch 'turtles-in-svg' of https://github.com/PowerShellWeb/Turtle into turtles-in-svg
2 parents 6de2157 + f17dbb1 commit 7eaccc3

File tree

1 file changed

+48
-11
lines changed

1 file changed

+48
-11
lines changed

Turtle.types.ps1xml

Lines changed: 48 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8356,14 +8356,31 @@ param()
83568356

83578357

83588358

8359-
@(
8359+
$javaScript = "$($this.JavaScript)"
8360+
return $javaScript
83608361

8361-
# Since we are building a javascript object, we need to wrap everything in curly braces
8362-
"{
8363-
"
8364-
# Indentation does not matter to most machines, but people tend to appreciate it.
8365-
" "
8366-
@(foreach ($javaScriptProperty in $this.psobject.properties | Sort-Object Name) {
8362+
</Script>
8363+
</ScriptMethod>
8364+
<ScriptProperty>
8365+
<Name>JavaScript</Name>
8366+
<GetScriptBlock>
8367+
&lt;#
8368+
.SYNOPSIS
8369+
`Turtle.js` definition
8370+
.DESCRIPTION
8371+
Our JavaScipt turtle is actually contained in a PowerShell object first.
8372+
8373+
This object has a number of properties ending with `.js`.
8374+
8375+
These are portions of the class.
8376+
8377+
To create our class, we simply join these properties together, and output a javascript object.
8378+
#&gt;
8379+
param()
8380+
8381+
$objectParts =
8382+
8383+
foreach ($javaScriptProperty in $this.psobject.properties | Sort-Object Name) {
83678384
# We only want the .js properties
83688385
if ($javaScriptProperty.Name -notmatch '\.js$') { continue }
83698386
# If the property is a function, we need to handle it differently
@@ -8372,17 +8389,37 @@ param()
83728389
$predicate, $extra = $javaScriptProperty.value -split '\(', 2
83738390
# and then we need to reassemble it as a javascript method
83748391
$functionName = $predicate -replace 'function\s{1,}'
8375-
"${functionName}:function ($extra"
8392+
if ($functionName -match '^[gs]et_') {
8393+
$getSet = $functionName -replace '_.+$'
8394+
$propertyName = $functionName -replace '^[gs]et_'
8395+
if ($getSet -eq 'get') {
8396+
$extra = $extra -replace '^.{0,}\)\s{0,}'
8397+
"$getSet ${propertyName}() $($extra)"
8398+
} else {
8399+
"$getSet ${propertyName}($($extra)"
8400+
}
8401+
8402+
} else {
8403+
"${functionName}:function ($extra"
8404+
}
8405+
83768406
}
83778407
else {
83788408
# Otherwise, include it inline.
83798409
$javaScriptProperty.value
83808410
}
83818411

8382-
}) -join (',' + [Environment]::Newline + ' ')
8412+
}
8413+
# Since we are building a javascript object, we need to wrap everything in curly braces
8414+
@("{
8415+
"
8416+
# Indentation does not matter to most machines, but people tend to appreciate it.
8417+
" "
8418+
($objectParts -join (',' + [Environment]::Newline + ' '))
83838419
"}") -join ''
8384-
</Script>
8385-
</ScriptMethod>
8420+
8421+
</GetScriptBlock>
8422+
</ScriptProperty>
83868423
<NoteProperty>
83878424
<Name>forward.js</Name>
83888425
<Value>function forward(distance) {

0 commit comments

Comments
 (0)