指定されたパラメーターとマップに従って HTML を生成するサービスを作成したいと考えています。パラメータを指定すると、サービスはマップ内で html を検索し、クライアント側で起動する関数を検索します。
type sample =
(string (* little text *)*
Html5_types.html Eliom_content.Html5.elt (* html page *) *
(unit -> unit)(* Demonstration function *))
関数がクライアント側で起動されることを考えると、クライアント値としてマップに挿入します。
{client{
let demo_function = ignore (Ojquery.add_html
(Ojquery.jQ "li") "<p id='test1'>new paragraph</p>") }}
let get_samples () =
let samples_map = Samples.empty in
let samples_map = Samples.add "add_html"
("text",
(Eliom_tools.F.html
(** html stuff **)
),
{unit->unit{demo_function}}) samples_map in
samples_map
そして、次のようにサービスを登録します。
let sample_service =
Eliom_service.service
~path:["examples"]
~get_params:Eliom_parameter.(string "entry")
()
let () =
Examples_app.register
~service:sample_service
(fun (entry) () ->
try
(let entry = Samples.find entry samples_map in
let html = ((function (name, html, func) -> html) entry) in
let func = ((function (name, html, func) -> func) entry) in
ignore {unit{%func ()}};
Lwt.return (html))
with Not_found -> Lwt.return (not_found)
)
コードの残りの部分は、使用されているクライアント関数の ojquery パッケージを含めた、古典的な eliom-distillery の結果にすぎません。コンパイル フェーズはスムーズに進みますが、サーバーを起動しようとすると、次のエラー メッセージが表示されます。
ocsigenserver: main: Fatal - Error in configuration file: Error while parsing configuration file: Eliom: while loading local/lib/examples/examples.cma: Failure("That function cannot be called here because it needs information about the request or the site.")
私の最初の推測では、サービスの外部にクライアントの値を保存しているという事実が原因であるということでしたが、この種の値をサーバーに保存する方法はありますか?
私は通常の関数でそれらをラップしようとしました:
let demo_serv_func () = {unit{demo_client_func ()}}
しかし、問題は残りました...