Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Laucans committed Jul 21, 2023
1 parent 9d42a47 commit 624ae4d
Show file tree
Hide file tree
Showing 20 changed files with 1,992 additions and 0 deletions.
15 changes: 15 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: "Build"
on:
push: {}

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/[email protected]
- name: Set-up OCaml 4.14.0
uses: ocaml/setup-ocaml@v2
with:
ocaml-compiler: 4.14.0
- run: opam install . --deps-only --with-test
- run: make
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
*~
_build
.merlin
*.install
_opam
.ligo
report.html
4 changes: 4 additions & 0 deletions .ocamlformat
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
version=0.25.1
profile=janestreet
let-binding-spacing=sparse
margin=90
32 changes: 32 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Frontend to dune.

.PHONY: default build install uninstall test clean fmt
.IGNORE: fmt

default: build

init:
opam switch list | grep ocaml-base-compiler.4.14.0 || opam switch create . ocaml-base-compiler.4.14.0 -y
eval $(opam env)

build:
opam exec -- dune build

test:
opam exec -- dune runtest -f

install:
opam exec -- dune install

uninstall:
opam exec -- dune uninstall

clean:
opam exec -- dune clean
# Optionally, remove all files/folders ignored by git as defined
# in .gitignore (-X).
git clean -dfXq

fmt:
opam exec -- dune build @fmt
opam exec -- dune promote
161 changes: 161 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
# ligo-mdx

## Goal
The project goal is to test ligo code contained in markdown file. For example it'll help to test your documentation or training through a CICD.

It'll generate a report file named report.html

## Try it

You can try now it by running :

```zsh
make && ./ligo-mdx/_build/default/src/bin/main.exe run ./examples/docs/tutorials/taco-shop/tezos-taco-shop-smart-contract.md ligo
```

It'll generate a report.html file.
## How to use

The script is able to read 3 keywords in header and the declared language.

Language can be jsligo, cameligo or zsh (in case of shell script)

- group : used to regroup multiple snippets, it'll also be used as a nameFile
- compilation : The way to test your code
- Interpret : Use `ligo interpret` to test your code
- Contract : Use `ligo compile contract` to test your code
- Test : Use `ligo run test` to test your code
- Command : Use directly command inside snippet
- None : Skip this snippet
- syntax: If the language does not match with the syntax, you can override the syntax with syntax attribute
- cameligo
- jsligo
- interpretation-type : interpretation-type=declaration
- Expression : Default value, nothing happen
- Declaration : When the snippet is interpreted, it'll be transformed to an expression, surrounding the code with `module ASFJNISFX = struct` and `end in ()`

## Examples

### Group snippets

(ommit \ which has been introduced to be able to insert markdown code)
```markdown

```jsligo group=taco-shop
type taco_supply is record [current_stock : nat; max_price : tez]

type taco_shop_storage is map (nat, taco_supply)

type return_ = [list <operation>, taco_shop_storage];

\```

blabla

```jsligo group=taco-shop compilation=contract
@entry
let buy_taco = (taco_kind_index: nat, taco_shop_storage: taco_shop_storage): return_ => {
/* Retrieve the taco_kind from the contracts storage or fail */
let taco_kind =
match (Map.find_opt (taco_kind_index, taco_shop_storage), {
Some: (k:taco_supply) => k,
None: (_:unit) => (failwith ("Unknown kind of taco") as taco_supply)
}) ;
}
\```
```

Will regroup and test snippets by running `ligo compile contract tmp/taco-shop.jsligo` on a temp file which is defined by
```jsligo
type taco_supply is record [current_stock : nat; max_price : tez]
type taco_shop_storage is map (nat, taco_supply)
type return_ = [list <operation>, taco_shop_storage];
@entry
let buy_taco = (taco_kind_index: nat, taco_shop_storage: taco_shop_storage): return_ => {
/* Retrieve the taco_kind from the contracts storage or fail */
let taco_kind =
match (Map.find_opt (taco_kind_index, taco_shop_storage), {
Some: (k:taco_supply) => k,
None: (_:unit) => (failwith ("Unknown kind of taco") as taco_supply)
}) ;
}
```

:warning: It's not file scopped so snippets can be included from different files. But currently snippet order is from top to down of a file, so it's hard to predict which one will be defined before. We will bring an "order" keyword to manage this case.

### Branch onto group

It's possible to branch on snippet, for example if you want to define step by step a function :

```markdown

```jsligo group=taco-shop;taco-shop2
type taco_supply is record [current_stock : nat; max_price : tez]

type taco_shop_storage is map (nat, taco_supply)

type return_ = [list <operation>, taco_shop_storage];

\```

blabla


```jsligo group=taco-shop compilation=contract
@entry
let buy_taco = (taco_kind_index: nat, taco_shop_storage: taco_shop_storage): return_ => {
[], taco_shop_storage
}
\```

blablablabla

```jsligo group=taco-shop2 compilation=contract
@entry
let buy_taco = (taco_kind_index: nat, taco_shop_storage: taco_shop_storage): return_ => {
/* Retrieve the taco_kind from the contracts storage or fail */
let taco_kind =
match (Map.find_opt (taco_kind_index, taco_shop_storage), {
Some: (k:taco_supply) => k,
None: (_:unit) => (failwith ("Unknown kind of taco") as taco_supply)
}) ;
}
\```
```

Will create two snippets named `taco-shop` and `taco-shop2` and test them using `ligo compile contract`

### Use shell command onto a snippet
Some time your documentation contains a bash command and you want to test it too, it's possible :

```
```jsligo group=contract/taco-shop
<your contract code here>
\```

blabla

```zsh group=contract/taco-shop compilation=command
ligo run dry-run contract/taco-shop.jsligo 4 3 --entry-point main
\```
```

### Build snippet with invisible code

Some time, your code is not compilable itself. You can add some code between `<!-- -->` and tag it with the correct group. For example :
```
<!--
```cameligo group=invisible-snippet
type taco_supply = { current_stock : nat ; max_price : tez }
type taco_shop_storage = (nat, taco_supply) map
\```
-->

```cameligo group=invisible-snippet compilation=interpret interpretation-type=declaration
type return = operation list * taco_shop_storage
\```
```
3 changes: 3 additions & 0 deletions dune-project
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
(lang dune 3.0)
(name ligo-mdx) ; optional
(version 0.1.0) ; optional
Loading

0 comments on commit 624ae4d

Please sign in to comment.