Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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
- Host: GitHub
- URL: https://github.com/mentalblood0/drunk_snail.nim
- Owner: mentalblood0
- Created: 2024-10-17T19:52:37.000Z (4 months ago)
- Default Branch: main
- Last Pushed: 2024-10-17T20:06:57.000Z (4 months ago)
- Last Synced: 2024-11-11T19:09:19.004Z (3 months ago)
- Topics: nim, template-engine
- Language: Nim
- Homepage:
- Size: 297 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
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/unittestimport 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