Anonymous avatar Anonymous committed 7ff17bd

rework the demo to shape it look more like the new rebarized Webmachine project template

Comments (0)

Files changed (14)

demo/Emakefile

-% -*- mode: erlang -*-
-{["src/*"], 
-  [{i, "include"},
-  {outdir, "ebin"},
-  debug_info]
-}.
-ERL          ?= erl
-EBIN_DIRS    := $(wildcard webmachine/ebin)
-APP          := webmachine_demo
+ERL ?= erl
+APP := webmachine_demo
 
-all: erl ebin/$(APP).app
+all:
+	@../rebar compile
 
-erl:
-	@$(ERL) -pa $(EBIN_DIRS) -noinput +B \
-	  -eval 'case make:all() of up_to_date -> halt(0); error -> halt(1) end.'
+clean:
+	@../rebar clean
 
 docs:
 	@erl -noshell -run edoc_run application '$(APP)' '"."' '[]'
-
-clean: 
-	@echo "removing:"
-	@rm -fv ebin/*.beam ebin/*.app
-
-ebin/$(APP).app: src/$(APP).app
-	@cp -v src/$(APP).app $@
+Project Skeleton for the webmachine_demo app.
+
+You should find in this directory:
+
+README : this file
+Makefile : simple make commands
+rebar : the Rebar build tool for Erlang applications
+rebar.config : configuration for Rebar
+start.sh : simple startup script for running webmachine_demo
+start-debug.sh : run webmachine_demo in "debug" mode (automatic module
+                 reloading on compilation)
+/ebin
+  /webmachine_demo.app : the Erlang app specification
+/src
+  /webmachine_demo_app.erl : base module for the Erlang application
+  /webmachine_demo_sup.erl : OTP supervisor for the application
+  /webmachine_demo_resource.erl : a simple example Webmachine resource
+/priv
+  /dispatch.conf : the Webmachine URL-dispatching table
+  /www : a convenient place to put your static web content
+
+You probably want to do one of a couple of things at this point:
+
+0. Build the skeleton application:
+   $ make
+   - or -
+   $ ./rebar compile
+
+1. Start up the skeleton application:
+   $ ./start.sh
+
+2. Change the basic application:
+   edit src/webmachine_demo_resource.erl
+
+3. Add some new resources:
+   edit src/YOUR_NEW_RESOURCE.erl
+   edit priv/dispatch.conf
Add a comment to this file

demo/ebin/.hg_empty_dir

Empty file removed.

demo/ebin/webmachine_demo.app

+{application, webmachine_demo,
+ [{description, "webmachine_demo"},
+  {vsn, "0.1"},
+  {modules, [
+	     webmachine_demo,
+	     webmachine_demo_app,
+	     webmachine_demo_sup,
+	     webmachine_demo_resource,
+	     demo_fs_resource
+	    ]},
+  {registered, []},
+  {mod, {webmachine_demo_app, []}},
+  {env, []},
+  {applications, [kernel, stdlib, crypto]}]}.

demo/mochiweb

-../deps/mochiweb
Add a comment to this file

demo/priv/.hg_empty_dir

Empty file removed.

demo/priv/dispatch.conf

+%%-*- mode: erlang -*-
+{["demo", '*'], webmachine_demo_resource, []}.
+{["fs", '*'], demo_fs_resource, [{root, "/tmp/fs"}]}.

demo/rebar.config

+%%-*- mode: erlang -*-
+{deps, [{webmachine, "1\.6", {hg, "http://hg.basho.com/webmachine", "tip"}}]}.
+

demo/src/webmachine_demo.app

-{application, webmachine_demo,
- [{description, "webmachine_demo"},
-  {vsn, "0.1"},
-  {modules, [
-	     webmachine_demo,
-	     webmachine_demo_app,
-	     webmachine_demo_sup,
-	     webmachine_demo_resource,
-	     demo_fs_resource
-	    ]},
-  {registered, []},
-  {mod, {webmachine_demo_app, []}},
-  {env, []},
-  {applications, [kernel, stdlib, crypto]}]}.

demo/src/webmachine_demo.hrl

-

demo/src/webmachine_demo_sup.erl

-%% @author Justin Sheehy <justin@basho.com>
-%% @author Andy Gross <andy@basho.com>
-%% @copyright 2007-2008 Basho Technologies
+%% @author author <author@example.com>
+%% @copyright YYYY author.
 
 %% @doc Supervisor for the webmachine_demo application.
 
 -module(webmachine_demo_sup).
--author('Justin Sheehy <justin@basho.com>').
--author('Andy Gross <andy@basho.com>').
+-author('author <author@example.com>').
 
 -behaviour(supervisor).
 
 %% External exports
--export([start_link/0]).
+-export([start_link/0, upgrade/0]).
 
 %% supervisor callbacks
 -export([init/1]).
 start_link() ->
     supervisor:start_link({local, ?MODULE}, ?MODULE, []).
 
-dispatch_map() ->
-    [{["demo", '*'], webmachine_demo_resource, []},
-     {["fs", '*'], demo_fs_resource, [{root, "/tmp/fs"}]}
-    ].
+%% @spec upgrade() -> ok
+%% @doc Add processes if necessary.
+upgrade() ->
+    {ok, {_, Specs}} = init([]),
 
+    Old = sets:from_list(
+	    [Name || {Name, _, _, _} <- supervisor:which_children(?MODULE)]),
+    New = sets:from_list([Name || {Name, _, _, _, _, _} <- Specs]),
+    Kill = sets:subtract(Old, New),
+
+    sets:fold(fun (Id, ok) ->
+		      supervisor:terminate_child(?MODULE, Id),
+		      supervisor:delete_child(?MODULE, Id),
+		      ok
+	      end, ok, Kill),
+
+    [supervisor:start_child(?MODULE, Spec) || Spec <- Specs],
+    ok.
+
+%% @spec init([]) -> SupervisorTree
 %% @doc supervisor callback.
 init([]) ->
     Ip = case os:getenv("WEBMACHINE_IP") of false -> "0.0.0.0"; Any -> Any end,
+    {ok, Dispatch} = file:consult(filename:join(
+                         [filename:dirname(code:which(?MODULE)),
+                          "..", "priv", "dispatch.conf"])),
     WebConfig = [
 		 {ip, Ip},
                  {backlog, 1000},
 		 {port, 8000},
                  {log_dir, "priv/log"},
-		 {dispatch, dispatch_map()}],
+		 {dispatch, Dispatch}],
     Web = {webmachine_mochiweb,
 	   {webmachine_mochiweb, start, [WebConfig]},
 	   permanent, 5000, worker, dynamic},
     Processes = [Web],
-    {ok, {{one_for_one, 10, 10}, Processes}}.
+    {ok, { {one_for_one, 10, 10}, Processes} }.
 #!/bin/sh
 cd `dirname $0`
-exec erl -pa $PWD/ebin $PWD/mochiweb/ebin $PWD/webmachine/ebin -boot start_sasl -s webmachine_demo
+exec erl -pa $PWD/ebin $PWD/deps/webmachine/ebin $PWD/deps/webmachine/deps/mochiweb/ebin -boot start_sasl -s reloader -s webmachine_demo

demo/webmachine

-..
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.