2 Star 1 Fork 0

Akini / scriban

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
BSD-2-Clause

scriban Build Status Coverage Status NuGet

Scriban is a fast, powerful, safe and lightweight text templating language and engine for .NET, with a compatibility mode for parsing liquid templates.

// 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 });

NOTICE

By default, Properties and methods of .NET objects are automatically exposed with lowercase and _ names. It means that a property like MyMethodIsNice will be exposed as my_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 a MemberRenamer delegate

Features

  • Very efficient, fast parser and a lightweight runtime. CPU and Garbage Collector friendly. Check the benchmarks for more details.
  • 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 the Template.ParseLiquid method
    • While the liquid language is less powerful than scriban, this mode allows to migrate from liquid to scriban language easily
    • With the AST to text mode, you can convert a liquid script to a scriban script using Template.ToText on a template parsed with Template.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.
  • Extensible runtime providing many extensibility points
  • Support for async/await evaluation of scripts (e.g Template.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)
  • Complex objects (javascript/json like objects x = {mymember: 1}) and arrays (e.g x = [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

Binaries

Scriban is available as a NuGet package: NuGet

Compatible with the following .NET framework profiles:

  • .NET Framework 3.5
  • .NET Framework 4.0
  • .NET Framework 4.5+ (supports asynchronous code and timeouts for regular expressions)
  • .NET Standard1.1+ (some features are not available)
  • .NET Standard1.3+ (which means .NET Core, Xamarin, UWP, Unity etc.)

Also the Scriban.Signed NuGet package provides signed assemblies.

Benchmarks

Scriban is blazing fast! For more details, you can check the benchmarks document.

License

This software is released under the BSD-Clause 2 license.

Related projects

Online Demo

Credits

Adapted logo Puzzle by Andrew Doane from the Noun Project

Author

Alexandre Mutel aka xoofx.

Copyright (c) 2016-2020, Alexandre Mutel All rights reserved. Redistribution and use in source and binary forms, with or without modification , are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

简介

暂无描述 展开 收起
BSD-2-Clause
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
1
https://gitee.com/Akini/scriban.git
git@gitee.com:Akini/scriban.git
Akini
scriban
scriban
master

搜索帮助