[ANN] Embedded Ocaml Templates 0.8

I am quite happy to announce the release of EML 0.8.
EML is a simple templating language that lets you generate text with plain OCaml. It is analogous to the way you would write PHP pages, but the language being Ocaml instead.

There are two ways of using it, the first one is in a standalone file, for instance resume.eml.tex :

<%# firstname lastname email birthdate phonenumber formations %>
\documentclass[10pt, a4paper, roman, french]{moderncv}
\usepackage{babel}
\firstname{ <%-firstname%> }
\familyname{ <%-lastname%> }
\mobile{<%- phonenumber%>}
\extrainfo{Born <%-birthdate%> }
\email{ <%-email%> }
\begin{document}
	\makecvtitle
	\section{Formation}
	 <% List.iteri (fun i (date_start, date_end, diploma, school) ->%>
		\cventry{ <%i- i %> <%-date_start%> -- <%-date_end%>}{<%-diploma%>}{<%-school%>}{}{}{}
	 <%) formations ;%>
\end{document}

There is also support for compiling a whole recursive directory of templating files with a single dune rule.

The other one would be in OCaml code with a PPX :

let resume  firstname lastname email birthdate phonenumber formations =
  {%eml|
\documentclass[10pt, a4paper, roman, french]{moderncv}
\usepackage{babel}
\firstname{ <%-firstname%> }
\familyname{ <%-lastname%> }
\mobile{<%- phonenumber%>}
\extrainfo{Born <%-birthdate%> }
\email{ <%-email%> }
\begin{document}
	\makecvtitle
	\section{Formation}
	 <% List.iteri (fun i (date_start, date_end, diploma, school) ->%>
		\cventry{ <%i- i %> <%-date_start%> -- <%-date_end%>}{<%-diploma%>}{<%-school%>}{}{}{}
	 <% ) formations ;%>
\end{document}
|}

The ppx is also suitable for simple string interpolation.

A similar templating and homonymous templating engine is present in the Dream framework. Dream.EML has a slightly different syntax, mine is less geared toward HTML and more suitable for general templating. Dream also does not support compiling multiple templates with a single dune rule.

In 0.8, the locations in the PPX are finally correct. This means that type errors will show up in their correct place, which is very nice (once a small bugfix in merlin is merged (the error message is still correct)).
I also got rid of a depency on Menhir.

It is available on opam as the embedded_ocaml_templates package, and the doc is here

17 Likes