Directive to run embedded scripts - LaurentDardenne/Template GitHub Wiki

The directive ScriptBlock run Powershell code.

By example this text :

Cd .\Demos
$File="$env:temp\Code.T.PS1"
@'
Write 'Text before the directive'
<#%ScriptBlock%
    #<DEFINE %V5%>
        . .\Convert-ObjectToClass.ps1
        #Class PS >= v5
        Convert-ObjectToClass -InputObject (Get-Process|Select Name,VirtualMemorySize -First 1)
    #<UNDEF %V5%>

    #<DEFINE %V3%>
        . .\New-PSCustomObjectFunction.ps1
        #PSCustomObject >= v3
        New-PSCustomObjectFunction -Noun ProcessLight -Parameters Name,VirtualMemorySize -AsFunction
    #<UNDEF %V3%>
#>
Write 'Text after the directive'
'@ > $File

with this statements :

#code generation for Powershell version 5
Get-Content -Path $File  -ReadCount 0 -Encoding UTF8|
 Edit-Template -ConditionnalsKeyWord  "V3"|
 Edit-Template -Clean|
 Out-string|
 Edit-String -Setting  $TemplateDefaultSettings

is transformed to :

Write 'Text before the directive'
class ProcessLight
{
        [string] $Name;
        [int] $VirtualMemorySize;

        ProcessLight([System.Diagnostics.Process] $Process) {
                $this.Name = $Process.Name
                $this.VirtualMemorySize = $Process.VirtualMemorySize

        }
} #ProcessLight
Write 'Text after the directive'
⚠️ **GitHub.com Fallback** ⚠️