Namdak Tonpa 9 years ago
parent
commit
e8b6cb9bb7

+ 1 - 1
include/mad.hrl

@@ -1 +1 @@
--define(VERSION,"1162ab").
+-define(VERSION,"a119fd").

BIN
mad


+ 0 - 1
priv/web/apps/sample/priv/static/spa/index.htm

@@ -10,7 +10,6 @@
 
     <script> var transition = {pid: '', port: window.location.port };</script>
     <script src='/n2o/protocols/bert.js'></script>
-    <script src='/n2o/protocols/binary.js'></script>
     <script src='/n2o/protocols/client.js'></script>
     <script src='/n2o/protocols/nitrogen.js'></script>
     <script src='/n2o/validation.js'></script>

+ 1 - 2
priv/web/apps/sample/priv/templates/index.html

@@ -8,7 +8,6 @@
 {{body}}
 <script>{{script}}</script>
     <script src='/n2o/protocols/bert.js'></script>
-    <script src='/n2o/protocols/binary.js'></script>
     <script src='/n2o/protocols/client.js'></script>
     <script src='/n2o/protocols/nitrogen.js'></script>
     <script src='/n2o/validation.js'></script>
@@ -16,6 +15,6 @@
     <script src='/n2o/utf8.js'></script>
     <script src='/n2o/template.js'></script>
     <script src='/n2o/n2o.js'></script>
-<script>protos = [ $bert, $client ]; N2O_start();</script><div id="n2ostatus"></div>
+<script>protos = [ $bert, $client ]; N2O_start();</script>
 </body>
 </html>

+ 6 - 5
priv/web/apps/sample/src/index.erl

@@ -1,15 +1,16 @@
 -module(index).
 -compile(export_all).
--include_lib("nitro/include/nitro.hrl").
 -include_lib("n2o/include/wf.hrl").
+-include_lib("nitro/include/nitro.hrl").
 
-peer()    -> io_lib:format("~p",[wf:peer(?REQ)]).
-message() -> wf:js_escape(wf:html_encode(wf:ql(message))).
-main()    -> #dtl{file="index",app=n2o_sample,bindings=[{body,body()}]}.
+peer()    -> wf:to_list(wf:peer(?REQ)).
+message() -> wf:info("wf:q: ~p~n",[wf:q(message)]),
+             wf:js_escape(wf:html_encode(wf:to_list(wf:q(message)))).
+main()    -> #dtl{file="index",app=sample,bindings=[{body,body()}]}.
 body()    -> [ #panel{id=history}, #textbox{id=message},
                #button{id=send,body="Chat",postback=chat,source=[message]} ].
 
 event(init) -> wf:reg(room);
 event(chat) -> wf:send(room,{client,{peer(),message()}});
-event({client,{Peer,Message}}) -> wf:insert_bottom(history,#panel{id=history,body=[Peer,": ",Message,#br{}]});
+event({client,{P,M}}) -> wf:insert_bottom(history,#panel{id=history,body=[P,": ",M,#br{}]});
 event(Event) -> wf:info(?MODULE,"Unknown Event: ~p~n",[Event]).

+ 10 - 9
priv/web/apps/sample/src/routes.erl

@@ -5,15 +5,16 @@
 finish(State, Ctx) -> {ok, State, Ctx}.
 init(State, Ctx) ->
     Path = wf:path(Ctx#cx.req),
+    Module = prefix(Path),
     wf:info(?MODULE,"Route: ~p~n",[Path]),
-    {ok, State, Ctx#cx{path=Path,module=route_prefix(Path)}}.
+    {ok, State, Ctx#cx{path=Path,module=Module}}.
 
-route_prefix(<<"/ws/",P/binary>>) -> route(P);
-route_prefix(<<"/",P/binary>>) -> route(P);
-route_prefix(P) -> route(P).
+prefix(<<"/ws/",P/binary>>) -> route(P);
+prefix(<<"/",P/binary>>)    -> route(P);
+prefix(P)                   -> route(P).
 
-route(<<>>)              -> index;
-route(<<"index">>)       -> index;
-route(<<"favicon.ico">>) -> static_file;
-route(<<"static/spa/index.htm">>) -> index;
-route(_) -> index.
+route(<<>>)                 -> index;
+route(<<"index">>)          -> index;
+route(<<"favicon.ico">>)    -> index;
+route(<<"static/spa/index",_/binary>>) -> index;
+route(_)                    -> index.

+ 6 - 8
priv/web/apps/sample/src/sample.app.src

@@ -1,9 +1,7 @@
 {application, sample,
- [
-  {description, "N2O Sample"},
-  {vsn, "1"},
-  {registered, []},
-  {applications, [kernel, stdlib, n2o]},
-  {mod, { web_app, []}},
-  {env, []}
- ]}.
+  [{description, "N2O Sample"},
+   {vsn, "1"},
+   {registered, []},
+   {applications, [kernel, stdlib, n2o]},
+   {mod, { sample, []}},
+   {env, []} ]}.

+ 26 - 0
priv/web/apps/sample/src/sample.erl

@@ -0,0 +1,26 @@
+-module(sample).
+-behaviour(supervisor).
+-behaviour(application).
+-export([init/1, start/2, stop/1, main/1]).
+-compile(export_all).
+
+main(A)    -> mad:main(A).
+start(_,_) -> supervisor:start_link({local,sample},sample,[]).
+stop(_)    -> ok.
+init([])   -> case cowboy:start_http(http,3,port(),env()) of
+                   {ok, _}   -> ok;
+                   {error,_} -> halt(abort,[]) end,
+                   {ok, {{one_for_one, 5, 10}, []}}.
+
+env()    -> [ { env, [ { dispatch, points() } ] } ].
+static() ->   { dir, "apps/sample/priv/static", mime() }.
+n2o()    ->   { dir, "deps/n2o/priv",           mime() }.
+mime()   -> [ { mimetypes, cow_mimetypes, all   } ].
+port()   -> [ { port, wf:config(n2o,port,8001)  } ].
+points() -> cowboy_router:compile([{'_', [
+              { "/static/[...]", n2o_static, static() },
+              { "/n2o/[...]",    n2o_static, n2o()    },
+              { "/ws/[...]",     n2o_stream, []       },
+              { '_',             n2o_cowboy, []       } ]}]).
+
+log_modules() -> [n2o_client,n2o_nitrogen,n2o_stream,wf_convert].

+ 0 - 10
priv/web/apps/sample/src/web_app.erl

@@ -1,10 +0,0 @@
--module(web_app).
--behaviour(application).
--export([start/0, start/2, stop/1, main/1, log_modules/0]).
-
-main(A) -> mad_repl:main(A,[]).
-start() -> start(normal, []).
-start(_StartType, _StartArgs) -> web_sup:start_link().
-stop(_State) -> ok.
-
-log_modules() -> [n2o_websocket,n2o_client,n2o_heart,n2o_nitrogen,bullet_handler].

+ 0 - 17
priv/web/apps/sample/src/web_sup.erl

@@ -1,17 +0,0 @@
--module(web_sup).
--behaviour(supervisor).
--export([start_link/0, init/1]).
-
-start_link() -> supervisor:start_link({local, ?MODULE}, ?MODULE, []).
-mime() -> [{mimetypes,cow_mimetypes,all}].
-rules() -> cowboy_router:compile(
-    [{'_', [
-        {"/static/[...]", n2o_dynalo, {dir, "apps/sample/priv/static", mime()}},
-        {"/n2o/[...]", n2o_dynalo, {dir, "deps/n2o/priv", mime()}},
-        {"/ws/[...]", bullet_handler, [{handler, n2o_bullet}]},
-        {'_', n2o_cowboy, []}
-    ]}]).
-
-init([]) ->
-    cowboy:start_http(http, 3, [{port, wf:config(n2o,port)}], [{env, [{dispatch, rules()}]}]),
-    {ok, {{one_for_one, 5, 10}, []}}.

+ 1 - 1
priv/web/rebar.config

@@ -4,9 +4,9 @@
     {erlydtl,".*", {git, "git://github.com/evanmiller/erlydtl", {tag, "0.8.0"}  }},
     {cowboy, ".*", {git, "git://github.com/extend/cowboy",      {tag, "1.0.1"}  }},
     {gproc,  ".*", {git, "git://github.com/uwiger/gproc.git",   {tag, "0.3"}    }},
-    {mad,    ".*", {git, "git://github.com/synrc/mad",          {tag, "master"} }},
     {fs,     ".*", {git, "git://github.com/synrc/fs",           {tag, "0.8"}    }},
     {sh,     ".*", {git, "git://github.com/synrc/sh",           {tag, "0.8"}    }},
+    {mad,    ".*", {git, "git://github.com/synrc/mad",          {tag, "master"} }},
     {active, ".*", {git, "git://github.com/synrc/active",       {tag, "master"} }},
     {nitro,  ".*", {git, "git://github.com/synrc/nitro",        {tag, "master"} }},
     {n2o,    ".*", {git, "git://github.com/synrc/n2o",          {tag, "master"} }}

+ 1 - 4
priv/web/sys.config

@@ -1,4 +1 @@
-[
- {n2o, [{port,8001},{route,routes},{log_modules,web_app}]},
- {kvs, [{dba,store_mnesia}, {schema, [kvs_user, kvs_acl, kvs_feed, kvs_subscription ]} ]}
-].
+[{n2o, [{port,8001},{route,routes},{log_modules,sample}]}].