Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/mentalblood0/drunk_snail.nim

Elegant template engine separating logic and data
https://github.com/mentalblood0/drunk_snail.nim

nim template-engine

Last synced: 26 days ago
JSON representation

Elegant template engine separating logic and data

Awesome Lists containing this project

README

        

🌪️ drunk snail

Pure [nim](https://nim-lang.org/) implementation of template language originally presented in [drunk snail](https://codeberg.org/mentalblood/drunk_snail)

Uses standard library modules only

## Why this language?

- Easy syntax
- Separates logic and data

## Why better then Python / C implementations?

- Compiled and statically typed yet memory safe
- Small codebase
- Allow for parser configuration

## Example

Row:

```html

```

Table:

```html

```

Arguments:

```json
{
"Row": [
{
"cell": ["1", "2"]
},
{
"cell": ["3", "4"]
}
]
}
```

Result:

```html


1
2


3
4

```

## Installation

Download and import [drunk_snail.nim](https://codeberg.org/mentalblood/drunk_snail.nim/src/branch/main/drunk_snail.nim) into your project

## Usage

```nim
import std/json
import std/tables
import std/unittest

import drunk_snail

check """

""".new_template.rendered(
%*{"Row": [{"cell": ["1.1", "2.1"]}, {"cell": ["1.2", "2.2"]}]},
{
"Row": """

""".new_template
}.to_table,
) == """

1.1
2.1


1.2
2.2

"""
```

## Testing/Benchmarking

Build [drunk_snail.nim](https://codeberg.org/mentalblood/drunk_snail.nim/src/branch/main/drunk_snail.nim) as main file and run, or call it's exported `test` and `benchmark` methods from another module