Blog Contribute

Interactive gists for the web

ocaml-gist is a tool to create interactive gist experiences for the web. It aims to be easy to use by both implementers and users.

No server required for compilation 🐫
Autocomplete support 🐫
Type info on hover 🐫

This is a gist with support for the OCaml standard library.

(* change me *) let rec fib n = if n = 0 then 0 else if n = 1 then 1 else fib (n - 1) + fib (n - 2) let example = fib 20

Requirements

OCaml 4.04.2

A recent Node and NPM version

Installation

opam install ocaml-gist

Btw. we'd love to know if you are using ocaml-gist.

Usage

jbuilder

This is an example of a create-gist rule for jbuilder that invokes the og-create command. The resulting gist has support for the OCaml stdlib and Base library. It also has a dependency on a local foo library.

(alias (
  (name create-gist)
  (deps (foo.cma))
  (action (progn
    (run og-create
         --input input_base
         --output output_base
         --dependency foo.cma
         --lib stdlib
         --lib +base/runtime.js
         --lib base
         --doc
    )
  ))
))
      
The used arguments have the following meaning:

Once a gist is created you need to start a server that serves the output directory.

To use the gist tool in your website, just copy the files needed around. Keep in mind that the output directory will be generated again on the next run.

Command line

This is an example of using the og-create command directly to create a gist experience that supports LWT.

      og-create
         --input input_lwt
         --output output_lwt
         --dependency foo.cma
         --lib stdlib
         --lib result
         --lib lwt
         --lib js_of_ocaml-lwt
         --lib js_of_ocaml
    

Limitations

Contribute

Contributions are very welcome