{"id":16484881,"url":"https://github.com/laurentdardenne/template","last_synced_at":"2025-09-09T04:38:52.736Z","repository":{"id":43607462,"uuid":"71456808","full_name":"LaurentDardenne/Template","owner":"LaurentDardenne","description":"Code generation by using text templates","archived":false,"fork":false,"pushed_at":"2017-08-01T10:32:13.000Z","size":174,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-09-01T17:51:13.612Z","etag":null,"topics":["conditional","parsing-engine","powershell","powershell-module","preprocessing","preprocessor","regex","template","template-engine","transformations"],"latest_commit_sha":null,"homepage":null,"language":"PowerShell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/LaurentDardenne.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-10-20T11:35:05.000Z","updated_at":"2022-10-31T21:44:09.000Z","dependencies_parsed_at":"2022-09-13T20:01:49.372Z","dependency_job_id":null,"html_url":"https://github.com/LaurentDardenne/Template","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/LaurentDardenne/Template","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LaurentDardenne%2FTemplate","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LaurentDardenne%2FTemplate/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LaurentDardenne%2FTemplate/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LaurentDardenne%2FTemplate/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/LaurentDardenne","download_url":"https://codeload.github.com/LaurentDardenne/Template/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LaurentDardenne%2FTemplate/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":274244212,"owners_count":25248157,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-09-09T02:00:10.223Z","response_time":80,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["conditional","parsing-engine","powershell","powershell-module","preprocessing","preprocessor","regex","template","template-engine","transformations"],"created_at":"2024-10-11T13:18:37.111Z","updated_at":"2025-09-09T04:38:52.694Z","avatar_url":"https://github.com/LaurentDardenne.png","language":"PowerShell","funding_links":[],"categories":[],"sub_categories":[],"readme":"﻿[![Build status](https://ci.appveyor.com/api/projects/status/ll5tv37ggguiulva?svg=true)](https://ci.appveyor.com/project/LaurentDardenne/template)\n                                                                                    \n![Logo](https://raw.githubusercontent.com/LaurentDardenne/Template/master/Assets/Template.png)\n\n# Template\nCode generation by using text templates.\nA template specifies a text template with placeholders for data to be extracted from models.\n\nThe 'Template' module offers these features:\n * [Text replacement](https://github.com/LaurentDardenne/Template/wiki/Text-replacement), simple or by regex or regex with [MatchEvaluator](https://msdn.microsoft.com/en-us/library/system.text.regularexpressions.matchevaluator(v=vs.110).aspx) (Scriptblock)\n * [File inclusion](https://github.com/LaurentDardenne/Template/wiki/File-inclusion)\n * [Directive to run embedded scripts](https://github.com/LaurentDardenne/Template/wiki/Directive-to-run-embedded-scripts)\n * [Conditionnal directive](https://github.com/LaurentDardenne/Template/wiki/Conditionnal-directives) (#Define \u0026 #Undef)\n * [Removal and uncomment directive](https://github.com/LaurentDardenne/Template/wiki/Removal-and-uncomment-directive)\n\n## Install\n```powershell\n$PSGalleryPublishUri = 'https://www.myget.org/F/ottomatt/api/v2/package'\n$PSGallerySourceUri = 'https://www.myget.org/F/ottomatt/api/v2'\nRegister-PSRepository -Name OttoMatt -SourceLocation $PSGallerySourceUri -PublishLocation $PSGalleryPublishUri #-InstallationPolicy Trusted\n\nInstall-Module Template -Repository OttoMatt\n```\n## Principle\nA template is a file that serves as a starting point for a new document.\nThe 'Template' module, allow to insert directives, as a comment, inside the source code.\nFor example :\n```Powershell\n    Write-Debug 'Test' #\u003c%REMOVE%\u003e\n```\nIn this case, the presence of this directive does not require to transform the source code before to execute it.\n\nFor this example, the directives require a transformation :\n```Powershell\nImport-Module Template\n #Initialize-TemplateModule.ps1 create the hashtable $TemplateDefaultSettings\n\n$File='C:\\temp\\Code.PS1'\n@'\nWrite 'Text before the directive'\n\u003c#%ScriptBlock%\n    #\u003cDEFINE %V5%\u003e\n        . .\\Convert-ObjectToClass.ps1\n        #Class PS \u003e= v5\n        Convert-ObjectToClass -InputObject (Get-Process|Select Name,VirtualMemorySize -First 1)\n    #\u003cUNDEF %V5%\u003e\n\n    #\u003cDEFINE %V3%\u003e\n        . .\\New-PSCustomObjectFunction.ps1\n        #PSCustomObject \u003e= v3\n        New-PSCustomObjectFunction -Noun ProcessLight -Parameters Name,VirtualMemorySize -AsFunction\n    #\u003cUNDEF %V3%\u003e\n#\u003e\nWrite 'Text after the directive'\n'@ \u003e $File\n```\nThe following script transform the content:\n```Powershell\n[string[]]$Lines=Get-Content -Path $File  -ReadCount 0 -Encoding UTF8\n  #Edit-Template need an ARRAY of string\n$Result=,$Lines|Edit-Template -ConditionnalsKeyWord  \"V5\"|\n Edit-Template -Clean\n$Result\n```\nto :\n```Powershell\nWrite 'Text before the directive'\n\u003c#%ScriptBlock%\n\n        . .\\New-PSCustomObjectFunction.ps1\n        #PSCustomObject \u003e= v3\n        New-PSCustomObjectFunction -Noun ProcessLight -Parameters Name,VirtualMemorySize -File\n#\u003e\nWrite 'Text after the directive'\n```\nThe text between the directive \\#\u0026lt;DEFINE %V5%\u0026gt; and \\#\u0026lt;UNDEF %V5%\u0026gt; is deleted.\nThe parameter _*-Clean*_ remove the remaining directives inside the text.\n\nThe second step, invoke the script to generate text :\n```Powershell\n #Edit-String need a string\n$ofs=\"`r`n\"\n\"$Result\"|\n Edit-String -Setting  $TemplateDefaultSettings\n```\nThe final source code :\n```Powershell\nWrite 'Text before the directive'\nFunction New-ProcessLight{\nparam(\n         [Parameter(Mandatory=$True,position=0)]\n        $Name,\n         [Parameter(Mandatory=$True,position=1)]\n        $VirtualMemorySize\n)\n\n  [pscustomobject]@{\n    PSTypeName='ProcessLight';\n    Name=$Name;\n    VirtualMemorySize=$VirtualMemorySize;\n   }\n\n\n}# New-ProcessLight\nWrite 'Text after the directive'\n```\n\nWith this script :\n```Powershell\nGet-Content -Path $File  -ReadCount 0 -Encoding UTF8|\n Edit-Template -ConditionnalsKeyWord  \"V3\"|\n Edit-Template -Clean|\n Out-string|\n Edit-String -Hashtable $TemplateDefaultSettings\n```\nThe result text is :\n```Powershell\nWrite 'Text before the directive'\nclass ProcessLight\n{\n        [string] $Name;\n        [int] $VirtualMemorySize;\n\n        ProcessLight([System.Diagnostics.Process] $Process) {\n                $this.Name = $Process.Name\n                $this.VirtualMemorySize = $Process.VirtualMemorySize\n\n        }\n} #ProcessLight\nWrite 'Text after the directive'\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flaurentdardenne%2Ftemplate","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flaurentdardenne%2Ftemplate","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flaurentdardenne%2Ftemplate/lists"}