- Rust 98.6%
- Nix 1.4%
|
|
||
|---|---|---|
| benches | ||
| fuzz | ||
| src | ||
| tests | ||
| .envrc | ||
| .gitignore | ||
| Cargo.lock | ||
| Cargo.toml | ||
| clippy.toml | ||
| flake.lock | ||
| flake.nix | ||
| README.md | ||
| rust-toolchain.toml | ||
| rustfmt.toml | ||
Nomo, a simple templating library
Nomo is pure Rust templating library meant to be unopinionated in which target language it is embedded.
Here is an example nomo HTML snippet:
<div id="notifications">
<ul>
{{ for notif in notifications }}
<li class="notification-{{= notif.level }}">{{= notif.text }}</li>
{{ end }}
</ul>
</div>
It supports the following features:
If/Else Conditionals
{{ if user.level > 3 }}
...
{{ else if value == 1 }}
...
{{ else }}
...
{{ end }}
For Loops
{{ for user in users }}
{{= user.name }}
{{ end }}
Whitespace Supression
Hello
{{- if world == 2 -}}
Hi
{{- end }}
will print Hello Hi.
Function Calls
{{= uppercase(user_name) }}
One can use function chaining for less nesting:
{{= user_name | uppercase() }}
The | operator has the lowest precedence of the operators.
Functions can still be given arguments. It is always the last argument that is
'applied' by the operator.
{{= username? | or_default("Unknown") }}
Undefined Chaining
Per default, trying to access a value that is not defined will cause an error.
This can be changed with the ? operator. This can be applied at any level:
{{= user?.profile.description? }}
This will give an error if user.profile is not defined. If either user or
description is missing, it simply does not render anything (akin to an empty
string). However if there is an user, it must have a profile value.
Inline Expressions Construction
One can construct array and objects directly in nomo if needed.
{{ for name in ["Hemera", "Neikos", "Nomo"] -}}
- Hello {{= name}}!
{{ end }}
{{= { name: "Hemera", species: "Snow Leopard" }.name }}
Objects can also be easily constructed with an implicit name:
If the variable name has been set before, then one can construct this object without having to repeat it.
{{= { name }.name }}
Include other files
{{= render "foo", scope() }}
{{= render "foo", { name, message: "You are authorized." } }}
To include a file one uses the include builtin. Per default, includes do not
propagate their scope. One can either pass in a custom scope by passing in an
object, or marking it as unscoped.
Render pieces inline to re-use in other templates
{{ define "content" }}
This is the main content
{{ end }}
{{= render "base", { content } }}