Skip to content

Commit 0058559

Browse files
committed
Replace template project with an example project
Since rebar3 expects templates to be in `~/.config/rebar3/templates/` [1], opt to instead having just an example project users can copy and update on their own. [1] https://www.rebar3.org/docs/tutorials/templates
1 parent 3b3478c commit 0058559

19 files changed

+121
-122
lines changed

README.md

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,9 @@ The mailing list for MochiWeb is at https://groups.google.com/group/mochiweb/
66

77
Erlang OTP is required for setting up the MochiWeb environment and is available at https://www.erlang.org/
88

9-
To create a new mochiweb using project:
10-
make app PROJECT=project_name
9+
To create a new mochiweb using project see the `example_project` in the `examples/` folder.
1110

12-
To create a new mochiweb using project in a specific directory:
13-
make app PROJECT=project_name PREFIX=$HOME/projects/
14-
15-
Information about Rebar (Erlang build tool) is available at https://github.com/rebar/rebar
11+
Information about Rebar (Erlang build tool) is available at https://github.com/erlang/rebar3
1612

1713
MochiWeb is currently tested with Erlang/OTP 18.3 through 24.0,
1814
versions older than 3.0.0 may still be compatible back to R15B-03.

examples/example_project/.gitignore

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/ebin
2+
/doc
3+
/_test
4+
/.eunit
5+
/docs
6+
.DS_Store
7+
/TEST-*.xml
8+
/deps
9+
/.rebar
10+
*.swp
11+
*.beam
12+
*.dump
13+
_build/
14+
rebar.lock

examples/example_project/Makefile

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
REBAR?=rebar3
2+
3+
.PHONY: all edoc test clean app
4+
5+
build:
6+
@$(REBAR) get-deps # rebar2 compatibility, it's no-op on rebar3
7+
@$(REBAR) compile
8+
9+
test:
10+
@$(REBAR) eunit
11+
12+
edoc:
13+
@$(REBAR) edoc
14+
15+
clean:
16+
@$(REBAR) clean

support/templates/mochiwebapp_skel/bench.sh renamed to examples/example_project/bench.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/bin/sh
22

33
# workaround for rebar mustache template bug
4-
DEFAULT_PORT={{port}}
4+
DEFAULT_PORT=8080
55
HOST=${HOST:-127.0.0.1}
66
PORT=${PORT:-${DEFAULT_PORT}}
77

support/templates/mochiwebapp_skel/priv/www/index.html renamed to examples/example_project/priv/www/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
<title>It Worked</title>
44
</head>
55
<body>
6-
{{appid}} running.
6+
example_project running.
77
</body>
88
</html>

support/templates/mochiwebapp_skel/rebar.config renamed to examples/example_project/rebar.config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22
{erl_opts, [debug_info]}.
33
{deps, [
44
{mochiweb, ".*",
5-
{git, "git://github.com/mochi/mochiweb.git", {branch, "main"}}}]}.
5+
{git, "https://github.com/mochi/mochiweb.git", {branch, "main"}}}]}.
66
{cover_enabled, true}.
77
{eunit_opts, [verbose, {report,{eunit_surefire,[{dir,"."}]}}]}.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
%% -*- erlang -*-
2+
{application, example_project,
3+
[{description, "example_project"},
4+
{vsn, "0.1"},
5+
{modules, []},
6+
{registered, []},
7+
{mod, {'example_project_app', []}},
8+
{env, []},
9+
{applications, [kernel, stdlib, crypto]}]}.
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
%% @author Mochi Media <[email protected]>
2+
%% @copyright 2010 Mochi Media <[email protected]>
3+
4+
%% @doc example_project.
5+
6+
-module(example_project).
7+
-author("Mochi Media <[email protected]>").
8+
-export([start/0, stop/0]).
9+
10+
ensure_started(App) ->
11+
case application:start(App) of
12+
ok ->
13+
ok;
14+
{error, {already_started, App}} ->
15+
ok
16+
end.
17+
18+
19+
%% @spec start() -> ok
20+
%% @doc Start the example_project server.
21+
start() ->
22+
example_project_deps:ensure(),
23+
ensure_started(crypto),
24+
application:start(example_project).
25+
26+
27+
%% @spec stop() -> ok
28+
%% @doc Stop the example_project server.
29+
stop() ->
30+
application:stop(example_project).
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
%% @author Mochi Media <[email protected]>
2+
%% @copyright example_project Mochi Media <[email protected]>
3+
4+
%% @doc Callbacks for the example_project application.
5+
6+
-module(example_project_app).
7+
-author("Mochi Media <[email protected]>").
8+
9+
-behaviour(application).
10+
-export([start/2,stop/1]).
11+
12+
13+
%% @spec start(_Type, _StartArgs) -> ServerRet
14+
%% @doc application start callback for example_project.
15+
start(_Type, _StartArgs) ->
16+
example_project_deps:ensure(),
17+
example_project_sup:start_link().
18+
19+
%% @spec stop(_State) -> ServerRet
20+
%% @doc application stop callback for example_project.
21+
stop(_State) ->
22+
ok.

support/templates/mochiwebapp_skel/src/mochiapp_deps.erl renamed to examples/example_project/src/example_project_deps.erl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
%% @author {{author}}
2-
%% @copyright {{year}} {{author}}
1+
%% @author Mochi Media <[email protected]>
2+
%% @copyright 2010 Mochi Media <[email protected]>
33

44
%% @doc Ensure that the relatively-installed dependencies are on the code
55
%% loading path, and locate resources relative
66
%% to this application's path.
77

8-
-module({{appid}}_deps).
9-
-author("{{author}}").
8+
-module(example_project_deps).
9+
-author("Mochi Media <[email protected]>").
1010

1111
-export([ensure/0, ensure/1]).
1212
-export([get_base_dir/0, get_base_dir/1]).

support/templates/mochiwebapp_skel/src/mochiapp_sup.erl renamed to examples/example_project/src/example_project_sup.erl

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
%% @author {{author}}
2-
%% @copyright {{year}} {{author}}
1+
%% @author Mochi Media <[email protected]>
2+
%% @copyright 2010 Mochi Media <[email protected]>
33

4-
%% @doc Supervisor for the {{appid}} application.
4+
%% @doc Supervisor for the example_project application.
55

6-
-module({{appid}}_sup).
7-
-author("{{author}}").
6+
-module(example_project_sup).
7+
-author("Mochi Media <[email protected]>").
88

99
-behaviour(supervisor).
1010

@@ -41,7 +41,7 @@ upgrade() ->
4141
%% @spec init([]) -> SupervisorTree
4242
%% @doc supervisor callback.
4343
init([]) ->
44-
Web = web_specs({{appid}}_web, {{port}}),
44+
Web = web_specs(example_project_web, 8080),
4545
Processes = [Web],
4646
Strategy = {one_for_one, 10, 10},
4747
{ok,
@@ -50,7 +50,7 @@ init([]) ->
5050
web_specs(Mod, Port) ->
5151
WebConfig = [{ip, {0,0,0,0}},
5252
{port, Port},
53-
{docroot, {{appid}}_deps:local_path(["priv", "www"])}],
53+
{docroot, example_project_deps:local_path(["priv", "www"])}],
5454
{Mod,
5555
{Mod, start, [WebConfig]},
5656
permanent, 5000, worker, dynamic}.

support/templates/mochiwebapp_skel/src/mochiapp_web.erl renamed to examples/example_project/src/example_project_web.erl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
%% @author {{author}}
2-
%% @copyright {{year}} {{author}}
1+
%% @author Mochi Media <[email protected]>
2+
%% @copyright 2010 Mochi Media <[email protected]>
33

4-
%% @doc Web server for {{appid}}.
4+
%% @doc Web server for example_project.
55

6-
-module('{{appid}}_web').
6+
-module('example_project_web').
77

8-
-author("{{author}}").
8+
-author("Mochi Media <[email protected]>").
99

1010
-export([loop/2, start/1, stop/0]).
1111

examples/example_project/start-dev.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/bin/sh
2+
exec erl \
3+
-pa _build/default/lib/example_project/ebin \
4+
-pa _build/default/lib/mochiweb/ebin \
5+
-pa ebin deps/*/ebin \
6+
-boot start_sasl \
7+
-sname example_project_dev \
8+
-s example_project \
9+
-s reloader

support/templates/.gitignore

Lines changed: 0 additions & 5 deletions
This file was deleted.

support/templates/mochiwebapp.template

Lines changed: 0 additions & 24 deletions
This file was deleted.

support/templates/mochiwebapp_skel/src/mochiapp.app.src

Lines changed: 0 additions & 9 deletions
This file was deleted.

support/templates/mochiwebapp_skel/src/mochiapp.erl

Lines changed: 0 additions & 30 deletions
This file was deleted.

support/templates/mochiwebapp_skel/src/mochiapp_app.erl

Lines changed: 0 additions & 22 deletions
This file was deleted.

support/templates/mochiwebapp_skel/start-dev.sh

Lines changed: 0 additions & 7 deletions
This file was deleted.

0 commit comments

Comments
 (0)