diff options
Diffstat (limited to 'templates')
-rw-r--r-- | templates/application.app.src | 13 | ||||
-rw-r--r-- | templates/application.erl | 11 | ||||
-rw-r--r-- | templates/apps_Makefile | 10 | ||||
-rw-r--r-- | templates/cowboy_http_h.erl | 19 | ||||
-rw-r--r-- | templates/cowboy_loop_h.erl | 18 | ||||
-rw-r--r-- | templates/cowboy_rest_h.erl | 14 | ||||
-rw-r--r-- | templates/cowboy_websocket_h.erl | 31 | ||||
-rw-r--r-- | templates/gen_fsm.erl | 50 | ||||
-rw-r--r-- | templates/gen_server.erl | 42 | ||||
-rw-r--r-- | templates/gen_statem.erl | 42 | ||||
-rw-r--r-- | templates/library.app.src | 11 | ||||
-rw-r--r-- | templates/module.erl | 2 | ||||
-rw-r--r-- | templates/ranch_protocol.erl | 25 | ||||
-rw-r--r-- | templates/relx.config | 6 | ||||
-rw-r--r-- | templates/supervisor.erl | 12 | ||||
-rw-r--r-- | templates/sys.config | 2 | ||||
-rw-r--r-- | templates/top_Makefile | 5 | ||||
-rw-r--r-- | templates/vm.args | 3 |
18 files changed, 316 insertions, 0 deletions
diff --git a/templates/application.app.src b/templates/application.app.src new file mode 100644 index 0000000..3bd1d6b --- /dev/null +++ b/templates/application.app.src @@ -0,0 +1,13 @@ +{application, project_name, [ + {description, ""}, + {vsn, "0.1.0"}, + {id, "git"}, + {modules, []}, + {registered, []}, + {applications, [ + kernel, + stdlib + ]}, + {mod, {project_name_app, []}}, + {env, []} +]}. diff --git a/templates/application.erl b/templates/application.erl new file mode 100644 index 0000000..2c8d27b --- /dev/null +++ b/templates/application.erl @@ -0,0 +1,11 @@ +-module(project_name_app). +-behaviour(application). + +-export([start/2]). +-export([stop/1]). + +start(_Type, _Args) -> + project_name_sup:start_link(). + +stop(_State) -> + ok. diff --git a/templates/apps_Makefile b/templates/apps_Makefile new file mode 100644 index 0000000..093287f --- /dev/null +++ b/templates/apps_Makefile @@ -0,0 +1,10 @@ +PROJECT = project_name +PROJECT_DESCRIPTION = New project +PROJECT_VERSION = 0.1.0 +template_sp +# Make sure we know where the applications are located. +ROOT_DIR ?= rel_root_dir +APPS_DIR ?= .. +DEPS_DIR ?= rel_deps_dir + +include rel_root_dir/erlang.mk diff --git a/templates/cowboy_http_h.erl b/templates/cowboy_http_h.erl new file mode 100644 index 0000000..a2c3200 --- /dev/null +++ b/templates/cowboy_http_h.erl @@ -0,0 +1,19 @@ +-module(template_name). +-behaviour(cowboy_http_handler). + +-export([init/3]). +-export([handle/2]). +-export([terminate/3]). + +-record(state, { +}). + +init(_, Req, _Opts) -> + {ok, Req, #state{}}. + +handle(Req, State=#state{}) -> + {ok, Req2} = cowboy_req:reply(200, Req), + {ok, Req2, State}. + +terminate(_Reason, _Req, _State) -> + ok. diff --git a/templates/cowboy_loop_h.erl b/templates/cowboy_loop_h.erl new file mode 100644 index 0000000..ce301c9 --- /dev/null +++ b/templates/cowboy_loop_h.erl @@ -0,0 +1,18 @@ +-module(template_name). +-behaviour(cowboy_loop_handler). + +-export([init/3]). +-export([info/3]). +-export([terminate/3]). + +-record(state, { +}). + +init(_, Req, _Opts) -> + {loop, Req, #state{}, 5000, hibernate}. + +info(_Info, Req, State) -> + {loop, Req, State, hibernate}. + +terminate(_Reason, _Req, _State) -> + ok. diff --git a/templates/cowboy_rest_h.erl b/templates/cowboy_rest_h.erl new file mode 100644 index 0000000..a15f4a5 --- /dev/null +++ b/templates/cowboy_rest_h.erl @@ -0,0 +1,14 @@ +-module(template_name). + +-export([init/3]). +-export([content_types_provided/2]). +-export([get_html/2]). + +init(_, _Req, _Opts) -> + {upgrade, protocol, cowboy_rest}. + +content_types_provided(Req, State) -> + {[{{<<"text">>, <<"html">>, '*'}, get_html}], Req, State}. + +get_html(Req, State) -> + {<<"<html><body>This is REST!</body></html>">>, Req, State}. diff --git a/templates/cowboy_websocket_h.erl b/templates/cowboy_websocket_h.erl new file mode 100644 index 0000000..538f020 --- /dev/null +++ b/templates/cowboy_websocket_h.erl @@ -0,0 +1,31 @@ +-module(template_name). +-behaviour(cowboy_websocket_handler). + +-export([init/3]). +-export([websocket_init/3]). +-export([websocket_handle/3]). +-export([websocket_info/3]). +-export([websocket_terminate/3]). + +-record(state, { +}). + +init(_, _, _) -> + {upgrade, protocol, cowboy_websocket}. + +websocket_init(_, Req, _Opts) -> + Req2 = cowboy_req:compact(Req), + {ok, Req2, #state{}}. + +websocket_handle({text, Data}, Req, State) -> + {reply, {text, Data}, Req, State}; +websocket_handle({binary, Data}, Req, State) -> + {reply, {binary, Data}, Req, State}; +websocket_handle(_Frame, Req, State) -> + {ok, Req, State}. + +websocket_info(_Info, Req, State) -> + {ok, Req, State}. + +websocket_terminate(_Reason, _Req, _State) -> + ok. diff --git a/templates/gen_fsm.erl b/templates/gen_fsm.erl new file mode 100644 index 0000000..73505df --- /dev/null +++ b/templates/gen_fsm.erl @@ -0,0 +1,50 @@ +-module(template_name). +-behaviour(gen_fsm). + +%% API. +-export([start_link/0]). + +%% gen_fsm. +-export([init/1]). +-export([state_name/2]). +-export([handle_event/3]). +-export([state_name/3]). +-export([handle_sync_event/4]). +-export([handle_info/3]). +-export([terminate/3]). +-export([code_change/4]). + +-record(state, { +}). + +%% API. + +-spec start_link() -> {ok, pid()}. +start_link() -> + gen_fsm:start_link(?MODULE, [], []). + +%% gen_fsm. + +init([]) -> + {ok, state_name, #state{}}. + +state_name(_Event, StateData) -> + {next_state, state_name, StateData}. + +handle_event(_Event, StateName, StateData) -> + {next_state, StateName, StateData}. + +state_name(_Event, _From, StateData) -> + {reply, ignored, state_name, StateData}. + +handle_sync_event(_Event, _From, StateName, StateData) -> + {reply, ignored, StateName, StateData}. + +handle_info(_Info, StateName, StateData) -> + {next_state, StateName, StateData}. + +terminate(_Reason, _StateName, _StateData) -> + ok. + +code_change(_OldVsn, StateName, StateData, _Extra) -> + {ok, StateName, StateData}. diff --git a/templates/gen_server.erl b/templates/gen_server.erl new file mode 100644 index 0000000..d297edf --- /dev/null +++ b/templates/gen_server.erl @@ -0,0 +1,42 @@ +-module(template_name). +-behaviour(gen_server). + +%% API. +-export([start_link/0]). + +%% gen_server. +-export([init/1]). +-export([handle_call/3]). +-export([handle_cast/2]). +-export([handle_info/2]). +-export([terminate/2]). +-export([code_change/3]). + +-record(state, { +}). + +%% API. + +-spec start_link() -> {ok, pid()}. +start_link() -> + gen_server:start_link(?MODULE, [], []). + +%% gen_server. + +init([]) -> + {ok, #state{}}. + +handle_call(_Request, _From, State) -> + {reply, ignored, State}. + +handle_cast(_Msg, State) -> + {noreply, State}. + +handle_info(_Info, State) -> + {noreply, State}. + +terminate(_Reason, _State) -> + ok. + +code_change(_OldVsn, State, _Extra) -> + {ok, State}. diff --git a/templates/gen_statem.erl b/templates/gen_statem.erl new file mode 100644 index 0000000..afdf20f --- /dev/null +++ b/templates/gen_statem.erl @@ -0,0 +1,42 @@ +-module(template_name). +-behaviour(gen_statem). + +%% API. +-export([start_link/0]). + +%% gen_statem. +-export([callback_mode/0]). +-export([init/1]). +-export([state_name/3]). +-export([handle_event/4]). +-export([terminate/3]). +-export([code_change/4]). + +-record(state, { +}). + +%% API. + +-spec start_link() -> {ok, pid()}. +start_link() -> + gen_statem:start_link(?MODULE, [], []). + +%% gen_statem. + +callback_mode() -> + state_functions. + +init([]) -> + {ok, state_name, #state{}}. + +state_name(_EventType, _EventData, StateData) -> + {next_state, state_name, StateData}. + +handle_event(_EventType, _EventData, StateName, StateData) -> + {next_state, StateName, StateData}. + +terminate(_Reason, _StateName, _StateData) -> + ok. + +code_change(_OldVsn, StateName, StateData, _Extra) -> + {ok, StateName, StateData}. diff --git a/templates/library.app.src b/templates/library.app.src new file mode 100644 index 0000000..e7f7d75 --- /dev/null +++ b/templates/library.app.src @@ -0,0 +1,11 @@ +{application, project_name, [ + {description, ""}, + {vsn, "0.1.0"}, + {id, "git"}, + {modules, []}, + {registered, []}, + {applications, [ + kernel, + stdlib + ]} +]}. diff --git a/templates/module.erl b/templates/module.erl new file mode 100644 index 0000000..30a3b1a --- /dev/null +++ b/templates/module.erl @@ -0,0 +1,2 @@ +-module(template_name). +-export([]). diff --git a/templates/ranch_protocol.erl b/templates/ranch_protocol.erl new file mode 100644 index 0000000..1458815 --- /dev/null +++ b/templates/ranch_protocol.erl @@ -0,0 +1,25 @@ +-module(template_name). +-behaviour(ranch_protocol). + +-export([start_link/4]). +-export([init/4]). + +-type opts() :: []. +-export_type([opts/0]). + +-record(state, { + socket :: inet:socket(), + transport :: module() +}). + +start_link(Ref, Socket, Transport, Opts) -> + Pid = spawn_link(?MODULE, init, [Ref, Socket, Transport, Opts]), + {ok, Pid}. + +-spec init(ranch:ref(), inet:socket(), module(), opts()) -> ok. +init(Ref, Socket, Transport, _Opts) -> + ok = ranch:accept_ack(Ref), + loop(#state{socket=Socket, transport=Transport}). + +loop(State) -> + loop(State). diff --git a/templates/relx.config b/templates/relx.config new file mode 100644 index 0000000..3a23af7 --- /dev/null +++ b/templates/relx.config @@ -0,0 +1,6 @@ +{release, {project_name_release, "1"}, [project_name, sasl, runtime_tools]}. +{dev_mode, false}. +{include_erts, true}. +{extended_start_script, true}. +{sys_config, "config/sys.config"}. +{vm_args, "config/vm.args"}. diff --git a/templates/supervisor.erl b/templates/supervisor.erl new file mode 100644 index 0000000..b4ddf91 --- /dev/null +++ b/templates/supervisor.erl @@ -0,0 +1,12 @@ +-module(template_name). +-behaviour(supervisor). + +-export([start_link/0]). +-export([init/1]). + +start_link() -> + supervisor:start_link({local, ?MODULE}, ?MODULE, []). + +init([]) -> + Procs = [], + {ok, {{one_for_one, 1, 5}, Procs}}. diff --git a/templates/sys.config b/templates/sys.config new file mode 100644 index 0000000..0dbd0fd --- /dev/null +++ b/templates/sys.config @@ -0,0 +1,2 @@ +[ +]. diff --git a/templates/top_Makefile b/templates/top_Makefile new file mode 100644 index 0000000..137993f --- /dev/null +++ b/templates/top_Makefile @@ -0,0 +1,5 @@ +PROJECT = project_name +PROJECT_DESCRIPTION = New project +PROJECT_VERSION = 0.1.0 +template_sp +include erlang.mk diff --git a/templates/vm.args b/templates/vm.args new file mode 100644 index 0000000..99a5076 --- /dev/null +++ b/templates/vm.args @@ -0,0 +1,3 @@ +-name [email protected] +-setcookie project_name +-heart |