Skip to content

Commit 433784c

Browse files
author
James Brundage
committed
Adding Inline Ruby Support (#42)
1 parent ae5c43e commit 433784c

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<#
2+
.SYNOPSIS
3+
Ruby Inline PipeScript Transpiler.
4+
.DESCRIPTION
5+
Transpiles Ruby with Inline PipeScript into Ruby.
6+
7+
PipeScript can be embedded in a multiline block that starts with ```=begin{``` and ends with } (followed by ```=end```)
8+
#>
9+
[ValidateScript({
10+
$cmdInfo = $_
11+
if ($cmdInfo.Source -match '\.rb$') {
12+
return $true
13+
}
14+
return $false
15+
})]
16+
param(
17+
# The command information. This will include the path to the file.
18+
[Parameter(Mandatory,ValueFromPipeline)]
19+
$CommandInfo
20+
)
21+
22+
begin {
23+
# We start off by declaring a number of regular expressions:
24+
25+
$startComment = '(?>[\r\n]{1,3}\s{0,}=begin[\s\r\n]{0,}\{)'
26+
$endComment = '(?>}[\r\n]{1,3}\s{0,}=end)'
27+
28+
$ignoreEach = '[\d\.]+',
29+
'""',
30+
"''"
31+
32+
$IgnoredContext = "(?<ignore>(?>$($ignoreEach -join '|'))\s{0,}){0,1}"
33+
34+
$startRegex = "(?<PSStart>${IgnoredContext}${startComment})"
35+
$endRegex = "(?<PSEnd>${endComment}${IgnoredContext})"
36+
37+
$sourcePattern = [Regex]::New("(?>$(
38+
$startRegex, $endRegex -join ([Environment]::NewLine + '|' + [Environment]::NewLine)
39+
))", "IgnoreCase, IgnorePatternWhitespace", "00:00:05")
40+
}
41+
42+
process {
43+
44+
$fileInfo = $commandInfo.Source -as [IO.FileInfo]
45+
$fileText = [IO.File]::ReadAllText($fileInfo.Fullname)
46+
47+
.>PipeScript.Inline -SourceFile $CommandInfo.Source -SourceText $fileText -SourcePattern $sourcePattern
48+
}

0 commit comments

Comments
 (0)