Movatterモバイル変換


[0]ホーム

URL:


main »en »code »ecamlsource

ECaml — a simple template engine for OCaml

ECaml logo

Download

Usage

% 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

Syntax

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.

Example

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

And how to use this stuff withocsigen?

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

See also


[8]ページ先頭

©2009-2025 Movatter.jp