Skip to content
Permalink
Browse files
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
  • Loading branch information
nickva committed May 9, 2022
1 parent 3b3478c commit 0058559a4e050932d4e9234fdffdfc83e75ebba2
Showing 19 changed files with 121 additions and 122 deletions.
@@ -6,13 +6,9 @@ The mailing list for MochiWeb is at https://groups.google.com/group/mochiweb/

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

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

To create a new mochiweb using project in a specific directory:
make app PROJECT=project_name PREFIX=$HOME/projects/

Information about Rebar (Erlang build tool) is available at https://github.com/rebar/rebar
Information about Rebar (Erlang build tool) is available at https://github.com/erlang/rebar3

MochiWeb is currently tested with Erlang/OTP 18.3 through 24.0,
versions older than 3.0.0 may still be compatible back to R15B-03.
@@ -0,0 +1,14 @@
/ebin
/doc
/_test
/.eunit
/docs
.DS_Store
/TEST-*.xml
/deps
/.rebar
*.swp
*.beam
*.dump
_build/
rebar.lock
@@ -0,0 +1,16 @@
REBAR?=rebar3

.PHONY: all edoc test clean app

build:
@$(REBAR) get-deps # rebar2 compatibility, it's no-op on rebar3
@$(REBAR) compile

test:
@$(REBAR) eunit

edoc:
@$(REBAR) edoc

clean:
@$(REBAR) clean
@@ -1,7 +1,7 @@
#!/bin/sh

# workaround for rebar mustache template bug
DEFAULT_PORT={{port}}
DEFAULT_PORT=8080
HOST=${HOST:-127.0.0.1}
PORT=${PORT:-${DEFAULT_PORT}}

@@ -3,6 +3,6 @@
<title>It Worked</title>
</head>
<body>
{{appid}} running.
example_project running.
</body>
</html>
@@ -2,6 +2,6 @@
{erl_opts, [debug_info]}.
{deps, [
{mochiweb, ".*",
{git, "git://github.com/mochi/mochiweb.git", {branch, "main"}}}]}.
{git, "https://github.com/mochi/mochiweb.git", {branch, "main"}}}]}.
{cover_enabled, true}.
{eunit_opts, [verbose, {report,{eunit_surefire,[{dir,"."}]}}]}.
@@ -0,0 +1,9 @@
%% -*- erlang -*-
{application, example_project,
[{description, "example_project"},
{vsn, "0.1"},
{modules, []},
{registered, []},
{mod, {'example_project_app', []}},
{env, []},
{applications, [kernel, stdlib, crypto]}]}.
@@ -0,0 +1,30 @@
%% @author Mochi Media <dev@mochimedia.com>
%% @copyright 2010 Mochi Media <dev@mochimedia.com>

%% @doc example_project.

-module(example_project).
-author("Mochi Media <dev@mochimedia.com>").
-export([start/0, stop/0]).

ensure_started(App) ->
case application:start(App) of
ok ->
ok;
{error, {already_started, App}} ->
ok
end.


%% @spec start() -> ok
%% @doc Start the example_project server.
start() ->
example_project_deps:ensure(),
ensure_started(crypto),
application:start(example_project).


%% @spec stop() -> ok
%% @doc Stop the example_project server.
stop() ->
application:stop(example_project).
@@ -0,0 +1,22 @@
%% @author Mochi Media <dev@mochimedia.com>
%% @copyright example_project Mochi Media <dev@mochimedia.com>

%% @doc Callbacks for the example_project application.

-module(example_project_app).
-author("Mochi Media <dev@mochimedia.com>").

-behaviour(application).
-export([start/2,stop/1]).


%% @spec start(_Type, _StartArgs) -> ServerRet
%% @doc application start callback for example_project.
start(_Type, _StartArgs) ->
example_project_deps:ensure(),
example_project_sup:start_link().

%% @spec stop(_State) -> ServerRet
%% @doc application stop callback for example_project.
stop(_State) ->
ok.
@@ -1,12 +1,12 @@
%% @author {{author}}
%% @copyright {{year}} {{author}}
%% @author Mochi Media <dev@mochimedia.com>
%% @copyright 2010 Mochi Media <dev@mochimedia.com>

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

-module({{appid}}_deps).
-author("{{author}}").
-module(example_project_deps).
-author("Mochi Media <dev@mochimedia.com>").

-export([ensure/0, ensure/1]).
-export([get_base_dir/0, get_base_dir/1]).
@@ -1,10 +1,10 @@
%% @author {{author}}
%% @copyright {{year}} {{author}}
%% @author Mochi Media <dev@mochimedia.com>
%% @copyright 2010 Mochi Media <dev@mochimedia.com>

%% @doc Supervisor for the {{appid}} application.
%% @doc Supervisor for the example_project application.

-module({{appid}}_sup).
-author("{{author}}").
-module(example_project_sup).
-author("Mochi Media <dev@mochimedia.com>").

-behaviour(supervisor).

@@ -41,7 +41,7 @@ upgrade() ->
%% @spec init([]) -> SupervisorTree
%% @doc supervisor callback.
init([]) ->
Web = web_specs({{appid}}_web, {{port}}),
Web = web_specs(example_project_web, 8080),
Processes = [Web],
Strategy = {one_for_one, 10, 10},
{ok,
@@ -50,7 +50,7 @@ init([]) ->
web_specs(Mod, Port) ->
WebConfig = [{ip, {0,0,0,0}},
{port, Port},
{docroot, {{appid}}_deps:local_path(["priv", "www"])}],
{docroot, example_project_deps:local_path(["priv", "www"])}],
{Mod,
{Mod, start, [WebConfig]},
permanent, 5000, worker, dynamic}.
@@ -1,11 +1,11 @@
%% @author {{author}}
%% @copyright {{year}} {{author}}
%% @author Mochi Media <dev@mochimedia.com>
%% @copyright 2010 Mochi Media <dev@mochimedia.com>

%% @doc Web server for {{appid}}.
%% @doc Web server for example_project.

-module('{{appid}}_web').
-module('example_project_web').

-author("{{author}}").
-author("Mochi Media <dev@mochimedia.com>").

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

@@ -0,0 +1,9 @@
#!/bin/sh
exec erl \
-pa _build/default/lib/example_project/ebin \
-pa _build/default/lib/mochiweb/ebin \
-pa ebin deps/*/ebin \
-boot start_sasl \
-sname example_project_dev \
-s example_project \
-s reloader

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

0 comments on commit 0058559

Please sign in to comment.