Permalink
Browse files

initial commit

  • Loading branch information...
0 parents commit 9c603280c5608ff9af733722763f8e0ccd9f7d5c @cloudhead committed Jul 26, 2011
Showing with 317 additions and 0 deletions.
  1. +60 −0 README
  2. +45 −0 erlapp.Makefile
  3. +18 −0 erlapp.app.src
  4. +1 −0 erlapp.dev/sync
  5. +17 −0 erlapp.erl
  6. +7 −0 erlapp.gitignore
  7. +1 −0 erlapp.hrl
  8. +9 −0 erlapp.rebar.config
  9. +21 −0 erlapp.start.args
  10. +9 −0 erlapp.start.sh
  11. +23 −0 erlapp.template
  12. +21 −0 erlapp_app.erl
  13. +53 −0 erlapp_server.erl
  14. +32 −0 erlapp_sup.erl
60 README
@@ -0,0 +1,60 @@
+
+
+ erlapp.template
+
+ a basic erlang/OTP application skeleton
+
+This is a minimal erlang/OTP app, with everything you need to get up and
+running. It tries to follow best practices, while providing everything necessary
+to start development.
+Compared to rebar's "create-app", erlapp is much more complete. It includes
+the following files and folders:
+
+ ebin/ % .app and .beam files
+ deps/ % dependencies
+ dev/
+ | start % startup script
+ | start.args % startup arguments
+ |
+ priv/ % application-specific files
+ src/
+ | erlapp.app.src % erlapp.app template
+ | erlapp.erl % entry-point
+ | erlapp_app.erl % application
+ | erlapp_sup.erl % supervisor
+ | erlapp_server.erl % gen_server
+ |
+ Makefile
+ rebar.config
+ .gitignore
+
+erlapp also comes with the sync <https://github.com/rustyio/sync> utility,
+which recompiles and reloads changed code.
+
+install
+-------
+
+Make sure you have the latest version of rebar installed.
+
+ $ mkdir -p ~/.rebar/templates
+ $ git clone https://github.com/cloudhead/erlapp.template ~/.rebar/templates
+
+setup
+-----
+
+Create the app skeleton, set `appid` to the app name
+
+ $ rebar create template=erlapp appid=myapp
+
+Build the application
+
+ $ make all
+
+Start the development console
+
+ $ dev/start
+
+Modules should get recompiled/reloaded when their source is changed. You can also
+compile the whole project with `make`. Check the Makefile for additional commands.
+
+
45 erlapp.Makefile
@@ -0,0 +1,45 @@
+
+REBAR = rebar
+APP = {{appid}}
+
+default: compile
+
+all: deps compile sync
+
+compile:
+ $(REBAR) compile
+
+deps:
+ $(REBAR) get-deps
+
+clean:
+ $(REBAR) clean
+
+generate:
+ $(REBAR) generate
+ chmod u+x rel/$(APP)/bin/$(APP)
+
+sync:
+ cd dev/sync && make && cd -
+
+distclean: clean
+ $(REBAR) delete-deps
+
+console:
+ rel/$(APP)/bin/$(APP) console -pa ../../ebin
+
+rebuild:
+ $(REBAR) clean compile generate
+ chmod u+x rel/$(APP)/bin/$(APP)
+
+eunit:
+ $(REBAR) skip_deps=true eunit
+
+docs: deps
+ $(REBAR) skip_deps=true doc
+
+dialyzer: compile
+ @dialyzer -Wno_return -c apps/$(APP)/ebin
+
+.PHONY: deps
+
18 erlapp.app.src
@@ -0,0 +1,18 @@
+{application, {{appid}}, [
+ {description, ""},
+ {vsn, "1"},
+ {registered, []},
+ {modules, [
+ {{appid}}_app,
+ {{appid}}_sup,
+ {{appid}}_server
+ ]},
+ {applications, [
+ kernel,
+ stdlib
+ ]},
+ {mod, {
+ {{appid}}_app, []
+ }},
+ {env, []}
+]}.
1 erlapp.dev/sync
@@ -0,0 +1 @@
+Subproject commit ce6edadc0f1acb60cc826e4b50b06d67784c46ff
17 erlapp.erl
@@ -0,0 +1,17 @@
+%%
+%% {{appid}}.erl
+%% {{appid}} entry point
+%%
+-module({{appid}}).
+
+-export([start/0, start_link/0, stop/0]).
+
+start_link() ->
+ {{appid}}_sup:start_link().
+
+start() ->
+ application:start({{appid}}).
+
+stop() ->
+ application:stop({{appid}}).
+
7 erlapp.gitignore
@@ -0,0 +1,7 @@
+*.beam
+.eunit
+deps/*
+apps/{{appid}}/ebin
+dev/*
+rel/{{nodeid}}
+
1 erlapp.hrl
@@ -0,0 +1 @@
+-define(PRINT(Var), io:format("~p:~p: ~p = ~p~n", [?MODULE, ?LINE, ??Var, Var])).
9 erlapp.rebar.config
@@ -0,0 +1,9 @@
+{sub_dirs, ["rel"]}.
+{lib_dirs, ["deps"]}.
+{deps, [
+ % {misultin, ".*", {git, "git://github.com/ostinelli/misultin", {branch, "master"}}},
+ % {json, ".*", {git, "git://github.com/davisp/eep0018", {branch, "master"}}},
+ % {webmachine, ".*", {git, "git://github.com/basho/webmachine", {branch, "master"}}},
+ % {riakc, ".*", {git, "git://github.com/basho/riak-erlang-client", {branch, "master"}}}
+]}.
+
21 erlapp.start.args
@@ -0,0 +1,21 @@
+
+# Start SASL
+-boot start_sasl
+
+# Start main application
+-s {{appid}}
+
+# Start 'sync' script, for auto-reloading
+-s sync
+
+# Node name
+-name {{appid}}@127.0.0.1
+
+# Cookie name
+-setcookie riak
+
+# Kernel polling
++K true
+
+# 4 async threads
++A 4
9 erlapp.start.sh
@@ -0,0 +1,9 @@
+#!/bin/sh
+
+echo Starting {{appid}} with development console..
+
+exec erl -pa $PWD/ebin\
+ -pa $PWD/deps/*/ebin\
+ -pa $PWD/dev/*/ebin\
+ -args_file `dirname $0`/start.args
+
23 erlapp.template
@@ -0,0 +1,23 @@
+{variables, [{appid, "myapp"}]}.
+
+{template, "erlapp.app.src", "src/{{appid}}.app.src"}.
+{template, "erlapp_app.erl", "src/{{appid}}_app.erl"}.
+{template, "erlapp_server.erl", "src/{{appid}}_server.erl"}.
+{template, "erlapp_sup.erl", "src/{{appid}}_sup.erl"}.
+{template, "erlapp.erl", "src/{{appid}}.erl"}.
+{template, "erlapp.hrl", "src/{{appid}}.hrl"}.
+{template, "erlapp.rebar.config", "rebar.config"}.
+{template, "erlapp.start.args", "dev/start.args"}.
+{template, "erlapp.start.sh", "dev/start"}.
+{template, "erlapp.Makefile", "Makefile"}.
+{template, "erlapp.gitignore", ".gitignore"}.
+{template, "README", "README"}.
+
+{chmod, 8#0744, "dev/start"}.
+{copy, "erlapp.dev", "dev"}.
+
+{dir, "deps"}.
+{dir, "src"}.
+{dir, "priv"}.
+{dir, "ebin"}.
+
21 erlapp_app.erl
@@ -0,0 +1,21 @@
+%%
+%% {{appid}}_app.erl
+%% {{appid}} application
+%%
+-module({{appid}}_app).
+
+-behaviour(application).
+
+%% Application callbacks
+-export([start/2, stop/1]).
+
+%% ~~~~~~~~~~~~~~~~~~~~~
+%% Application callbacks
+%% ~~~~~~~~~~~~~~~~~~~~~
+
+start(_StartType, _StartArgs) ->
+ {{appid}}_sup:start_link().
+
+stop(_State) ->
+ ok.
+
53 erlapp_server.erl
@@ -0,0 +1,53 @@
+%%
+%% {{appid}}_server.erl
+%% {{appid}} server
+%%
+-module({{appid}}_server).
+-behaviour(gen_server).
+-define(SERVER, ?MODULE).
+
+%% ~~~~~~~~~~~~~~~~~~~~
+%% API Function Exports
+%% ~~~~~~~~~~~~~~~~~~~~
+
+-export([start_link/0]).
+
+%% ~~~~~~~~~~~~~~~~~~~~~~~~~~~
+%% gen_server Function Exports
+%% ~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+-export([init/1, handle_call/3, handle_cast/2, handle_info/2, terminate/2, code_change/3]).
+
+%% ~~~~~~~~~~~~~~~~~~~~~~~~
+%% API Function Definitions
+%% ~~~~~~~~~~~~~~~~~~~~~~~~
+
+start_link() ->
+ gen_server:start_link({local, ?SERVER}, ?MODULE, [], []).
+
+%% ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+%% gen_server Function Definitions
+%% ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+init(Args) ->
+ {ok, Args}.
+
+handle_call(_Request, _From, State) ->
+ {noreply, ok, State}.
+
+handle_cast(_Msg, State) ->
+ {noreply, State}.
+
+handle_info(_Info, State) ->
+ {noreply, State}.
+
+terminate(_Reason, _State) ->
+ ok.
+
+code_change(_OldVsn, State, _Extra) ->
+ {ok, State}.
+
+%% ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+%% Internal Function Definitions
+%% ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
32 erlapp_sup.erl
@@ -0,0 +1,32 @@
+%%
+%% {{appid}}_sup.erl
+%% {{appid}} supervisor
+%%
+-module({{appid}}_sup).
+
+-behaviour(supervisor).
+
+%% API
+-export([start_link/0]).
+
+%% Supervisor callbacks
+-export([init/1]).
+
+%% Helper macro for declaring children of supervisor
+-define(CHILD(I, Type), {I, {I, start_link, []}, permanent, 5000, Type, [I]}).
+
+%% ~~~~~~~~~~~~~
+%% API functions
+%% ~~~~~~~~~~~~~
+
+start_link() ->
+ supervisor:start_link({local, ?MODULE}, ?MODULE, []).
+
+%% ~~~~~~~~~~~~~~~~~~~~
+%% Supervisor callbacks
+%% ~~~~~~~~~~~~~~~~~~~~
+
+init([]) ->
+ Server = ?CHILD({{appid}}_server, worker),
+ {ok, { {one_for_one, 5, 10}, [Server]} }.
+

0 comments on commit 9c60328

Please sign in to comment.