diff options
author | Loïc Hoguin <[email protected]> | 2024-11-21 15:55:37 +0100 |
---|---|---|
committer | Loïc Hoguin <[email protected]> | 2024-11-22 14:36:39 +0100 |
commit | e299e34960cd8968f7a8a9914e47ea83ed9218c2 (patch) | |
tree | d63594a5a95d23904b8e95bd68387c66e032df85 /templates/cowboy_websocket_h.erl | |
parent | 9376f53f549c05cf692d0e259763049a039e96eb (diff) | |
download | erlang.mk-templates.tar.gz erlang.mk-templates.tar.bz2 erlang.mk-templates.zip |
Move templates outside the source .mk filestemplates
Templates now no longer use Make variables for substitution
but instead replace strings with their equivalent:
template_name: Corresponds to n=template_name
project_name: Corresponds to $(PROJECT) or in=project_name
This allows defining templates outside of Makefiles. For
example an external plugin could define their templates
in templates/my_template.erl and then have the following
in the included Makefile:
tpl_my_template = $(file < $(THIS)/templates/my_template.erl)
By default the created file will be in src/template_name.erl.
This can be overriden with the tplp_* variable:
tplp_my_template = src/model/my_template.erl
Substitution is applied both to the template contents and
to its path.
In addition, attempting to overwrite an existing file when
creating a template will result in failure.
Diffstat (limited to 'templates/cowboy_websocket_h.erl')
-rw-r--r-- | templates/cowboy_websocket_h.erl | 31 |
1 files changed, 31 insertions, 0 deletions
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. |