basho / webmachine (http://webmachine.basho.com/)

A REST-based system for building web applications.

Clone this repository (size: 1.8 MB): HTTPS / SSH
$ hg clone http://hg.basho.com/webmachine
commit 132: 7ff17bdd5d01
parent 131: 9fff12d1eb9f
branch: default
rework the demo to shape it look more like the new rebarized Webmachine project template
Bry...@basho.com>
5 months ago

Changed (Δ2.5 KB):

raw changeset »

demo/Emakefile

demo/Makefile (6 lines added, 14 lines removed)

demo/README (37 lines added, 0 lines removed)

demo/ebin/.hg_empty_dir

demo/ebin/webmachine_demo.app (14 lines added, 0 lines removed)

demo/mochiweb

demo/priv/.hg_empty_dir

demo/priv/dispatch.conf (3 lines added, 0 lines removed)

demo/rebar.config (3 lines added, 0 lines removed)

demo/src/webmachine_demo.app

demo/src/webmachine_demo.hrl

demo/src/webmachine_demo_sup.erl (28 lines added, 12 lines removed)

demo/start.sh (1 lines added, 1 lines removed)

demo/webmachine

Up to file-list demo/Makefile:

1
ERL          ?= erl
2
EBIN_DIRS    := $(wildcard webmachine/ebin)
3
APP          := webmachine_demo
1
ERL ?= erl
2
APP := webmachine_demo
4
3
5
all: erl ebin/$(APP).app
4
all:
5
	@../rebar compile
6
6
7
erl:
8
	@$(ERL) -pa $(EBIN_DIRS) -noinput +B \
9
	  -eval 'case make:all() of up_to_date -> halt(0); error -> halt(1) end.'
7
clean:
8
	@../rebar clean
10
9
11
10
docs:
12
11
	@erl -noshell -run edoc_run application '$(APP)' '"."' '[]'
13
14
clean: 
15
	@echo "removing:"
16
	@rm -fv ebin/*.beam ebin/*.app
17
18
ebin/$(APP).app: src/$(APP).app
19
	@cp -v src/$(APP).app $@

Up to file-list demo/README:

1
Project Skeleton for the webmachine_demo app.
2
3
You should find in this directory:
4
5
README : this file
6
Makefile : simple make commands
7
rebar : the Rebar build tool for Erlang applications
8
rebar.config : configuration for Rebar
9
start.sh : simple startup script for running webmachine_demo
10
start-debug.sh : run webmachine_demo in "debug" mode (automatic module
11
                 reloading on compilation)
12
/ebin
13
  /webmachine_demo.app : the Erlang app specification
14
/src
15
  /webmachine_demo_app.erl : base module for the Erlang application
16
  /webmachine_demo_sup.erl : OTP supervisor for the application
17
  /webmachine_demo_resource.erl : a simple example Webmachine resource
18
/priv
19
  /dispatch.conf : the Webmachine URL-dispatching table
20
  /www : a convenient place to put your static web content
21
22
You probably want to do one of a couple of things at this point:
23
24
0. Build the skeleton application:
25
   $ make
26
   - or -
27
   $ ./rebar compile
28
29
1. Start up the skeleton application:
30
   $ ./start.sh
31
32
2. Change the basic application:
33
   edit src/webmachine_demo_resource.erl
34
35
3. Add some new resources:
36
   edit src/YOUR_NEW_RESOURCE.erl
37
   edit priv/dispatch.conf

Up to file-list demo/ebin/webmachine_demo.app:

1
{application, webmachine_demo,
2
 [{description, "webmachine_demo"},
3
  {vsn, "0.1"},
4
  {modules, [
5
	     webmachine_demo,
6
	     webmachine_demo_app,
7
	     webmachine_demo_sup,
8
	     webmachine_demo_resource,
9
	     demo_fs_resource
10
	    ]},
11
  {registered, []},
12
  {mod, {webmachine_demo_app, []}},
13
  {env, []},
14
  {applications, [kernel, stdlib, crypto]}]}.

Up to file-list demo/priv/dispatch.conf:

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

Up to file-list demo/rebar.config:

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

Up to file-list demo/src/webmachine_demo_sup.erl:

1
%% @author Justin Sheehy <justin@basho.com>
2
%% @author Andy Gross <andy@basho.com>
3
%% @copyright 2007-2008 Basho Technologies
1
%% @author author <author@example.com>
2
%% @copyright YYYY author.
4
3
5
4
%% @doc Supervisor for the webmachine_demo application.
6
5
7
6
-module(webmachine_demo_sup).
8
-author('Justin Sheehy <justin@basho.com>').
9
-author('Andy Gross <andy@basho.com>').
7
-author('author <author@example.com>').
10
8
11
9
-behaviour(supervisor).
12
10
13
11
%% External exports
14
-export([start_link/0]).
12
-export([start_link/0, upgrade/0]).
15
13
16
14
%% supervisor callbacks
17
15
-export([init/1]).
21
19
start_link() ->
22
20
    supervisor:start_link({local, ?MODULE}, ?MODULE, []).
23
21
24
dispatch_map() ->
25
    [{["demo", '*'], webmachine_demo_resource, []},
26
     {["fs", '*'], demo_fs_resource, [{root, "/tmp/fs"}]}
27
    ].
22
%% @spec upgrade() -> ok
23
%% @doc Add processes if necessary.
24
upgrade() ->
25
    {ok, {_, Specs}} = init([]),
28
26
27
    Old = sets:from_list(
28
	    [Name || {Name, _, _, _} <- supervisor:which_children(?MODULE)]),
29
    New = sets:from_list([Name || {Name, _, _, _, _, _} <- Specs]),
30
    Kill = sets:subtract(Old, New),
31
32
    sets:fold(fun (Id, ok) ->
33
		      supervisor:terminate_child(?MODULE, Id),
34
		      supervisor:delete_child(?MODULE, Id),
35
		      ok
36
	      end, ok, Kill),
37
38
    [supervisor:start_child(?MODULE, Spec) || Spec <- Specs],
39
    ok.
40
41
%% @spec init([]) -> SupervisorTree
29
42
%% @doc supervisor callback.
30
43
init([]) ->
31
44
    Ip = case os:getenv("WEBMACHINE_IP") of false -> "0.0.0.0"; Any -> Any end,
45
    {ok, Dispatch} = file:consult(filename:join(
46
                         [filename:dirname(code:which(?MODULE)),
47
                          "..", "priv", "dispatch.conf"])),
32
48
    WebConfig = [
33
49
		 {ip, Ip},
34
50
                 {backlog, 1000},
35
51
		 {port, 8000},
36
52
                 {log_dir, "priv/log"},
37
		 {dispatch, dispatch_map()}],
53
		 {dispatch, Dispatch}],
38
54
    Web = {webmachine_mochiweb,
39
55
	   {webmachine_mochiweb, start, [WebConfig]},
40
56
	   permanent, 5000, worker, dynamic},
41
57
    Processes = [Web],
42
    {ok, {{one_for_one, 10, 10}, Processes}}.
58
    {ok, { {one_for_one, 10, 10}, Processes} }.

Up to file-list demo/start.sh:

1
1
#!/bin/sh
2
2
cd `dirname $0`
3
exec erl -pa $PWD/ebin $PWD/mochiweb/ebin $PWD/webmachine/ebin -boot start_sasl -s webmachine_demo
3
exec erl -pa $PWD/ebin $PWD/deps/webmachine/ebin $PWD/deps/webmachine/deps/mochiweb/ebin -boot start_sasl -s reloader -s webmachine_demo