<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array">
    <added>
      <filename>priv/skel/src/home_controller.erl</filename>
    </added>
    <added>
      <filename>priv/skel/views/base.html</filename>
    </added>
    <added>
      <filename>priv/skel/views/home/index.html</filename>
    </added>
    <added>
      <filename>priv/skel/views/home/show.html</filename>
    </added>
    <added>
      <filename>priv/skel/www/stylesheets/style.css</filename>
    </added>
    <added>
      <filename>src/beepbeep.erl</filename>
    </added>
    <added>
      <filename>src/beepbeep_args.erl</filename>
    </added>
    <added>
      <filename>src/beepbeep_router.erl</filename>
    </added>
    <added>
      <filename>src/mochiweb_env.erl</filename>
    </added>
  </added>
  <modified type="array">
    <modified>
      <diff>@@ -32,48 +32,50 @@ To run the sample:
 
 h3. How it works:
 
-You write a controller similar to how you'd write a &quot;gen_server&quot; based app, but in our
-case you use the included &quot;gen_controller&quot; behavior. In the controller you define the functions
-you want to expose to requests.  BeepBeep will automatically map Url requests to controller and
-functions (or actions). For example a request to &quot;/hello/show&quot; would map to the &quot;hello_controller&quot; 
-and invoke the &quot;show&quot; function. 
+You write a controller with a set of method that look like this:
 
-Here's a controller example:
+handle_request(Action,Params)
+
+where Action is a string that will match to request in the Url and
+Params is an Array of optional parameters.
+
+BeepBeep will automatically map Url requests to controller and functions (or actions). For example a request to &quot;/hello/show&quot; would map to the &quot;hello_controller&quot; 
+and invoke the &quot;handle_request(&quot;show&quot;,[])&quot; function. 
+
+Here's anexample:
 
 &lt;pre&gt;
  &lt;code&gt;
 %% hello_controller.erl
 -module(hello_controller).
 
--export([show/1]).
--export([handle_request/2, before_filter/1]).
+-export([handle_request/2, before_filter/0]).
 
--behaviour(gen_controller).
--include(&quot;beepbeep.hrl&quot;).
-
-show(Params) -&gt;
-    gen_controller:call(?MODULE,index,Params).
-
-%% Callback for show
-handle_request(show,Params) -&gt;
-    {render, &quot;hello/show.html&quot;,[{name,&quot;BeepBeep&quot;}],Params}.
+%% Maps to http://localhost:8000/hello/show
+handle_request(&quot;show&quot;,[]) -&gt;
+    {render, &quot;hello/show.html&quot;,[{name,&quot;BeepBeep&quot;}]};
 
+%% Maps to http://localhost:8000/hello/feed/2007
+handle_request(&quot;feed&quot;,[Year]) -&gt;
+    %% Now Year contains the value 2007
+    {render,&quot;hello/feed.html&quot;,[{year,Year}]}.
+  
 
 %% Callback filter hook
 before_filter(Params) -&gt;
-    {ok}.
+    ok.
 
  &lt;/code&gt;
 &lt;/pre&gt;
 
 From &quot;handle_request&quot; we return a tuple that tells the framework what template to use. Templates
-are located in the template directory. In our example we'ill use the template located in the 
+are located in the template directory. In our example we'll use the template located in the 
 subdirectory &quot;hello&quot; and the file &quot;show.html&quot;
 
 Here's an example of the &quot;show.html&quot; template:
 
 &lt;pre&gt;&lt;code&gt;
-&lt;h2&gt;Hello from {{ data }} &lt;/h2&gt;
+&lt;h2&gt;Hello from {{ name }} &lt;/h2&gt;
 &lt;/code&gt;&lt;/pre&gt;
 
 Which will result in:
@@ -87,4 +89,8 @@ via erlyDTL.
 This approach provides a clean separation of the erlang logic in the controller and the html code in
 the template.
 
+You can also implement the before_filter to check requests before the matching &quot;handle_request&quot; is
+called.  Filters that pass should simply return the atom ok, otherwise they should return one
+of the request responses such as {render...} or {redirect...&quot; 
+
 More to come...</diff>
      <filename>README.textile</filename>
    </modified>
    <modified>
      <diff>@@ -1,13 +1,14 @@
-
 %% Session Id key
--define(SID,&quot;_beepbeep_session_id&quot;).
+-define(BEEPBEEP_SID, &quot;_beepbeep_session_id_&quot;).
 
-%% Holds parameter information passes around
--record(params,{
-	  controller,
-	  action,
-	  id,
-	  method,
-	  data, %% Query and Post Data
- 	  sid   %% Session Id
-	 }).
+%% Environment data
+-define(BEEPBEEP_ENV_DATA, [{server_sw, &quot;SERVER_SOFTWARE&quot;},
+			    {server_name, &quot;SERVER_NAME&quot;},
+			    {server_protocol, &quot;SERVER_PROTOCOL&quot;},
+			    {server_port, &quot;SERVER_PORT&quot;},
+			    {method, &quot;REQUEST_METHOD&quot;},
+			    {content_type, &quot;CONTENT_TYPE&quot;},
+			    {content_length,&quot;CONTENT_LENGTH&quot;},
+			    {path_info, &quot;PATH_INFO&quot;},
+			    {remote_addr, &quot;REMOTE_ADDR&quot;},
+			    {beepbeep_params, &quot;beepbeep.data&quot;}]).</diff>
      <filename>include/beepbeep.hrl</filename>
    </modified>
    <modified>
      <diff>@@ -5,6 +5,7 @@
     skel,
     skel_app,
     skel_sup,
+    skel_web,
     skel_deps
   ]},
   {registered, []},</diff>
      <filename>priv/skel/src/skel.app</filename>
    </modified>
    <modified>
      <diff>@@ -1,10 +1,4 @@
-%% @author author &lt;author@example.com&gt;
-%% @copyright YYYY author.
-
-%% @doc TEMPLATE.
-
 -module(skel).
--author('author &lt;author@example.com&gt;').
 -export([start/0, stop/0]).
 
 ensure_started(App) -&gt;</diff>
      <filename>priv/skel/src/skel.erl</filename>
    </modified>
    <modified>
      <diff>@@ -1,10 +1,4 @@
-%% @author author &lt;author@example.com&gt;
-%% @copyright YYYY author.
-
-%% @doc Callbacks for the skel application.
-
 -module(skel_app).
--author('author &lt;author@example.com&gt;').
 
 -behaviour(application).
 -export([start/2,stop/1]).</diff>
      <filename>priv/skel/src/skel_app.erl</filename>
    </modified>
    <modified>
      <diff>@@ -1,12 +1,4 @@
-%% @author author &lt;author@example.com&gt;
-%% @copyright YYYY author.
-
-%% @doc Ensure that the relatively-installed dependencies are on the code
-%%      loading path, and locate resources relative
-%%      to this application's path.
-
 -module(skel_deps).
--author('author &lt;author@example.com&gt;').
 
 -export([ensure/0, ensure/1]).
 -export([get_base_dir/0, get_base_dir/1]).</diff>
      <filename>priv/skel/src/skel_deps.erl</filename>
    </modified>
    <modified>
      <diff>@@ -1,10 +1,4 @@
-%% @author author &lt;author@example.com&gt;
-%% @copyright YYYY author.
-
-%% @doc Supervisor for the skel application.
-
 -module(skel_sup).
--author('author &lt;author@example.com&gt;').
 
 -behaviour(supervisor).
 
@@ -43,17 +37,21 @@ upgrade() -&gt;
 init([]) -&gt;
     Ip = case os:getenv(&quot;MOCHIWEB_IP&quot;) of false -&gt; &quot;0.0.0.0&quot;; Any -&gt; Any end,   
     WebConfig = [
-         {ip, Ip},
-                 {port, 8000},
-                 {docroot, skel_deps:local_path([&quot;priv&quot;, &quot;www&quot;])}],
+		 {ip, Ip},
+                 {port, 8000}
+                ],
+
+    BaseDir = skel_deps:get_base_dir(),
     
     Web = {skel_web,
 	   {skel_web, start, [WebConfig]},
 	   permanent, 5000, worker, dynamic},
-    
+    Router = {beepbeep_router,
+	      {beepbeep_router, start, [BaseDir]},
+	      permanent, 5000, worker, dynamic},
     SessionServer = {beepbeep_session_server,
 		     {beepbeep_session_server,start,[]},
 		     permanent, 5000, worker, dynamic},
     
-    Processes = [Web,SessionServer],
+    Processes = [Router,SessionServer,Web],
     {ok, {{one_for_one, 10, 10}, Processes}}.</diff>
      <filename>priv/skel/src/skel_sup.erl</filename>
    </modified>
    <modified>
      <diff>@@ -1,104 +1,46 @@
 -module(skel_web).
 -author('Dave Bryson &lt;http://weblog.miceda.org&gt;').
 
--export([start/1, stop/0, loop/2]).
-
+-export([start/1, stop/0, loop/1]).
 -include(&quot;beepbeep.hrl&quot;).
 
 start(Options) -&gt;
-    {DocRoot, Options1} = get_option(docroot, Options),
     Loop = fun (Req) -&gt;
-		   ?MODULE:loop(Req, DocRoot)
-	   end,
-    mochiweb_http:start([{name, ?MODULE}, {loop, Loop} | Options1]).
+                   ?MODULE:loop(Req)
+           end,
+    mochiweb_http:start([{name, ?MODULE}, {loop, Loop} | Options]).
 
 stop() -&gt;
     mochiweb_http:stop(?MODULE).
 
-loop(Req, DocRoot) -&gt;
-    Path = Req:get(path),
-    RequestMethod = Req:get(method),
-    Params = case RequestMethod of
-		 Method when Method =:= 'GET'; Method =:= 'HEAD' -&gt;
-		     Req:parse_qs(); 
-		 _ -&gt;
-		     Req:parse_post()
-	     end,
+loop(Req) -&gt;
+    %% Setup env...
+    InitialEnv = mochiweb_env:setup_environment(Req),
+    Env = setup_session(Req,InitialEnv),
+    %%error_logger:info_report(Env),
     
-    %% Setup the Session
-    CookieKey = beepbeep_session_server:new_session(Req:get_cookie_value(?SID)),
-    %% Setup Params structure for controllers
-    P1 = #params{sid=CookieKey,data=Params,method=RequestMethod},
-  
-
-    %% Route the request
-    case dispatch(Path,P1) of
-	{render,Template,Data,P} -&gt;
-	    H = mochiweb_cookies:cookie(?SID,P#params.sid, [{path, &quot;/&quot;}]), 
-	    {ok,Content} = render_template(Template,Data),
-	    Req:ok({&quot;text/html&quot;,[H],Content});
+    case beepbeep:dispatch(Env) of
+	{ok,Status,ContentType,H,Content} -&gt;
+	    Cookie = get_cookie(Env), 
+	    Headers = [Cookie|H],
+	    Req:respond({Status,[{&quot;Content-Type&quot;,ContentType}|Headers],Content});
+	    %%Req:ok({&quot;text/html&quot;,Headers,Content});
 	{redirect,Url} -&gt;
 	    Req:respond({302, 
                          [{&quot;Location&quot;, Url}, 
                           {&quot;Content-Type&quot;, &quot;text/html; charset=UTF-8&quot;}], 
                          &quot;&quot;});
-	{static,File} -&gt;
-	    Req:serve_file(File,DocRoot)
+	{static, File} -&gt;
+	    &quot;/&quot; ++ StaticFile = File,
+	    Req:serve_file(StaticFile,skel_deps:local_path([&quot;www&quot;]));
+	{error,_} -&gt;
+	    Req:respond({500,[],&quot;Server Error&quot;})
     end.
-    
-%% Internal API
-
-get_option(Option, Options) -&gt;
-    {proplists:get_value(Option, Options), proplists:delete(Option, Options)}.
-
-%% Route the Request
-dispatch(Path,Params) -&gt;
-    PathParts = string:tokens(Path,&quot;/&quot;),
-    P1 = extract_route_info(PathParts,Params),
-    Controller = P1#params.controller,
-    Action = P1#params.action,
-    
-    Reply = case catch(Controller:Action(P1)) of
-		{'EXIT', {undef, _}} -&gt;
-		    %% Try static 
-		    &quot;/&quot; ++ StaticPath = Path,
-		    {static,StaticPath};
-		Any -&gt;
-		    io:format(&quot;Ran with ~p~n&quot;,[Any]),
-		    Any
-	    end,
-    Reply.
-
-
-%% Parse out the route information from the path 
-extract_route_info([],P) -&gt;
-    %% Default route of root (&quot;/&quot;) path
-    P1 = P,
-    P1#params{controller=main_controller,action=index};
-extract_route_info([C],P) -&gt;
-    %% Default &quot;/hello&quot; to &quot;hello_controller:index&quot;
-    P1 = P,
-    P1#params{controller=make_controller_name(C),action=index};
-extract_route_info([C,A],P) -&gt;
-    P1 = P,
-    P1#params{controller=make_controller_name(C),action=list_to_atom(A)};
-extract_route_info([C,A,Id],P) -&gt;
-    P1 = P,
-    P1#params{controller=make_controller_name(C),action=list_to_atom(A), id=Id}.
-
-make_controller_name(ControllerName) -&gt;
-    list_to_atom(ControllerName ++ &quot;_controller&quot;).
-
-
-%% Render the Template via erlydtl
-render_template(File,Data) -&gt;
-    FullPathToFile = skel_deps:local_path([&quot;templates&quot;,File]),
+ 
 
-    %% Make a module name
-    F = lists:reverse(string:tokens(File,&quot;/&quot;)),
-    [N,_] = string:tokens(hd(F),&quot;.&quot;),
-    Mn = string:join([N,&quot;template&quot;],&quot;_&quot;),
-    ModName = list_to_atom(Mn),
+get_cookie(Env) -&gt;
+    mochiweb_cookies:cookie(?BEEPBEEP_SID,beepbeep_args:get_session_id(Env),[{path, &quot;/&quot;}]).
 
-    erlydtl:compile(FullPathToFile,ModName),
-    ModName:render(Data).
+setup_session(Req,Env) -&gt;
+    SessionKey = beepbeep_session_server:new_session(Req:get_cookie_value(?BEEPBEEP_SID)),
+    beepbeep_args:set_session_id(SessionKey,Env).</diff>
      <filename>priv/skel/src/skel_web.erl</filename>
    </modified>
  </modified>
  <removed type="array">
    <removed>
      <filename>src/beepbeep_api.erl</filename>
    </removed>
    <removed>
      <filename>src/gen_controller.erl</filename>
    </removed>
  </removed>
  <parents type="array">
    <parent>
      <id>8803a2fa9a0b6983479b952ca7f9a1bb32fc8f05</id>
    </parent>
  </parents>
  <author>
    <name>Dave Bryson</name>
    <email>daveb@miceda.org</email>
  </author>
  <url>http://github.com/davebryson/beepbeep/commit/5cce39ecd7ab9417067330f1ac4bb0e41580f0df</url>
  <id>5cce39ecd7ab9417067330f1ac4bb0e41580f0df</id>
  <committed-date>2009-02-10T16:57:38-08:00</committed-date>
  <authored-date>2009-02-10T16:57:38-08:00</authored-date>
  <message>Completely revamped and improved</message>
  <tree>6776bbd0a51bdf33f79f7e7322812d84611ceaf1</tree>
  <committer>
    <name>Dave Bryson</name>
    <email>daveb@miceda.org</email>
  </committer>
</commit>
