Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions rebar.config

This file was deleted.

4 changes: 0 additions & 4 deletions relx.config

This file was deleted.

21 changes: 0 additions & 21 deletions src/_.app.src

This file was deleted.

13 changes: 0 additions & 13 deletions src/_app.erl

This file was deleted.

20 changes: 0 additions & 20 deletions src/_sup.erl

This file was deleted.

34 changes: 17 additions & 17 deletions webmachine.template
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
%%-*- mode: erlang -*-
{description, "Generates an empty WebMachine application"}.
{description, "OTP Release structure for executable Webmachine programs"}.
{variables, [
{name, "wmskel", "name of the application to build"},
{prefix, ".", "path where the application should be created"}
{name, "myapp", "Name of the OTP release. An app with this name will also be created."},
{desc, "A Webmachine Service", "Short description of the release's main app's purpose"}
]}.

%% main project files
{template, "_README.md", "{{prefix}}/README.md"}.
{template, "Makefile", "{{prefix}}/Makefile"}.
{template, "rebar.config", "{{prefix}}/rebar.config"}.
{template, "relx.config", "{{prefix}}/relx.config"}.
{template, "dot.gitignore", "{{prefix}}/.gitignore"}.
{template, "webmachine/Makefile", "{{name}}/Makefile"}.
{template, "webmachine/app.erl", "{{name}}/{{apps_dir}}/{{name}}/src/{{name}}_app.erl"}.
{template, "webmachine/sup.erl", "{{name}}/{{apps_dir}}/{{name}}/src/{{name}}_sup.erl"}.
{template, "webmachine/config.erl", "{{name}}/{{apps_dir}}/{{name}}/src/{{name}}_config.erl"}.
{template, "webmachine/resource.erl", "{{name}}/{{apps_dir}}/{{name}}/src/{{name}}_resource.erl"}.
{template, "webmachine/top.erl", "{{name}}/{{apps_dir}}/{{name}}/src/{{name}}.erl"}.
{template, "webmachine/otp_app.app.src", "{{name}}/{{apps_dir}}/{{name}}/src/{{name}}.app.src"}.
{template, "webmachine/relx_rebar.config", "{{name}}/rebar.config"}.
{template, "webmachine/sys.config", "{{name}}/config/sys.config"}.
{template, "webmachine/vm.args", "{{name}}/config/vm.args"}.
{template, "webmachine/gitignore", "{{name}}/.gitignore"}.
{template, "webmachine/LICENSE", "{{name}}/LICENSE"}.
{template, "webmachine/README.md", "{{name}}/README.md"}.

{template, "src/_.app.src", "{{prefix}}/src/{{name}}.app.src"}.
{dir, "{{name}}/priv/www"}.

{template, "src/_.erl", "{{prefix}}/src/{{name}}.erl"}.
{template, "src/_app.erl", "{{prefix}}/src/{{name}}_app.erl"}.
{template, "src/_sup.erl", "{{prefix}}/src/{{name}}_sup.erl"}.
{template, "src/_config.erl", "{{prefix}}/src/{{name}}_config.erl"}.
{template, "src/_resource.erl", "{{prefix}}/src/{{name}}_resource.erl"}.

{dir, "{{prefix}}/priv/www"}.
29 changes: 29 additions & 0 deletions webmachine/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
Copyright (c) {{copyright_year}}, {{author_name}} <{{author_email}}>.
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:

* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.

* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.

* The names of its contributors may not be used to endorse or promote
products derived from this software without specific prior written
permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3 changes: 3 additions & 0 deletions Makefile → webmachine/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ all: $(REBAR3)
rel: all
@$(REBAR3) release

prod: all
@$(REBAR3) as prod release

$(REBAR3):
curl -Lo rebar3 $(REBAR3_URL) || wget $(REBAR3_URL)
chmod a+x rebar3
2 changes: 1 addition & 1 deletion _README.md → webmachine/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ You should find in this directory:
README : this file
Makefile : simple make commands
rebar.config : configuration for Rebar3
/src
{{apps_dir}}/{{name}}/src
/{{name}}.app.src : application information file for OTP
/{{name}}.erl : the public API for your app
/{{name}}_app.erl : base module for the Erlang application behavior
Expand Down
27 changes: 27 additions & 0 deletions webmachine/app.erl
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
%%%-------------------------------------------------------------------
%% @doc {{name}} public API
%% @end
%%%-------------------------------------------------------------------

-module('{{name}}_app').

-behaviour(application).

%% Application callbacks
-export([start/2
,stop/1]).

%%====================================================================
%% API
%%====================================================================

start(_StartType, _StartArgs) ->
'{{name}}_sup':start_link().

%%--------------------------------------------------------------------
stop(_State) ->
ok.

%%====================================================================
%% Internal functions
%%====================================================================
19 changes: 10 additions & 9 deletions src/_config.erl → webmachine/config.erl
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
-module({{name}}_config).

-export([
dispatch/0,
web_config/0
]).
dispatch/0,
web_config/0
]).

-spec dispatch() -> [webmachine_dispatcher:route()].
dispatch() ->
lists:flatten([
{[], {{name}}_resource, []}
]).
{[], {{name}}_resource, []}
]).

web_config() ->
{ok, App} = application:get_application(?MODULE),
{ok, Ip} = application:get_env(App, web_ip),
{ok, Port} = application:get_env(App, web_port),
[
{ip, Ip},
{port, Port},
{log_dir, "priv/log"},
{dispatch, dispatch()}
{ip, Ip},
{port, Port},
{log_dir, "priv/log"},
{dispatch, dispatch()}
].

File renamed without changes.
23 changes: 23 additions & 0 deletions webmachine/otp_app.app.src
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{application, '{{name}}',
[{description, "{{desc}}"},
{vsn, "0.1.0"},
{registered, []},
{mod, {'{{name}}_app', []}},
{applications,
[kernel,
stdlib,
inets,
crypto,
mochiweb,
webmachine
]},
{env,[
{web_ip, "0.0.0.0"},
{web_port, 8080}
]},
{modules, []},

{contributors, []},
{licenses, []},
{links, []}
]}.
23 changes: 23 additions & 0 deletions webmachine/relx_rebar.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{erl_opts, [debug_info]}.

{deps, [
{webmachine, "1.10.*", {git, "git://github.com/webmachine/webmachine", {branch, "develop"}}}
]}.

{relx, [{release, {'{{name}}', "0.1.0"},
['{{name}}',
sasl]},

{sys_config, "./config/sys.config"},
{vm_args, "./config/vm.args"},

{dev_mode, true},
{include_erts, false},

{extended_start_script, true}]
}.

{profiles, [{prod, [{relx, [{dev_mode, false},
{include_erts, true}]}]
}]
}.
7 changes: 4 additions & 3 deletions src/_resource.erl → webmachine/resource.erl
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
-module({{name}}_resource).
-export([
init/1,
to_html/2
]).
init/1,
to_html/2
]).

-include_lib("webmachine/include/webmachine.hrl").

Expand All @@ -13,3 +13,4 @@ init([]) ->
-spec to_html(wrq:reqdata(), term()) -> {iodata(), wrq:reqdata(), term()}.
to_html(ReqData, State) ->
{"<html><body>Hello, new world</body></html>", ReqData, State}.

39 changes: 39 additions & 0 deletions webmachine/sup.erl
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
%%%-------------------------------------------------------------------
%% @doc {{name}} top level supervisor.
%% @end
%%%-------------------------------------------------------------------

-module('{{name}}_sup').

-behaviour(supervisor).

%% API
-export([start_link/0]).

%% Supervisor callbacks
-export([init/1]).

-define(SERVER, ?MODULE).

%%====================================================================
%% API functions
%%====================================================================

start_link() ->
supervisor:start_link({local, ?SERVER}, ?MODULE, []).

%%====================================================================
%% Supervisor callbacks
%%====================================================================

%% Child :: {Id,StartFunc,Restart,Shutdown,Type,Modules}
init([]) ->
Web = {webmachine_mochiweb,
{webmachine_mochiweb, start, [{{name}}_config:web_config()]},
permanent, 5000, worker, [mochiweb_socket_server]},
Processes = [Web],
{ok, { {one_for_one, 10, 10}, Processes} }.

%%====================================================================
%% Internal functions
%%====================================================================
3 changes: 3 additions & 0 deletions webmachine/sys.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[
{'{{name}}', []}
].
1 change: 1 addition & 0 deletions src/_.erl → webmachine/top.erl
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,4 @@ resolve_deps(App) ->
is_otp_base_app(kernel) -> true;
is_otp_base_app(stdlib) -> true;
is_otp_base_app(_) -> false.

6 changes: 6 additions & 0 deletions webmachine/vm.args
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
-name {{name}}@127.0.0.1

-setcookie {{name}}_cookie

+K true
+A30