Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge branch 'rebarify-15688'

  • Loading branch information...
commit b39bd09eb0a7c066949246d7237263f5c778c668 2 parents 80571b9 + cbc93be
David Reid authored
Showing with 225 additions and 630 deletions.
  1. +1 −0  .gitignore
  2. +20 −11 Makefile
  3. +6 −0 README
  4. +0 −20 priv/skel/Makefile
  5. +0 −33 priv/skel/src/Makefile
  6. +0 −14 priv/skel/src/skel.app
  7. +0 −30 priv/skel/src/skel.erl
  8. +0 −1  priv/skel/src/skel.hrl
  9. +0 −30 priv/skel/src/skel_app.erl
  10. +0 −51 priv/skel/src/skel_web.erl
  11. +0 −12 priv/skel/start-dev.sh
  12. +0 −3  priv/skel/start.sh
  13. +0 −40 priv/skel/support/include.mk
  14. +0 −94 priv/skel/support/run_tests.escript
  15. BIN  rebar
  16. +5 −0 rebar.config
  17. +0 −33 src/Makefile
  18. +1 −1  src/mochiweb.app.src
  19. +0 −41 support/include.mk
  20. +0 −86 support/make_app.escript
  21. +0 −94 support/run_tests.escript
  22. +5 −0 support/templates/.gitignore
  23. +22 −0 support/templates/mochiwebapp.template
  24. +1 −1  {priv/skel → support/templates/mochiwebapp_skel}/priv/www/index.html
  25. +7 −0 support/templates/mochiwebapp_skel/rebar.config
  26. +9 −0 support/templates/mochiwebapp_skel/src/mochiapp.app.src
  27. +30 −0 support/templates/mochiwebapp_skel/src/mochiapp.erl
  28. +22 −0 support/templates/mochiwebapp_skel/src/mochiapp_app.erl
  29. +4 −12 priv/skel/src/skel_deps.erl → support/templates/mochiwebapp_skel/src/mochiapp_deps.erl
  30. +17 −23 priv/skel/src/skel_sup.erl → support/templates/mochiwebapp_skel/src/mochiapp_sup.erl
  31. +69 −0 support/templates/mochiwebapp_skel/src/mochiapp_web.erl
  32. +6 −0 support/templates/mochiwebapp_skel/start-dev.sh
View
1  .gitignore
@@ -1,4 +1,5 @@
/ebin
/doc
/_test
+/.eunit
/docs
View
31 Makefile
@@ -1,20 +1,29 @@
-all: ebin/
- (cd src;$(MAKE) all)
+
+PREFIX:=../
+DEST:=$(PREFIX)$(PROJECT)
+
+REBAR=./rebar
+
+all:
+ @$(REBAR) get-deps compile
edoc:
- (cd src;$(MAKE) edoc)
+ @$(REBAR) doc
-test: ebin/
- (cd src;$(MAKE) test)
+test:
+ @rm -rf .eunit
+ @mkdir -p .eunit
+ @$(REBAR) skip_deps=true eunit
clean:
- rm -rf ebin
+ @$(REBAR) clean
-clean_plt:
- (cd src;$(MAKE) clean_plt)
+build_plt:
+ @$(REBAR) build_plt
dialyzer:
- (cd src;$(MAKE) dialyzer)
+ @$(REBAR) analyze
+
+app:
+ @$(REBAR) create template=mochiwebapp dest=$(DEST) appid=$(PROJECT)
-ebin/:
- @mkdir -p ebin
View
6 README
@@ -7,3 +7,9 @@ The master of MochiWeb is tested with R13B04 and later. A branch compatible
with R12B is maintained separately at http://github.com/lemenkov/mochiweb
The R12B branch of that repository is mirrored in the official repository
occasionally for convenience.
+
+To create a new mochiweb using project:
+ make app PROJECT=project_name
+
+To create a new mochiweb using project in a specific directory:
+ make app PROJECT=project_name PREFIX=$HOME/projects/
View
20 priv/skel/Makefile
@@ -1,20 +0,0 @@
-all: ebin/
- (cd src;$(MAKE) all)
-
-edoc:
- (cd src;$(MAKE) edoc)
-
-test:
- (cd src;$(MAKE) test)
-
-clean:
- (cd src;$(MAKE) clean)
-
-clean_plt:
- (cd src;$(MAKE) clean_plt)
-
-dialyzer:
- (cd src;$(MAKE) dialyzer)
-
-ebin/:
- @mkdir -p ebin
View
33 priv/skel/src/Makefile
@@ -1,33 +0,0 @@
-include ../support/include.mk
-
-APPLICATION=skel
-DOC_OPTS={dir,\"../doc\"}
-TEST_PLT=$(TEST_DIR)/dialyzer_plt
-
-all: $(EBIN_FILES)
-
-debug:
- $(MAKE) DEBUG=-DDEBUG
-
-clean:
- rm -rf $(EBIN_FILES)
-
-edoc:
- $(ERL) -noshell -pa ../ebin \
- -eval "edoc:application($(APPLICATION), \".\", [$(DOC_OPTS)])" \
- -s init stop
-
-test: $(EBIN_FILES)
- mkdir -p $(TEST_DIR);
- @../support/run_tests.escript $(EBIN_DIR) | tee $(TEST_DIR)/test.log
-
-$(TEST_PLT):
- mkdir -p $(TEST_DIR)
- cp $(DIALYZER_PLT) $(TEST_PLT)
- dialyzer --plt $(TEST_PLT) --add_to_plt -r ../deps/*/ebin
-
-clean_plt:
- rm $(TEST_PLT)
-
-dialyzer: $(TEST_PLT)
- dialyzer --src --plt $(TEST_PLT) -DNOTEST -DDIALYZER -c ../src | tee $(TEST_DIR)/dialyzer.log
View
14 priv/skel/src/skel.app
@@ -1,14 +0,0 @@
-{application, skel,
- [{description, "skel"},
- {vsn, "0.01"},
- {modules, [
- skel,
- skel_app,
- skel_sup,
- skel_web,
- skel_deps
- ]},
- {registered, []},
- {mod, {skel_app, []}},
- {env, []},
- {applications, [kernel, stdlib, crypto]}]}.
View
30 priv/skel/src/skel.erl
@@ -1,30 +0,0 @@
-%% @author author <author@example.com>
-%% @copyright YYYY author.
-
-%% @doc TEMPLATE.
-
--module(skel).
--author('author <author@example.com>').
--export([start/0, stop/0]).
-
-ensure_started(App) ->
- case application:start(App) of
- ok ->
- ok;
- {error, {already_started, App}} ->
- ok
- end.
-
-%% @spec start() -> ok
-%% @doc Start the skel server.
-start() ->
- skel_deps:ensure(),
- ensure_started(crypto),
- application:start(skel).
-
-%% @spec stop() -> ok
-%% @doc Stop the skel server.
-stop() ->
- Res = application:stop(skel),
- application:stop(crypto),
- Res.
View
1  priv/skel/src/skel.hrl
@@ -1 +0,0 @@
-
View
30 priv/skel/src/skel_app.erl
@@ -1,30 +0,0 @@
-%% @author author <author@example.com>
-%% @copyright YYYY author.
-
-%% @doc Callbacks for the skel application.
-
--module(skel_app).
--author('author <author@example.com>').
-
--behaviour(application).
--export([start/2, stop/1]).
-
-
-%% @spec start(_Type, _StartArgs) -> ServerRet
-%% @doc application start callback for skel.
-start(_Type, _StartArgs) ->
- skel_deps:ensure(),
- skel_sup:start_link().
-
-%% @spec stop(_State) -> ServerRet
-%% @doc application stop callback for skel.
-stop(_State) ->
- ok.
-
-
-%%
-%% Tests
-%%
--include_lib("eunit/include/eunit.hrl").
--ifdef(TEST).
--endif.
View
51 priv/skel/src/skel_web.erl
@@ -1,51 +0,0 @@
-%% @author author <author@example.com>
-%% @copyright YYYY author.
-
-%% @doc Web server for skel.
-
--module(skel_web).
--author('author <author@example.com>').
-
--export([start/1, stop/0, loop/2]).
-
-%% External API
-
-start(Options) ->
- {DocRoot, Options1} = get_option(docroot, Options),
- Loop = fun (Req) ->
- ?MODULE:loop(Req, DocRoot)
- end,
- mochiweb_http:start([{name, ?MODULE}, {loop, Loop} | Options1]).
-
-stop() ->
- mochiweb_http:stop(?MODULE).
-
-loop(Req, DocRoot) ->
- "/" ++ Path = Req:get(path),
- case Req:get(method) of
- Method when Method =:= 'GET'; Method =:= 'HEAD' ->
- case Path of
- _ ->
- Req:serve_file(Path, DocRoot)
- end;
- 'POST' ->
- case Path of
- _ ->
- Req:not_found()
- end;
- _ ->
- Req:respond({501, [], []})
- end.
-
-%% Internal API
-
-get_option(Option, Options) ->
- {proplists:get_value(Option, Options), proplists:delete(Option, Options)}.
-
-
-%%
-%% Tests
-%%
--include_lib("eunit/include/eunit.hrl").
--ifdef(TEST).
--endif.
View
12 priv/skel/start-dev.sh
@@ -1,12 +0,0 @@
-#!/bin/sh
-cd `dirname $0`
-
-MAKE=make
-case `uname` in
-*BSD)
- MAKE=gmake
- ;;
-esac
-
-"${MAKE}"
-exec erl -pa $PWD/ebin $PWD/deps/*/ebin -boot start_sasl -s reloader -s skel
View
3  priv/skel/start.sh
@@ -1,3 +0,0 @@
-#!/bin/sh
-cd `dirname $0`
-exec erl -pa $PWD/ebin $PWD/deps/*/ebin -boot start_sasl -s skel
View
40 priv/skel/support/include.mk
@@ -1,40 +0,0 @@
-## -*- makefile -*-
-
-######################################################################
-## Erlang
-
-ERL := erl
-ERLC := $(ERL)c
-
-INCLUDE_DIRS := ../include $(wildcard ../deps/*/include)
-EBIN_DIRS := $(wildcard ../deps/*/ebin)
-ERLC_FLAGS := -W $(INCLUDE_DIRS:../%=-I ../%) $(EBIN_DIRS:%=-pa %)
-
-ifndef no_debug_info
- ERLC_FLAGS += +debug_info
-endif
-
-ifdef debug
- ERLC_FLAGS += -Ddebug
-endif
-
-EBIN_DIR := ../ebin
-TEST_DIR := ../_test
-EMULATOR := beam
-
-ERL_SOURCES := $(wildcard *.erl)
-ERL_HEADERS := $(wildcard *.hrl) $(wildcard ../include/*.hrl)
-ERL_OBJECTS := $(ERL_SOURCES:%.erl=$(EBIN_DIR)/%.$(EMULATOR))
-ERL_OBJECTS_LOCAL := $(ERL_SOURCES:%.erl=./%.$(EMULATOR))
-APP_FILES := $(wildcard *.app)
-EBIN_FILES = $(ERL_OBJECTS) $(APP_FILES:%.app=../ebin/%.app)
-MODULES = $(ERL_SOURCES:%.erl=%)
-
-../ebin/%.app: %.app
- cp $< $@
-
-$(EBIN_DIR)/%.$(EMULATOR): %.erl
- $(ERLC) $(ERLC_FLAGS) -o $(EBIN_DIR) $<
-
-./%.$(EMULATOR): %.erl
- $(ERLC) $(ERLC_FLAGS) -o . $<
View
94 priv/skel/support/run_tests.escript
@@ -1,94 +0,0 @@
-#!/usr/bin/env escript
-%% -*- erlang -*-
-%%! -name mochiweb__test@127.0.0.1
-main([Ebin]) ->
- code:add_path(Ebin),
- code:add_paths(filelib:wildcard("../deps/*/ebin", Ebin)),
- code:add_paths(filelib:wildcard("../deps/*/deps/*/ebin", Ebin)),
-
- ModuleNames = [hd(string:tokens(M, "."))
- || "../src/" ++ M <- filelib:wildcard("../src/*.erl")],
-
- {ok, NonTestRe} = re:compile("_tests$"),
- Modules = [list_to_atom(M) ||
- M <- lists:filter(
- fun(M) ->
- nomatch == re:run(M, NonTestRe)
- end,
- ModuleNames)],
-
-
- crypto:start(),
- start_cover(Modules),
- eunit:test(Modules, [verbose,{report,{eunit_surefire,[{dir,"../_test"}]}}]),
- analyze_cover(Modules);
-main(_) ->
- io:format("usage: run_tests.escript EBIN_DIR~n"),
- halt(1).
-
-start_cover(Modules) ->
- {ok, _Cover} = cover:start(),
- io:format("Cover compiling...~n"),
- Compiled = [ M || {ok, M} <- [ cover:compile(
- M,
- [{i, "include"}
- ])
- || M <- Modules ] ],
- case length(Modules) == length(Compiled) of
- true -> ok;
- false ->
- io:format("Warning: the following modules were not"
- " cover-compiled:~n ~p~n", [Compiled])
- end.
-
-analyze_cover(Modules) ->
- io:format("Analyzing cover...~n"),
- CoverBase = filename:join(["..", "_test", "cover"]),
- ok = filelib:ensure_dir(filename:join([CoverBase, "fake"])),
- Coverages = lists:foldl(
- fun(M, Acc) ->
- [analyze_module(CoverBase, M)|Acc]
- end,
- [], Modules),
- IndexFilename = filename:join([CoverBase, "index.html"]),
- {ok, Index} = file:open(IndexFilename, [write]),
- {LineTotal, CoverTotal} =
- lists:foldl(fun({_,_,Lines,Covered}, {LineAcc, CovAcc}) ->
- {LineAcc+Lines, CovAcc+Covered}
- end, {0,0}, Coverages),
- file:write(Index,
- "<html><head><title>Coverage</title></head>\n"
- "<body><h1>Coverage</h1><ul>\n"),
- file:write(Index,
- io_lib:format("<h2>Total: ~.2f%</h2>\n",
- [percentage(CoverTotal, LineTotal)])),
- [ file:write(Index,
- io_lib:format(
- "<li><a href=\"~s\">~p</a>: ~.2f%</li>~n",
- [Filename, Module, percentage(Covered, Lines)]))
- || {Filename, Module, Lines, Covered} <- Coverages ],
- file:write(Index,"</ul></body></html>"),
- file:close(Index),
- io:format("Cover analysis in ~s~n", [IndexFilename]).
-
-analyze_module(CoverBase, Module) ->
- {ok, Filename} =
- cover:analyze_to_file(
- Module,
- filename:join(CoverBase, atom_to_list(Module)++".COVER.html"),
- [html]),
- Lines = count_lines(Filename, "[[:digit:]]\.\.|"),
- Covered = count_lines(Filename, "[[:space:]]0\.\.|"),
- {filename:basename(Filename), Module, Lines, Lines-Covered}.
-
-count_lines(Filename, Pattern) ->
- {ok, [Lines],_} = io_lib:fread(
- "~d",
- os:cmd(io_lib:format("grep -e \"~s\" ~s | wc -l",
- [Pattern, Filename]))),
- Lines.
-
-percentage(_, 0) -> 1000.0;
-percentage(Part, Total) ->
- (Part/Total)*100.
-
View
BIN  rebar
Binary file not shown
View
5 rebar.config
@@ -0,0 +1,5 @@
+% -*- mode: erlang -*-
+{erl_opts, [debug_info]}.
+{cover_enabled, true}.
+{eunit_opts, [verbose, {report,{eunit_surefire,[{dir,"."}]}}]}.
+{template_dir, "support/templates/"}.
View
33 src/Makefile
@@ -1,33 +0,0 @@
-include ../support/include.mk
-
-APPLICATION=mochiweb
-DOC_OPTS={dir,\"../doc\"}
-TEST_PLT=$(TEST_DIR)/dialyzer_plt
-
-all: $(EBIN_FILES)
-
-debug:
- $(MAKE) DEBUG=-DDEBUG
-
-clean:
- rm -rf $(EBIN_FILES)
-
-edoc:
- $(ERL) -noshell -pa ../ebin \
- -eval "edoc:application($(APPLICATION), \".\", [$(DOC_OPTS)])" \
- -s init stop
-
-test: $(EBIN_FILES)
- mkdir -p $(TEST_DIR);
- @../support/run_tests.escript $(EBIN_DIR) | tee $(TEST_DIR)/test.log
-
-$(TEST_PLT):
- mkdir -p $(TEST_DIR)
- cp $(DIALYZER_PLT) $(TEST_PLT)
- dialyzer --plt $(TEST_PLT) --add_to_plt
-
-clean_plt:
- rm $(TEST_PLT)
-
-dialyzer: $(TEST_PLT)
- dialyzer --src --plt $(TEST_PLT) -DNOTEST -DDIALYZER -c ../src | tee $(TEST_DIR)/dialyzer.log
View
2  src/mochiweb.app.src
@@ -1,7 +1,7 @@
%% This is generated from src/mochiweb.app.src
{application, mochiweb,
[{description, "MochiMedia Web Server"},
- {vsn, "1.4.1"},
+ {vsn, "1.5.0"},
{modules, []},
{registered, []},
{mod, {mochiweb_app, []}},
View
41 support/include.mk
@@ -1,41 +0,0 @@
-## -*- makefile -*-
-
-######################################################################
-## Erlang
-
-ERL := erl
-ERLC := $(ERL)c
-
-INCLUDE_DIRS := ../include $(wildcard ../deps/*/include)
-EBIN_DIRS := $(wildcard ../deps/*/ebin)
-ERLC_FLAGS := -W $(INCLUDE_DIRS:../%=-I ../%) $(EBIN_DIRS:%=-pa %)
-
-ifndef no_debug_info
- ERLC_FLAGS += +debug_info
-endif
-
-ifdef debug
- ERLC_FLAGS += -Ddebug
-endif
-
-EBIN_DIR := ../ebin
-TEST_DIR := ../_test
-EMULATOR := beam
-
-ERL_SOURCES := $(wildcard *.erl)
-ERL_HEADERS := $(wildcard *.hrl) $(wildcard ../include/*.hrl)
-ERL_OBJECTS := $(ERL_SOURCES:%.erl=$(EBIN_DIR)/%.$(EMULATOR))
-ERL_OBJECTS_LOCAL := $(ERL_SOURCES:%.erl=./%.$(EMULATOR))
-APP_FILES := $(wildcard *.app.src)
-EBIN_FILES = $(ERL_OBJECTS) $(APP_FILES:%.app.src=../ebin/%.app)
-MODULES = $(ERL_SOURCES:%.erl=%)
-
-../ebin/%.app: %.app.src
- ../support/make_app.escript $< $@ _ "$(MODULES)"
-
-
-$(EBIN_DIR)/%.$(EMULATOR): %.erl
- $(ERLC) $(ERLC_FLAGS) -o $(EBIN_DIR) $<
-
-./%.$(EMULATOR): %.erl
- $(ERLC) $(ERLC_FLAGS) -o . $<
View
86 support/make_app.escript
@@ -1,86 +0,0 @@
-#!/usr/bin/env escript
-%% -*- erlang -*-
-
-main(Args) ->
- [AppSrc,AppF,Vsn,Modules] = Args,
- {Comments, L, App} = parse_appsrc(AppSrc),
- {application, A, Attrs} = App,
- Attrs1 = [vsn(Vsn, Attrs),
- descr(Attrs),
- {modules, lists:sort([list_to_atom(M) || M <- string:tokens(Modules," ")])} |
- [Attr || {K,_} = Attr <- Attrs,
- not lists:member(K, [vsn, modules, description])]],
- write_app(AppF, Comments, L, {application, A, Attrs1}).
-
-write_app(F, Comments, TermL, App) ->
- case file:open(F, [write]) of
- {ok, Fd} ->
- try L = write_comments(Comments, Fd),
- write_term(App, L, TermL, Fd)
- after
- file:close(Fd)
- end;
- Error ->
- mochi_error(Error)
- end.
-
-parse_appsrc(F) ->
- case file:read_file(F) of
- {ok, B} ->
- case erl_scan:string(binary_to_list(B), 1, [return_comments]) of
- {ok, Toks, _} ->
- Comments = lists:takewhile(
- fun({comment,_,_}) -> true;
- (_) -> false
- end, Toks),
- TermToks = [T || T <- Toks, element(1,T) =/= comment],
- TermL = element(2, hd(TermToks)),
- case erl_parse:parse_term(TermToks) of
- {ok, {application, _A, _Attrs} = App} ->
- {Comments, TermL, App};
- Error ->
- mochi_error(Error)
- end;
- ScanErr ->
- mochi_error(ScanErr)
- end;
- ReadErr ->
- mochi_error(ReadErr)
- end.
-
-write_comments(Comments, Fd) ->
- lists:foldl(
- fun({comment, L, C}, L0) ->
- S = ["\n" || _ <- lists:seq(1,L-L0)] ++ C,
- io:put_chars(Fd, S),
- L
- end, 1, Comments).
-
-write_term(T, L0, TermL, Fd) ->
- case ["\n" || _ <- lists:seq(1,TermL-L0)] of
- [] -> ok;
- S -> io:put_chars(Fd, S)
- end,
- io:fwrite(Fd, "~p.~n", [T]).
-
-vsn(Vsn, Attrs) when Vsn =:= '' orelse Vsn =:= "" orelse Vsn =:= "_" ->
- case lists:keyfind(vsn, 1, Attrs) of
- false ->
- {vsn, "0.00"};
- V ->
- V
- end;
-vsn(Vsn, _Attrs) ->
- {vsn, Vsn}.
-
-descr(Attrs) ->
- case lists:keyfind(description, 1, Attrs) of
- false ->
- {description, "auto_generated .app file"};
- D ->
- D
- end.
-
-mochi_error(E) ->
- io:fwrite("*** ~p~n", [E]),
- halt(1).
View
94 support/run_tests.escript
@@ -1,94 +0,0 @@
-#!/usr/bin/env escript
-%% -*- erlang -*-
-%%! -name mochiweb__test@127.0.0.1
-main([Ebin]) ->
- code:add_path(Ebin),
- code:add_paths(filelib:wildcard("../deps/*/ebin", Ebin)),
- code:add_paths(filelib:wildcard("../deps/*/deps/*/ebin", Ebin)),
-
- ModuleNames = [hd(string:tokens(M, "."))
- || "../src/" ++ M <- filelib:wildcard("../src/*.erl")],
-
- {ok, NonTestRe} = re:compile("_tests$"),
- Modules = [list_to_atom(M) ||
- M <- lists:filter(
- fun(M) ->
- nomatch == re:run(M, NonTestRe)
- end,
- ModuleNames)],
-
-
- crypto:start(),
- start_cover(Modules),
- eunit:test(Modules, [verbose,{report,{eunit_surefire,[{dir,"../_test"}]}}]),
- analyze_cover(Modules);
-main(_) ->
- io:format("usage: run_tests.escript EBIN_DIR~n"),
- halt(1).
-
-start_cover(Modules) ->
- {ok, _Cover} = cover:start(),
- io:format("Cover compiling...~n"),
- Compiled = [ M || {ok, M} <- [ cover:compile(
- M,
- [{i, "include"}
- ])
- || M <- Modules ] ],
- case length(Modules) == length(Compiled) of
- true -> ok;
- false ->
- io:format("Warning: the following modules were not"
- " cover-compiled:~n ~p~n", [Compiled])
- end.
-
-analyze_cover(Modules) ->
- io:format("Analyzing cover...~n"),
- CoverBase = filename:join(["..", "_test", "cover"]),
- ok = filelib:ensure_dir(filename:join([CoverBase, "fake"])),
- Coverages = lists:foldl(
- fun(M, Acc) ->
- [analyze_module(CoverBase, M)|Acc]
- end,
- [], Modules),
- IndexFilename = filename:join([CoverBase, "index.html"]),
- {ok, Index} = file:open(IndexFilename, [write]),
- {LineTotal, CoverTotal} =
- lists:foldl(fun({_,_,Lines,Covered}, {LineAcc, CovAcc}) ->
- {LineAcc+Lines, CovAcc+Covered}
- end, {0,0}, Coverages),
- file:write(Index,
- "<html><head><title>Coverage</title></head>\n"
- "<body><h1>Coverage</h1><ul>\n"),
- file:write(Index,
- io_lib:format("<h2>Total: ~.2f%</h2>\n",
- [percentage(CoverTotal, LineTotal)])),
- [ file:write(Index,
- io_lib:format(
- "<li><a href=\"~s\">~p</a>: ~.2f%</li>~n",
- [Filename, Module, percentage(Covered, Lines)]))
- || {Filename, Module, Lines, Covered} <- Coverages ],
- file:write(Index,"</ul></body></html>"),
- file:close(Index),
- io:format("Cover analysis in ~s~n", [IndexFilename]).
-
-analyze_module(CoverBase, Module) ->
- {ok, Filename} =
- cover:analyze_to_file(
- Module,
- filename:join(CoverBase, atom_to_list(Module)++".COVER.html"),
- [html]),
- Lines = count_lines(Filename, "[[:digit:]]\.\.|"),
- Covered = count_lines(Filename, "[[:space:]]0\.\.|"),
- {filename:basename(Filename), Module, Lines, Lines-Covered}.
-
-count_lines(Filename, Pattern) ->
- {ok, [Lines],_} = io_lib:fread(
- "~d",
- os:cmd(io_lib:format("grep -e \"~s\" ~s | wc -l",
- [Pattern, Filename]))),
- Lines.
-
-percentage(_, 0) -> 1000.0;
-percentage(Part, Total) ->
- (Part/Total)*100.
-
View
5 support/templates/.gitignore
@@ -0,0 +1,5 @@
+/ebin
+/edit
+/deps
+/erl_crash.dump
+/.eunit
View
22 support/templates/mochiwebapp.template
@@ -0,0 +1,22 @@
+%% -*- erlang -*-
+{variables, [{appid, "mochiwebapp"},
+ {author, "Mochi Media <dev@mochimedia.com>"},
+ {year, "2010"},
+ {version, "0.1"},
+ {port, 8080},
+ {dest, "{{appid}}"}]}.
+{dir, "{{dest}}"}.
+{template, "mochiwebapp_skel/src/mochiapp.app.src", "{{dest}}/src/{{appid}}.app.src"}.
+{template, "mochiwebapp_skel/src/mochiapp.erl", "{{dest}}/src/{{appid}}.erl"}.
+{template, "mochiwebapp_skel/src/mochiapp_app.erl", "{{dest}}/src/{{appid}}_app.erl"}.
+{template, "mochiwebapp_skel/src/mochiapp_deps.erl", "{{dest}}/src/{{appid}}_deps.erl"}.
+{template, "mochiwebapp_skel/src/mochiapp_sup.erl", "{{dest}}/src/{{appid}}_sup.erl"}.
+{template, "mochiwebapp_skel/src/mochiapp_web.erl", "{{dest}}/src/{{appid}}_web.erl"}.
+{template, "mochiwebapp_skel/start-dev.sh", "{{dest}}/start-dev.sh"}.
+{template, "mochiwebapp_skel/priv/www/index.html", "{{dest}}/priv/www/index.html"}.
+{file, "../../.gitignore", "{{dest}}/.gitignore"}.
+{file, "../../Makefile", "{{dest}}/Makefile"}.
+{file, "mochiwebapp_skel/rebar.config", "{{dest}}/rebar.config"}.
+{file, "../../rebar", "{{dest}}/rebar"}.
+{chmod, 8#755, "{{dest}}/rebar"}.
+{chmod, 8#755, "{{dest}}/start-dev.sh"}.
View
2  priv/skel/priv/www/index.html → ...ates/mochiwebapp_skel/priv/www/index.html
@@ -3,6 +3,6 @@
<title>It Worked</title>
</head>
<body>
-MochiWeb running.
+{{appid}} running.
</body>
</html>
View
7 support/templates/mochiwebapp_skel/rebar.config
@@ -0,0 +1,7 @@
+%% -*- erlang -*-
+{erl_opts, [debug_info]}.
+{deps, [
+ {mochiweb, ".*",
+ {git, "git://github.com/mochi/mochiweb.git", ""}}]}.
+{cover_enabled, true}.
+{eunit_opts, [verbose, {report,{eunit_surefire,[{dir,"."}]}}]}.
View
9 support/templates/mochiwebapp_skel/src/mochiapp.app.src
@@ -0,0 +1,9 @@
+%% -*- erlang -*-
+{application, {{appid}},
+ [{description, "{{appid}}"},
+ {vsn, "{{version}}"},
+ {modules, []},
+ {registered, []},
+ {mod, {'{{appid}}_app', []}},
+ {env, []},
+ {applications, [kernel, stdlib, crypto]}]}.
View
30 support/templates/mochiwebapp_skel/src/mochiapp.erl
@@ -0,0 +1,30 @@
+%% @author {{author}}
+%% @copyright {{year}} {{author}}
+
+%% @doc {{appid}}.
+
+-module({{appid}}).
+-author("{{author}}").
+-export([start/0, stop/0]).
+
+ensure_started(App) ->
+ case application:start(App) of
+ ok ->
+ ok;
+ {error, {already_started, App}} ->
+ ok
+ end.
+
+
+%% @spec start() -> ok
+%% @doc Start the {{appid}} server.
+start() ->
+ {{appid}}_deps:ensure(),
+ ensure_started(crypto),
+ application:start({{appid}}).
+
+
+%% @spec stop() -> ok
+%% @doc Stop the {{appid}} server.
+stop() ->
+ application:stop({{appid}}).
View
22 support/templates/mochiwebapp_skel/src/mochiapp_app.erl
@@ -0,0 +1,22 @@
+%% @author {{author}}
+%% @copyright {{appid}} {{author}}
+
+%% @doc Callbacks for the {{appid}} application.
+
+-module({{appid}}_app).
+-author("{{author}}").
+
+-behaviour(application).
+-export([start/2,stop/1]).
+
+
+%% @spec start(_Type, _StartArgs) -> ServerRet
+%% @doc application start callback for {{appid}}.
+start(_Type, _StartArgs) ->
+ {{appid}}_deps:ensure(),
+ {{appid}}_sup:start_link().
+
+%% @spec stop(_State) -> ServerRet
+%% @doc application stop callback for {{appid}}.
+stop(_State) ->
+ ok.
View
16 priv/skel/src/skel_deps.erl → ...es/mochiwebapp_skel/src/mochiapp_deps.erl
@@ -1,12 +1,12 @@
-%% @author author <author@example.com>
-%% @copyright YYYY author.
+%% @author {{author}}
+%% @copyright {{year}} {{author}}
%% @doc Ensure that the relatively-installed dependencies are on the code
%% loading path, and locate resources relative
%% to this application's path.
--module(skel_deps).
--author('author <author@example.com>').
+-module({{appid}}_deps).
+-author("{{author}}").
-export([ensure/0, ensure/1]).
-export([get_base_dir/0, get_base_dir/1]).
@@ -82,11 +82,3 @@ local_path(Components, Module) ->
%% Equivalent to local_path(Components, ?MODULE).
local_path(Components) ->
local_path(Components, ?MODULE).
-
-
-%%
-%% Tests
-%%
--include_lib("eunit/include/eunit.hrl").
--ifdef(TEST).
--endif.
View
40 priv/skel/src/skel_sup.erl → ...tes/mochiwebapp_skel/src/mochiapp_sup.erl
@@ -1,10 +1,10 @@
-%% @author author <author@example.com>
-%% @copyright YYYY author.
+%% @author {{author}}
+%% @copyright {{year}} {{author}}
-%% @doc Supervisor for the skel application.
+%% @doc Supervisor for the {{appid}} application.
--module(skel_sup).
--author('author <author@example.com>').
+-module({{appid}}_sup).
+-author("{{author}}").
-behaviour(supervisor).
@@ -41,22 +41,16 @@ upgrade() ->
%% @spec init([]) -> SupervisorTree
%% @doc supervisor callback.
init([]) ->
- Ip = case os:getenv("MOCHIWEB_IP") of false -> "0.0.0.0"; Any -> Any end,
- WebConfig = [
- {ip, Ip},
- {port, 8000},
- {docroot, skel_deps:local_path(["priv", "www"])}],
- Web = {skel_web,
- {skel_web, start, [WebConfig]},
- permanent, 5000, worker, dynamic},
-
+ Web = web_specs({{appid}}_web, {{port}}),
Processes = [Web],
- {ok, {{one_for_one, 10, 10}, Processes}}.
-
-
-%%
-%% Tests
-%%
--include_lib("eunit/include/eunit.hrl").
--ifdef(TEST).
--endif.
+ Strategy = {one_for_one, 10, 10},
+ {ok,
+ {Strategy, lists:flatten(Processes)}}.
+
+web_specs(Mod, Port) ->
+ WebConfig = [{ip, {0,0,0,0}},
+ {port, Port},
+ {docroot, {{appid}}_deps:local_path(["priv", "www"])}],
+ {Mod,
+ {Mod, start, [WebConfig]},
+ permanent, 5000, worker, dynamic}.
View
69 support/templates/mochiwebapp_skel/src/mochiapp_web.erl
@@ -0,0 +1,69 @@
+%% @author {{author}}
+%% @copyright {{year}} {{author}}
+
+%% @doc Web server for {{appid}}.
+
+-module({{appid}}_web).
+-author("{{author}}").
+
+-export([start/1, stop/0, loop/2]).
+
+%% External API
+
+start(Options) ->
+ {DocRoot, Options1} = get_option(docroot, Options),
+ Loop = fun (Req) ->
+ ?MODULE:loop(Req, DocRoot)
+ end,
+ mochiweb_http:start([{name, ?MODULE}, {loop, Loop} | Options1]).
+
+stop() ->
+ mochiweb_http:stop(?MODULE).
+
+loop(Req, DocRoot) ->
+ "/" ++ Path = Req:get(path),
+ try
+ case Req:get(method) of
+ Method when Method =:= 'GET'; Method =:= 'HEAD' ->
+ case Path of
+ _ ->
+ Req:serve_file(Path, DocRoot)
+ end;
+ 'POST' ->
+ case Path of
+ _ ->
+ Req:not_found()
+ end;
+ _ ->
+ Req:respond({501, [], []})
+ end
+ catch
+ Type:What ->
+ Report = ["web request failed",
+ {path, Path},
+ {type, Type}, {what, What},
+ {trace, erlang:get_stacktrace()}],
+ error_logger:error_report(Report),
+ %% NOTE: mustache templates need \\ because they are not awesome.
+ Req:respond({500, [{"Content-Type", "text/plain"}],
+ "request failed, sorry\\n"})
+ end.
+
+%% Internal API
+
+get_option(Option, Options) ->
+ {proplists:get_value(Option, Options), proplists:delete(Option, Options)}.
+
+%%
+%% Tests
+%%
+-ifdef(TEST).
+-include_lib("eunit/include/eunit.hrl").
+
+you_should_write_a_test() ->
+ ?assertEqual(
+ "No, but I will!",
+ "Have you written any tests?"),
+ ok.
+
+-endif.
View
6 support/templates/mochiwebapp_skel/start-dev.sh
@@ -0,0 +1,6 @@
+#!/bin/sh
+# NOTE: mustache templates need \\ because they are not awesome.
+exec erl -pa ebin edit deps/*/ebin -boot start_sasl \\
+ -sname {{appid}}_dev \\
+ -s {{appid}} \\
+ -s reloader
Please sign in to comment.
Something went wrong with that request. Please try again.