aboutsummaryrefslogtreecommitdiffstats
path: root/plugins.mk
diff options
context:
space:
mode:
authorLoïc Hoguin <[email protected]>2016-12-28 17:54:50 +0100
committerLoïc Hoguin <[email protected]>2016-12-28 17:54:50 +0100
commit5838a0c81a978377084b33fd086de10f9775f425 (patch)
tree34cab3c3fcfe9b59db716378d960630f5db64b53 /plugins.mk
parentf7094ad78f6638d0e940a724fe5a857cc857155f (diff)
downloadcowboy-5838a0c81a978377084b33fd086de10f9775f425.tar.gz
cowboy-5838a0c81a978377084b33fd086de10f9775f425.tar.bz2
cowboy-5838a0c81a978377084b33fd086de10f9775f425.zip
Add templates as Erlang.mk plugin
Diffstat (limited to 'plugins.mk')
-rw-r--r--plugins.mk75
1 files changed, 75 insertions, 0 deletions
diff --git a/plugins.mk b/plugins.mk
new file mode 100644
index 0000000..649eb79
--- /dev/null
+++ b/plugins.mk
@@ -0,0 +1,75 @@
+# See LICENSE for licensing information.
+
+# Plain HTTP handlers.
+define tpl_cowboy.http
+-module($(n)).
+-behavior(cowboy_handler).
+
+-export([init/2]).
+
+init(Req, State) ->
+ {ok, Req, State}.
+endef
+
+# Loop handlers.
+define tpl_cowboy.loop
+-module($(n)).
+-behavior(cowboy_loop).
+
+-export([init/2]).
+-export([info/3]).
+
+init(Req, State) ->
+ {cowboy_loop, Req, State, 5000, hibernate}.
+
+info(_Info, Req, State) ->
+ {ok, Req, State, hibernate}.
+endef
+
+# REST handlers.
+define tpl_cowboy.rest
+-module($(n)).
+-behavior(cowboy_rest).
+
+-export([init/2]).
+-export([content_types_provided/2]).
+-export([to_html/2]).
+
+init(Req, State) ->
+ {cowboy_rest, Req, State}.
+
+content_types_provided(Req, State) ->
+ {[
+ {{<<"text">>, <<"html">>, '*'}, to_html}
+ ], Req, State}.
+
+to_html(Req, State) ->
+ {<<"<html><body>This is REST!</body></html>">>, Req, State}.
+endef
+
+# Websocket handlers.
+define tpl_cowboy.ws
+-module($(n)).
+-behavior(cowboy_websocket).
+
+-export([init/2]).
+-export([websocket_init/1]).
+-export([websocket_handle/2]).
+-export([websocket_info/2]).
+
+init(Req, State) ->
+ {cowboy_websocket, Req, State}.
+
+websocket_init(State) ->
+ {ok, State}.
+
+websocket_handle({text, Data}, State) ->
+ {reply, {text, Data}, State};
+websocket_handle({binary, Data}, State) ->
+ {reply, {binary, Data}, State};
+websocket_handle(_Frame, State) ->
+ {ok, State}.
+
+websocket_info(_Info, State) ->
+ {ok, State}.
+endef