Pure nim implementation of template language originally presented in drunk snail
Uses standard library modules only
- Easy syntax
- Separates logic and data
- Compiled and statically typed yet memory safe
- Small codebase
- Allow for parser configuration
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>Download and import drunk_snail.nim into your project
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>"""Build drunk_snail.nim as main file and run, or call it's exported test and benchmark methods from another module