前回は諸々をインストールして、ブラウザに「Welcome from Eliom’s distillery!」と表示するところまでたどり着きました。
というわけで、「Welcome from Eliom’s distillery!」がどこで出力されているかを、まずは調べてみたいと思います。
作成された「hello」ディレクトリで適当にgrepすると、
バイナリファイル _server/hello.cmo に一致しました hello.eliom: h1 [pcdata "Welcome from Eliom's distillery!"]; バイナリファイル local/lib/hello/hello.cma に一致しました
こんな感じ。
バイナリファイルはとりあえず置いといて、hello.eliomですね。
ここで指定しているみたいです。
開いてみると。
[%%shared
open Eliom_lib
open Eliom_content
open Html.D
]
module Hello_app =
Eliom_registration.App (
struct
let application_name = “hello”
let global_data_path = None
end)
let main_service =
Eliom_service.create
~path:(Eliom_service.Path [])
~meth:(Eliom_service.Get Eliom_parameter.unit)
()
let () =
Hello_app.register
~service:main_service
(fun () () ->
Lwt.return
(Eliom_tools.F.html
~title:”hello”
~css:[[“css”;”hello.css”]]
Html.F.(body [
h1 [pcdata “Welcome from Eliom’s distillery!“];
])))
こんな感じです。最初の方はまだわからないが、後半で該当の文字列が見えます。
ここを変更すると反映されるのか?
上記、赤字部分を適当に変更してみます。
「Welcome from yonezos distillery」
テキスト編集して保存してブラウザを更新。
当然ですが、これだけでは反映はされません。当然、コンパイルが必要なんだろうなと。
前回は「make test.byte」とかやりましたが、今回はどうするのだろう?
とりあえず再度やってみますが、エラーが出ます。
$ make test.byte js_of_eliom -ppx -c -package lwt.ppx -package js_of_ocaml.ppx -package js_of_ocaml.deriving.ppx hello.eliom make: js_of_eliom: コマンドが見つかりませんでした Makefile:206: ターゲット '_client/hello.cmo' のレシピで失敗しました make: *** [_client/hello.cmo] エラー 127
師匠曰く「パスが通ってない?」との事で、.profileをチェック。
# OPAM configuration . /home/develop/.opam/opam-init/init.sh > /dev/null 2> /dev/null || true
上記記述があるか確認します。
で、記述があるのにダメな場合は
$ source .profile
で反映します。
で、再度make test.byteとやるもエラー。
$ make test.byte js_of_eliom -ppx -c -package lwt.ppx -package js_of_ocaml.ppx -package js_of_ocaml.deriving.ppx hello.eliom js_of_eliom -ppx -o local/var/www/hello/eliom/hello.js -package lwt.ppx -package js_of_ocaml.ppx -package js_of_ocaml.deriving.ppx \ _client/hello.cmo eliomc -ppx -c -package lwt.ppx -package js_of_ocaml.deriving.ppx hello.eliom eliomc -ppx -a -o local/lib/hello/hello.cma \ _server/hello.cmo ocsigenserver -c local/etc/hello/hello-test.conf ocsigenserver: ocsigen:main: Fatal - The port 8080 is already in use. Makefile:58: ターゲット 'test.byte' のレシピで失敗しました make: *** [test.byte] エラー 8
「ocsigensetverが8080掴んでて実行できないわ。」という感じなのでしょうか。
別コンソールで実行したままとなっていたocsigenserverをC-cで閉じます。
再度meke test.byteとやると、めでたく「Welcome from yonezos distillery!」と表示されました。
この「make test.byte」というコマンドですが、makeはコンパイルを行うとして「test.byte」って何?
makeでtabキーを押すと、続けて打てるオプションが出てきます。
$ make all install install.lib.byte local/ run.opt byte install.byte install.lib.opt opt test.byte clean install.etc install.opt print-install-files test.opt distclean install.lib install.static run.byte
大きくrunとtestがあって、開発時はtestですかね。
実行形式の違いだったかな…。
byteとoptはコンパイル方法が異なるみたいで、optの方が10倍ほど早いとの事。
いや、間違えてるかも知れない。
とりあえず、この辺は実際にサイトを公開する際にもう一度掘り下げるとしよう。