Skip to content
This repository was archived by the owner on Mar 3, 2026. It is now read-only.

mentalblood0/drunk_snail.nim

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

44 Commits
 
 
 
 
 
 

Repository files navigation

🌪️ drunk snail

Pure nim implementation of template language originally presented in 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:

<tr>
  <td><!-- (param)cell --></td>
</tr>

Table:

<table>
  <!-- (ref)Row -->
</table>

Arguments:

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

Result:

<table>
  <tr>
    <td>1</td>
    <td>2</td>
  </tr>
  <tr>
    <td>3</td>
    <td>4</td>
  </tr>
</table>

Installation

Download and import drunk_snail.nim into your project

Usage

import std/json
import std/tables
import std/unittest

import drunk_snail

check """<table>
    <!-- (ref)Row -->
</table>""".new_template.rendered(
    %*{"Row": [{"cell": ["1.1", "2.1"]}, {"cell": ["1.2", "2.2"]}]},
    {
      "Row": """<tr>
    <td><!-- (param)cell --></td>
</tr>""".new_template
    }.to_table,
) == """<table>
    <tr>
        <td>1.1</td>
        <td>2.1</td>
    </tr>
    <tr>
        <td>1.2</td>
        <td>2.2</td>
    </tr>
</table>"""

Testing/Benchmarking

Build drunk_snail.nim as main file and run, or call it's exported test and benchmark methods from another module

About

Elegant template engine separating logic and data

Topics

Resources

Stars

Watchers

Forks

Contributors

Languages