Scriban.Signed
5.12.0
Prefix Reserved
dotnet add package Scriban.Signed --version 5.12.0
NuGet\Install-Package Scriban.Signed -Version 5.12.0
<PackageReference Include="Scriban.Signed" Version="5.12.0" />
paket add Scriban.Signed --version 5.12.0
#r "nuget: Scriban.Signed, 5.12.0"
// Install Scriban.Signed as a Cake Addin #addin nuget:?package=Scriban.Signed&version=5.12.0 // Install Scriban.Signed as a Cake Tool #tool nuget:?package=Scriban.Signed&version=5.12.0
scriban
<img align="right" width="160px" height="160px" src="img/scriban.png">
Scriban is a fast, powerful, safe and lightweight scripting language and engine for .NET, which was primarily developed for text templating with a compatibility mode for parsing liquid
templates.
Today, not only Scriban can be used in text templating scenarios, but also can be integrated as a general scripting engine: For example, Scriban is at the core of the scripting engine for kalk, a command line calculator application for developers.
// Parse a scriban template
var template = Template.Parse("Hello {{name}}!");
var result = template.Render(new { Name = "World" }); // => "Hello World!"
Parse a Liquid template using the Liquid language:
// Parse a liquid template
var template = Template.ParseLiquid("Hello {{name}}!");
var result = template.Render(new { Name = "World" }); // => "Hello World!"
The language is very versatile, easy to read and use, similar to liquid templates:
var template = Template.Parse(@"
<ul id='products'>
{{ for product in products }}
<li>
<h2>{{ product.name }}</h2>
Price: {{ product.price }}
{{ product.description | string.truncate 15 }}
</li>
{{ end }}
</ul>
");
var result = template.Render(new { Products = this.ProductList });
Scriban can also be used in pure scripting context without templating ({{
and }}
) and can help you to create your own small DSL.
NOTICE
By default, Properties and methods of .NET objects are automatically exposed with lowercase and
_
names. It means that a property likeMyMethodIsNice
will be exposed asmy_method_is_nice
. This is the default convention, originally to match the behavior of liquid templates. If you want to change this behavior, you need to use aMemberRenamer
delegate
New in 3.0+
- AST is now fully visitable with
ScriptVisitor
. You can now accessParent
on anyScriptNode
object and navigate the AST.- Improve AST round-trip by preserving whitespaces around template enter
{{
and exit}}
- Improve AST round-trip by preserving whitespaces around template enter
- Several new language features:
- Hexadecimal/binary numbers:
0x1ef
or0b101010
- Support for large integers
- New parametric functions:
func sub(x,y = 1, z...); ret x - y - z[0]; end
- New inline functions:
sub(x,y) = x - y
- Optional member access with
?.
instead of regular.
(e.ga?.b?.c
) - Conditional expressions:
cond ? a : b
- Hexadecimal/binary numbers:
- Separate language mode (via
ScriptLang
enum) from template/scripting parsing mode (ScriptMode
). - New language parsing mode
Scientific
, in addition to default Scriban and Liquid language mode. - More fine-grained options on the
TemplateContext
to define scripting behaviors (EnableRelaxedTargetAccess
,EnableRelaxedMemberAccess
,EnableRelaxedFunctionAccess
,EnableRelaxedIndexerAccess
,EnableNullIndexer
) - New
object.eval
andobject.eval_template
function to evaluate Scriban expressions/templates at runtime. - Better support for
IFormattable
objects.
Features
- An extensible sandbox execution model: You have the full control about which Scripting objects (and so properties and methods) are accessible from Scriban templates.
- Very efficient, fast parser and a lightweight runtime. CPU and Garbage Collector friendly.
- Powered by a Lexer/Parser providing a full Abstract Syntax Tree, fast, versatile and robust, more efficient than regex based parsers.
- Precise source code location (path, column and line) for error reporting
- Write an AST to a script textual representation, with
Template.ToText
, allowing to manipulate scripts in memory and re-save them to the disk, useful for roundtrip script update scenarios
- Compatible with
liquid
by using theTemplate.ParseLiquid
method- While the
liquid
language is less powerful than scriban, this mode allows to migrate fromliquid
toscriban
language easily - With the AST to text mode, you can convert a
liquid
script to a scriban script usingTemplate.ToText
on a template parsed withTemplate.ParseLiquid
- As the liquid language is not strictly defined and there are in fact various versions of liquid syntax, there are restrictions while using liquid templates with scriban, see the document liquid support in scriban for more details.
- While the
- Extensible runtime providing many extensibility points
- Support for
async
/await
evaluation of scripts (e.gTemplate.RenderAsync
) - Precise control of whitespace text output
- Full featured language including
if
/else
/for
/while
, expressions (x = 1 + 2
), conditions... etc. - Function calls and pipes (
myvar | string.capitalize
)- Custom functions directly into the language via
func
statement and allow function pointers/delegates via thealias @ directive
- Bind .NET custom functions from the runtime API with many options for interfacing with .NET objects.
- Custom functions directly into the language via
- Complex objects (javascript/json like objects
x = {mymember: 1}
) and arrays (e.gx = [1,2,3,4]
) - Allow to pass a block of statements to a function, typically used by the
wrap
statement - Several built-in functions:
- Multi-line statements without having to embrace each line by
{{...}}
- Safe parser and safe runtime, allowing you to control what objects and functions are exposed
Syntax Coloring
You can install the Scriban Extension for Visual Studio Code to get syntax coloring for scriban scripts (without HTML) and scriban html files.
Documentation
- See the Language document for a description of the language syntax.
- See the Built-in functions document for the list of the built-in functions.
- See the Runtime document for a description of the .NET runtime API to compile and run templates.
- See the Liquid support document for more details about the support of liquid templates.
- See my blog post "Implementing a Text Templating Engine for .NET" for some behind the scene details.
Binaries
Scriban is available as a NuGet package:
Compatible with the following .NET Standard 2.0+ (New in 3.0)
For support for older framework (.NET 3.5, 4.0, 4.5, .NET Standard 1.1, 1.3, they are only provided in older Scriban 2.x, which is no longer supported.
Also the Scriban.Signed NuGet package provides signed assemblies.
Source Embedding
Starting with Scriban 3.2.1+, the package comes with source included so that you can internalize your usage of Scriban into your project. This can be useful in an environment where you can't easily consume NuGet references (e.g Roslyn Source Generators).
WARNING: Currently, the Scriban sources are not set as readonly, so you should not modify Scriban sources in that mode as it will modify the sources for other projects using Scriban on your machine. Use this feature at your own risks!
In order to activate this feature you need to:
- Set the property
PackageScribanIncludeSource
totrue
in your project:<PropertyGroup> <PackageScribanIncludeSource>true</PackageScribanIncludeSource> </PropertyGroup>
- Add the
IncludeAssets="Build"
to the NuGet PackageReference for Scriban:<ItemGroup> <PackageReference Include="Scriban" Version="3.2.1" IncludeAssets="Build"/> </ItemGroup>
If you are targeting netstandard2.0
or .NET Framework 4.7.2+
, in order to compile Scriban you will need these NuGet package references (that can come from a dependency that you already have):
<ItemGroup>
<PackageReference Include="Microsoft.CSharp" Version="4.5.0" />
<PackageReference Include="System.Threading.Tasks.Extensions" Version="4.5.0" />
</ItemGroup>
NOTE: In this mode, all Scriban types are marked as
internal
.You should see a Scriban folder and empty subfolders in your project. This is an issue with Visual Studio 2019 16.8.x (and before) and it will be fixed in VS 2019 16.9+
License
This software is released under the BSD-Clause 2 license.
Related projects
- dotliquid: .NET port of the liquid templating engine
- Fluid .NET liquid templating engine
- Nustache: Logic-less templates for .NET
- Handlebars.Net: .NET port of handlebars.js
- Textrude: UI and CLI tools to turn CSV/JSON/YAML models into code using Scriban templates
- NTypewriter: VS extension to turn C# code into documentation/TypeScript/anything using Scriban templates
Online Demo
- (https://scribanonline.azurewebsites.net/): ASP.NET Core Sample.
Sponsors
Supports this project with a monthly donation and help me continue improving it. [Become a sponsor]
<img src="https://github.com/lilith.png?size=200" width="64px;" style="border-radius: 50%" alt="lilith"/> Lilith River, author of Imageflow Server, an easy on-demand image editing, optimization, and delivery server
Credits
Adapted logo Puzzle
by Andrew Doane from the Noun Project
Author
Alexandre Mutel aka xoofx.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 is compatible. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- Microsoft.CSharp (>= 4.5.0)
- System.Threading.Tasks.Extensions (>= 4.5.0)
-
net7.0
- No dependencies.
NuGet packages (10)
Showing the top 5 NuGet packages that depend on Scriban.Signed:
Package | Downloads |
---|---|
WireMock.Net
Lightweight Http Mocking Server for .Net, inspired by WireMock from the Java landscape. |
|
NTypewriter
File/code generator from Scriban text templates populated with Roslyn C# code model |
|
Axuno.TextTemplating
Text templating is used to dynamically render contents based on a template and a model. * It is based on the Scriban library, so it supports conditional logics, loops and much more. * Template content can be localized. * You can define layout templates to be used as the layout while rendering other templates. * You can pass arbitrary objects to the template context (beside the model) for advanced scenarios. The library is a modified version of the lightweight TextTemplating.Scriban part of Volo.Abp.TextTemplating 7.0 (i.e., exluding the more heavy TextTemplating.Razor). |
|
NTypewriter.Runtime
App-independent engine used to run NTypewriter from UI |
|
essentialMix.Template
Common extensions methods, helper classes, components, nano systems, common patterns, and caching |
GitHub repositories (9)
Showing the top 5 popular GitHub repositories that depend on Scriban.Signed:
Repository | Stars |
---|---|
chocolatey/choco
Chocolatey - the package manager for Windows
|
|
npgsql/npgsql
Npgsql is the .NET data provider for PostgreSQL.
|
|
WireMock-Net/WireMock.Net
WireMock.Net is a flexible product for stubbing and mocking web HTTP responses using advanced request matching and response templating. Based on the functionality from http://WireMock.org, but extended with more functionality.
|
|
ErsatzTV/ErsatzTV
Stream custom live channels using your own media
|
|
microsoft/Oryx
Build your repo automatically.
|
Version | Downloads | Last updated |
---|---|---|
5.12.0 | 696 | 11/13/2024 |
5.11.0 | 2,116 | 11/1/2024 |
5.10.0 | 81,594 | 4/12/2024 |
5.9.1 | 51,771 | 1/9/2024 |
5.9.0 | 110,918 | 9/6/2023 |
5.8.0 | 2,451 | 9/1/2023 |
5.7.0 | 86,942 | 2/25/2023 |
5.6.0 | 31,908 | 2/3/2023 |
5.5.2 | 205,825 | 1/4/2023 |
5.5.1 | 11,687 | 11/18/2022 |
5.5.0 | 10,072,181 | 7/11/2022 |
5.4.6 | 18,775 | 5/29/2022 |
5.4.5 | 11,375 | 5/22/2022 |
5.4.4 | 8,298 | 4/9/2022 |
5.4.3 | 1,626 | 4/3/2022 |
5.4.2 | 1,492 | 3/31/2022 |
5.4.1 | 1,809 | 3/15/2022 |
5.4.0 | 9,027 | 2/6/2022 |
5.3.0 | 1,305 | 2/6/2022 |
5.2.0 | 1,767 | 2/6/2022 |
5.1.0 | 22,937 | 2/5/2022 |
5.0.0 | 83,692 | 10/20/2021 |
4.1.0 | 38,159 | 10/7/2021 |
4.0.2 | 2,520 | 9/22/2021 |
4.0.1 | 42,053 | 6/3/2021 |
4.0.0 | 1,044 | 6/2/2021 |
3.9.0 | 1,775 | 5/31/2021 |
3.8.2 | 1,461 | 5/27/2021 |
3.8.1 | 1,218 | 5/25/2021 |
3.8.0 | 1,195 | 5/25/2021 |
3.7.0 | 7,790 | 5/1/2021 |
3.6.0 | 6,439 | 3/20/2021 |
3.5.0 | 10,329 | 2/13/2021 |
3.4.2 | 1,341 | 2/1/2021 |
3.4.1 | 1,215 | 1/23/2021 |
3.4.0 | 1,127 | 1/21/2021 |
3.3.3 | 3,211 | 1/14/2021 |
3.3.2 | 5,028,640 | 12/30/2020 |
3.3.1 | 1,106 | 12/30/2020 |
3.3.0 | 1,109 | 12/29/2020 |
3.2.2 | 1,118 | 12/24/2020 |
3.2.1 | 1,144 | 12/22/2020 |
3.2.0 | 1,126 | 12/22/2020 |
3.1.0 | 1,085 | 12/21/2020 |
3.0.7 | 1,221 | 12/15/2020 |
3.0.6 | 1,164 | 12/6/2020 |
3.0.5 | 1,128 | 12/1/2020 |
3.0.4 | 1,139 | 11/30/2020 |
3.0.3 | 1,178 | 11/29/2020 |
3.0.2 | 1,326 | 11/23/2020 |
3.0.1 | 1,151 | 11/22/2020 |
3.0.0 | 1,200 | 11/15/2020 |
3.0.0-alpha.9 | 327 | 8/20/2020 |
3.0.0-alpha.8 | 312 | 8/7/2020 |
3.0.0-alpha.7 | 259 | 7/31/2020 |
3.0.0-alpha.6 | 289 | 7/31/2020 |
3.0.0-alpha.5 | 272 | 7/25/2020 |
3.0.0-alpha.4 | 339 | 7/25/2020 |
3.0.0-alpha.3 | 269 | 7/16/2020 |
3.0.0-alpha.2 | 276 | 7/6/2020 |
3.0.0-alpha.1 | 278 | 6/18/2020 |
2.1.4 | 648,351 | 8/16/2020 |
2.1.3 | 5,562 | 6/5/2020 |
2.1.2 | 31,020 | 3/8/2020 |
2.1.1 | 3,471 | 12/6/2019 |
2.1.0 | 19,049 | 6/30/2019 |
2.0.1 | 1,725 | 5/11/2019 |
2.0.0 | 2,051 | 3/8/2019 |
2.0.0-alpha-006 | 1,141 | 3/7/2019 |
2.0.0-alpha-005 | 1,303 | 1/15/2019 |
2.0.0-alpha-004 | 1,294 | 1/4/2019 |
2.0.0-alpha-003 | 1,272 | 1/3/2019 |
2.0.0-alpha-002 | 1,275 | 1/1/2019 |
2.0.0-alpha-001 | 1,224 | 12/28/2018 |
1.2.9 | 622,984 | 12/21/2018 |
1.2.8 | 1,412 | 12/17/2018 |
1.2.7 | 36,518 | 10/6/2018 |
1.2.6 | 1,580 | 9/26/2018 |
1.2.5 | 81,746 | 8/29/2018 |
1.2.4 | 1,477 | 8/21/2018 |
1.2.3 | 1,993 | 7/20/2018 |
1.2.2 | 1,709 | 7/3/2018 |
1.2.1 | 1,876 | 6/1/2018 |
1.2.0 | 2,099 | 2/10/2018 |
1.1.1 | 1,930 | 1/22/2018 |
1.1.0 | 1,716 | 1/22/2018 |
1.0.0 | 1,740 | 12/24/2017 |
1.0.0-beta-006 | 1,607 | 12/12/2017 |
1.0.0-beta-005 | 1,476 | 12/3/2017 |
1.0.0-beta-004 | 1,630 | 11/19/2017 |
1.0.0-beta-003 | 1,654 | 11/19/2017 |
1.0.0-beta-002 | 1,630 | 11/13/2017 |
1.0.0-beta-001 | 1,571 | 11/12/2017 |
0.16.0 | 1,896 | 11/12/2017 |
0.15.0 | 1,803 | 11/9/2017 |
0.14.0 | 1,819 | 11/7/2017 |
0.13.0 | 1,855 | 11/7/2017 |
0.12.1 | 1,786 | 11/6/2017 |
0.12.0 | 1,823 | 11/6/2017 |
0.11.0 | 1,827 | 11/4/2017 |
0.10.0 | 1,820 | 11/1/2017 |
0.9.1 | 1,798 | 10/27/2017 |
0.9.0 | 2,151 | 10/25/2017 |