Upload
ngoc-dao
View
1.810
Download
1
Embed Size (px)
DESCRIPTION
Introduction about "Erlang Web" framework
Citation preview
Erlang Web
Erlangのウェブフレームワーク
ダオ ゴック タン2009/4/15
特徴• 設定:多い(設定ファイル + ソースコードでの設定)• URL-controllerマッピングが自由に設定できるし、正規表現により URL成分をパラメータにすることもできる
• データフロー:リクエストからリスポンスまでの関数呼び 出し流れが設定で きる( Railsの before_filterと after_filterと
同じ)• DB wrapperがあるがMnesiaと CouchDBしかサポートしていない
• テンプレート:作りにくい、使いにくい、 XML• I18nがある• リクエスト処理流れが Nitrogenのと大体同じ• Nitrogen より完成度(機能、資料)が少し高い
ClientClient
YawsYaws
out/1out/1
Controllershop:list/0
% URL, Method, Cookieなどは dictionaryかget% Status, Headerなどは dictionaryに putItems = shop:all(),wpart:fset(“items”, Items), % dictionaryにput{template, "list.html”}.
Controllershop:list/0
% URL, Method, Cookieなどは dictionaryかget% Status, Headerなどは dictionaryに putItems = shop:all(),wpart:fset(“items”, Items), % dictionaryにput{template, "list.html”}.
Modelshop:all/0
Modelshop:all/0
DBDB
テンプレート (View)list.html
<wpart:list select="map" list="items" as="item"> <li><wpart:shop /></li></wpart:list>
テンプレート (View)list.html
<wpart:list select="map" list="items" as="item"> <li><wpart:shop /></li></wpart:list>
(3)dispatch.confを参照し•ステーティックファイルを返すか•テンプレートを直接にまたは•controllerを呼ぶ
URL, Method, Cookieなどをプロセスの dictionaryにput
(1)(HTTP) http://server/app/shop/list
(2)1つのプロセスを spawnURL, Method, Cookieなどを Argにセットout(Arg)を呼び出す
wpart (View Helper)wpart_shop:handle_call/1
Item = wpart:fget(“item”), % dictionaryから get… % Itemを XMLに変換
wpart (View Helper)wpart_shop:handle_call/1
Item = wpart:fget(“item”), % dictionaryから get… % Itemを XMLに変換
(5)
(6)
(7)list.htmldictionary
(8)(10)XML
(12)dictionaryからgetし、リスポンスを作りYawsに返す[{html, Html}{status, Status}…]
(13)(HTTP)HTMLStatusCookie…
dispatch.confdispatch.conf
(4c)shop:list/0を呼び出す
(9)
テンプレート
テンプレート
ステーティックファイル
ステーティックファイル
(4a) (4b)
テンプレートエンジンテンプレートエンジン
(11)HTML
(3) dispatch.conf
• URL-controllerマッピングを設定• 正規表現により URL成分をパラメータにすることもできる
• HTTPメソッドの認識はできていない(Railsの routes.rbのような RESTfulマッピング機能はまだない )
(6) e_dbモジュル
• DB wrapper• Mnesiaと CouchDBしかサポートしていない• write(Domain, Element)• read(Domain)• read(Domain, Id)• update(Domain, Element)• size(Domain)• delete(Domain, Element)• get_next_id(Domain)
(9) wpart
• データをテンプレートによって XMLに変換
wpart (View Helper)wpart_shop:handle_call/1
handle_call(_XML) -> % dictionaryから get Item = wpart:fget("item"), % Itemを XMLに変換 #xmlText{value = create_item_desc(Item), type = cdata}.
create_item_desc(Item) -> Skeleton = wpart_gen:tpl_get(shop, item_short), wpart_gen:build_html(Skeleton, [ Item#item.title, integer_to_list(Item#item.quantity), integer_to_list(Item#item.prize)]).
wpart (View Helper)wpart_shop:handle_call/1
handle_call(_XML) -> % dictionaryから get Item = wpart:fget("item"), % Itemを XMLに変換 #xmlText{value = create_item_desc(Item), type = cdata}.
create_item_desc(Item) -> Skeleton = wpart_gen:tpl_get(shop, item_short), wpart_gen:build_html(Skeleton, [ Item#item.title, integer_to_list(Item#item.quantity), integer_to_list(Item#item.prize)]).
<h3><% slot %></h3><i>Quantity: <% slot %></i><br/><b>Prize: <% slot %></b>
<h3><% slot %></h3><i>Quantity: <% slot %></i><br/><b>Prize: <% slot %></b>
参考
• Presentation at the 14th International Erlang/OTP User Conference 2008, Stockholm, Sweden:http://www.erlang-consulting.com/euc2008/euc08_erlang_web_slides.pdf
• Presentation at the 2008 Erlang eXchange, London UK:http://www.erlang-web.org/doc/ErlangWeb.pdf
• マニュアル :http://www.erlang-web.org/doc/tutorial.pdf