main »en »code »ecaml | source |
darcs get http://komar.in/darcs/ecaml/
.% ecaml --helpecaml - a simple template tool for OCamlUsage: ecaml [OPTIONS] template.eml -o FILE destination file to output an OCaml code; default is sourcename.ml -p STR printer function to apply to strings; default is print_string -esc-p STR function to apply to <%= %> parts but not to <%=raw %>; default is the same as -p -d write a directive with original file name for more impressive error messages -header STR header to write before the output -footer STR footer to write after the output -help Display this list of options --help Display this list of options
<% %>
are for code.%
in the beginning of line is for code too.<%= %>
are for “print this expression”; if-esc-p
is set — also escape string (useful for HTML).<%=raw %>
are also for “print this expression”, but do not escape anything inside even if-esc-p
is set.This tool is so stupid, so don't forget about;
at the end of your expressions!
I don't want to add any other features yet, because I want to keep this tool simple.
komar@thinkpad /home/komar/devel/ecaml % cat test.eml
<%= if Sys.os_type = "Unix" then "Hello world!" else "gtfo" %>% List.iter (fun s -><%= s %>% ) ["hello"; "from"; "list"];
komar@thinkpad /home/komar/devel/ecaml % ./ecaml test.eml
komar@thinkpad /home/komar/devel/ecaml % cat test.ml
print_string print_string print_string print_string print_stringos_type print_string print_stringiter s print_string print_string s print_string print_string print_string print_string
komar@thinkpad /home/komar/devel/ecaml % ocaml test.ml
Hello world!hellofromlist
Write something like:
% let f buf ~title ~content = (<%= title %><%= content %>% )
Then compile this template with-p 'Buffer.add_string buf'
:
komar@thinkpad /home/komar % ~/devel/ecaml/ecaml -p 'Buffer.add_string buf' site_template.eml
komar@thinkpad /home/komar % cat site_template.ml
f buf title contentadd_string bufadd_string bufadd_string bufadd_string bufadd_string buf titleadd_string bufadd_string bufadd_string bufadd_string bufadd_string buf contentadd_string bufadd_string bufadd_string buf
And now you can get the output with:
title content bufcreatef buf title contentcontents buf