1+ <#
2+ . SYNOPSIS
3+ Razor Inline PipeScript Transpiler.
4+ . DESCRIPTION
5+ Transpiles Razor with Inline PipeScript into Razor.
6+
7+ Multiline comments blocks like this ```<!--{}-->``` will be treated as blocks of PipeScript.
8+
9+ JavaScript/CSS comment blocks like ```/*{}*/``` will also be treated as blocks of PipeScript.
10+
11+ Razor comment blocks like ```@*{}*@``` will also be treated as blocks of PipeScript.
12+ #>
13+ [ValidateScript ({
14+ $cmdInfo = $_
15+ if ($cmdInfo.Source -match ' \.(cshtml|razor)$' ) {
16+ return $true
17+ }
18+ return $false
19+ })]
20+ param (
21+ # The command information. This will include the path to the file.
22+ [Parameter (Mandatory , ValueFromPipeline )]
23+ $CommandInfo
24+ )
25+
26+ begin {
27+ # We start off by declaring a number of regular expressions:
28+ $startComment = ' (?><\!--|/\*|\@\*)'
29+ $endComment = ' (?>-->|\*/|\*@)'
30+ $Whitespace = ' [\s\n\r]{0,}'
31+ # * StartRegex ```$StartComment + '{' + $Whitespace```
32+ $startRegex = " (?<PSStart>${startComment} \{$Whitespace )"
33+ # * EndRegex ```$whitespace + '}' + $EndComment```
34+ $endRegex = " (?<PSEnd>$Whitespace \}${endComment} \s{0,})"
35+
36+ $sourcePattern = [Regex ]::New(" (?>$ (
37+ $startRegex , $endRegex -join ([Environment ]::NewLine + ' |' + [Environment ]::NewLine)
38+ ) )" , " IgnoreCase, IgnorePatternWhitespace" , " 00:00:05" )
39+ }
40+
41+ process {
42+
43+ $fileInfo = $commandInfo.Source -as [IO.FileInfo ]
44+ $fileText = [IO.File ]::ReadAllText($fileInfo.Fullname )
45+
46+ .> PipeScript.Inline - SourceFile $CommandInfo.Source - SourceText $fileText - SourcePattern $sourcePattern
47+ }
0 commit comments