Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/johnridesabike/acutis

A declarative, type-safe template language
https://github.com/johnridesabike/acutis

compiler eleventy handlebars mustache nunjucks ocaml template-engine template-language

Last synced: 2 months ago
JSON representation

A declarative, type-safe template language

Awesome Lists containing this project

README

        

Acutis icon.

## Acutis language

Acutis is a template language that features static typing, pattern matching, and
asynchronous template components. You can execute your templates like scripts or
compile them to self-contained JavaScript files.

Acutis is an experimental, personal project and is not stable.

```acutis
{% interface
siteTitle = string
blogPosts =
[
{
title: string,
author: {name: ?string},
date: string,
image: ?{alt: string, src: string},
content: string
}
]
~%}

Blog posts for {% siteTitle %}


{%~ map blogPosts with {image, title, content, date, author: {name}} %}


{% match image with null ~%}
{* no image *}
{%~ with !{src, alt} ~%}
{% alt %}
{% /match ~%}

{% title %}


By {% name ? "Anonymous" %}
Posted on {% date %}

{{% content %}}


{%~ /map %}
```

[See how this example compiles in the playground][example].

[example]:
https://johnridesa.bike/acutis/playground/?props=ewogICJzaXRlVGl0bGUiOiAiTXkgQmxvZyIsCiAgImJsb2dQb3N0cyI6IFsKICAgIHsKICAgICAgInRpdGxlIjogIk15IHNlY29uZCBwb3N0IiwKICAgICAgImF1dGhvciI6IHsgIm5hbWUiOiAiSm9obiIgfSwKICAgICAgImRhdGUiOiAiMjAyMC0xMi0wMSIsCiAgICAgICJpbWFnZSI6IG51bGwsCiAgICAgICJjb250ZW50IjogIjxwPlRoaXMgaXMgbXkgc2Vjb25kIHBvc3Q8L3A%2BIgogICAgfSwKICAgIHsKICAgICAgInRpdGxlIjogIkhlbGxvLCB3b3JsZCEiLAogICAgICAiYXV0aG9yIjogeyAibmFtZSI6ICJKb2huIiB9LAogICAgICAiZGF0ZSI6ICIyMDIwLTExLTMwIiwKICAgICAgImltYWdlIjogbnVsbCwKICAgICAgImNvbnRlbnQiOiAiPHA%2BVGhpcyBpcyBteSBmaXJzdCBwb3N0PC9wPiIKICAgIH0KIC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bGU%2BCnslfiAvbWFwICV9
[Read the documentation here](https://johnridesa.bike/acutis/).

## Usage in OCaml

The Acutis source is written in OCaml. You can install it with the OCaml package
manager, OPAM.

```shell
opam pin https://github.com/johnridesabike/acutis.git
```

## JavaScript & Eleventy plugin

You can use npm to install a JavaScript build of Acutis. This includes an
[Eleventy] plugin.

[eleventy]: https://www.11ty.dev/

Install the JavaScript package in your project:

```shell
npm install acutis-lang
```

Import the package in your Eleventy-powered site:

```javascript
const acutis = require("acutis-lang");
const acutisEleventy = require("acutis-lang/eleventy");
```

## Development

Clone this repository with git. Then create a development OPAM switch:

```shell
opam switch create . --deps-only --with-test --with-doc
```

Compile the code:

```shell
dune build
```

Run tests:

```shell
dune runtest
```

## License

Copyright (c) 2022 John Jackson.

This Source Code Form is subject to the terms of the Mozilla Public
License, v. 2.0. If a copy of the MPL was not distributed with this
file, You can obtain one at http://mozilla.org/MPL/2.0/.