TextScript!
Text templating with .NET comfort
This project is a fork over Scriban
TextScript is a text templating engine. Designed to be powerful yet easy to learn, TextScript aims to provide the same functionality of liquid and more. TextScript is written entirely in .NET, so there's absolutely no need for ruby, python or a boatload of NodeJS npms!
TextScript is initially forked from Scriban in late 2018, and the code base has diverged since. Some primary differences are:
You can read more about a list of differences here.
How about some good old templating done right inside PowerShell?
ipmo TextScript
@{ name = 'Partner' } | ConvertFrom-Template -Template 'Howdy {{ name }}!'
# Howdy Partner!
Same thing in C#:
// Parse a template
var template = Template.Parse("Hello {{name}}!");
var result = template.Render(new { Name = "World" }); // => "Hello World!"
TextScript borrows from the very popular liquid, which you are encouraged to look at too. In most of the cases, there is no difference at all:
ipmo TextScript
@{
food = @(
{ name = 'cabbage'; price = '$10'; fullDesc = "Fresh and green" }
{ name = 'banana'; price = '$5'; fullDesc = "Minion's favorite" }
{ name = 'beef'; price = '$50'; fullDesc = "Meatlovers delight"}
)
} | ConvertFrom-Template @'
<ul id='cart'>
{{ for item in food }}
<li>
<h2>{{ item.name }}</h2>
Price: {{ item.price }}
{{ item.full_desc | string.truncate 15 }}
</li>
{{ end }}
</ul>
'@
Template.ToText
. You can manipulate templates in memory and re-save them to disk, which is handy for roundtrip script update scenariosliquid
compatibility mode with the Template.ParseLiquid
method:
liquid
language is less powerful, we know migrating existing code can be a chore. This mode allows for a drop-in replacement for your existing liquid
templates.liquid
template to TextScript automatically (by using Template.ParseLiquid
, then Template.ToText
)
Extensible runtime providing many extensibility pointsif
/else
, for
, and while
, expressions (x = 1 + 2
), conditions... etc.myvar | string.capitalize
func
statement. alias @ directive
x = {mymember: 1}
x = [1,2,3,4]
wrap
statement{{...}}
Go to the documentation page to get started.
Prebuilt binaries are available in the release tab.
To integrate TextScript in your .NET project, reference our NuGet package in your packages.config
or project file:
TextScript can run on the following platforms:
.NET 4.6.2
NetStandard1.3
To install our PowerShell cmdlet:
Install-Package TextScript
Platform specific implementations for PowerShell:
.NET 4.6.2
NETStandard 1.6
NETStandard 2.0
We aim for real-time rendering! Compete results are updated in our benchmarks document.
See the LICENSE file for licensing information.
We take inspirations from the following repos. For third party licensing info, refer to the third party license file.