drunk_snail.cr
drunk_snail
Pure crystal implementation of template language originally presented in drunk snail
Uses standard library only
Why this language?
- Easy syntax
- Separates logic and data
Why better then C / Python / Nim implementations?
- Compiled and statically typed yet memory safe
- Small codebase
- Allow for parser configuration
- Significantly (~x2) faster then Nim implementation
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
-
Add the dependency to your
shard.yml
:dependencies: drunk_snail: github: mentalblood0/drunk_snail.cr
-
Run
shards install
Usage
require "drunk_snail"
template = DrunkSnail::Template.new(
"<table>\n" \
" <!-- (ref)Row -->\n" \
"</table>"
)
params = {"Row" => [{"cell" => ["1", "2"]}, {"cell" => ["3", "4"]}]}
deps = {"Row" => DrunkSnail::Template.new(
"<tr>\n" \
" <td><!-- (param)cell --></td>\n" \
"</tr>"
)}
puts template.render params, deps
Testing
Inside cloned repository execute:
crystal spec
Benchmarking
Inside cloned repository execute:
crystal build drunk_snail_benchmark.cr --release
./drunk_snail_benchmark
Repository
drunk_snail.cr
Owner
Statistic
- 0
- 0
- 0
- 0
- 0
- 10 days ago
- March 11, 2025
License
MIT License
Links
Synced at
Sun, 30 Mar 2025 19:36:12 GMT
Languages