Skip to content
Browse files

Zotonic module Rebar template added.

This Rebar template creates the module directory structure from the
parent directory. For example, inside ${ZOTONIC_BASE}/modules you could
run:
% rebar create template=ztmod module_name=your_module \
    module_title="Your Module's Title" module_priority="500" \
    description="description of what your Zotonic module does." \
    author_name="Your Name" author_email="user@domain.com"
  • Loading branch information...
1 parent 709c8b2 commit e0ff69c8284214cf9919c9ca7e59eb18760dd8c5 @mbbx6spp committed Jan 31, 2011
Showing with 109 additions and 0 deletions.
  1. +82 −0 ztmod.erl
  2. +27 −0 ztmod.template
View
82 ztmod.erl
@@ -0,0 +1,82 @@
+%%%' HEADER
+%%% @author {{author_name}} <{{author_name}}>
+%%% @copyright {{copyright_year}} {{author_name}}
+%%% @doc gen_server-based Zotonic module:
+%%% {{description}}
+%%% @end
+
+-module(mod_{{module_name}}).
+-author('{{author_name}} <{{author_email}}>').
+-behaviour(gen_server).
+
+-mod_title("{{module_title}}").
+-mod_description("{{description}}").
+-mod_prio({{module_priority}}).
+
+-export([init/1, handle_call/3, handle_cast/2, handle_info/2, terminate/2, code_change/3]).
+-export([start_link/1]).
+
+-include_lib("zotonic.hrl").
+-record(state, {context}).
+
+%%%.
+%%%' PUBLIC API
+
+%% @doc starts gen_server implementation and caller links to the process too.
+%% @spec start_link() -> {ok, Pid} | ignore | {error, Error}
+%% where
+%% Pid = pid(),
+%% Error = {already_started, Pid} | term()
+start_link(Args) when is_list(Args) ->
+ gen_server:start_link(?MODULE, Args, []).
+
+%% @doc stops gen_server implementation process
+%% @spec stop() -> ok
+stop() ->
+ gen_server:cast(?MODULE, stop).
+
+% TODO: define public API here.
+%%%.
+%%%' CALLBACKS
+%% @private
+init(Args) ->
+ process_flag(trap_exit, true),
+ {context, Context} = proplists:lookup(context, Args),
+ {ok, #state{context=z_context:new(Context)}}.
+
+%% @private
+handle_call(Req, _From, State) ->
+ %{reply, State}.
+ {stop, {unknown_call, Req}, State}.
+
+%% @private
+handle_cast(stop, State) ->
+ {stop, normal, State};
+handle_cast(Req, State) ->
+ %{noreply, State}.
+ {stop, {unknown_call, Req}, State}.
+
+%% @private
+handle_info(_Info, State) ->
+ {noreply, State}.
+
+%% @private
+code_change(_OldVsn, State, _Extra) ->
+ {ok, State}.
+
+%% @private
+terminate(normal, _State) ->
+ ok;
+terminate(shutdown, _State) ->
+ ok;
+terminate({shutdown, _Reason}, _State) ->
+ ok;
+terminate(Reason, _State) ->
+ ok.
+
+%%%.
+%%%' PRIVATE FUNCTIONS
+% TODO: Add private helper functions here.
+
+%%%.
+%%% vim: set filetype=erlang tabstop=2 foldmarker=%%%',%%%. foldmethod=marker:
View
27 ztmod.template
@@ -0,0 +1,27 @@
+{variables, [
+ {module_name, "mymodule"},
+ {module_title, "Zotonic Module Title"},
+ {module_priority, "500"},
+ {copyright_year, "2010"},
+ {author_name, "Susan Potter"},
+ {author_email,"me@susanpotter.net"},
+ {description, "<fill in description of Zotonic module here>."}
+]}.
+{dir, ["mod_{{module_name}}"]}.
+{dir, ["mod_{{module_name}}", "actions"]}.
+{dir, ["mod_{{module_name}}", "dispatch"]}.
+%{dir, ["mod_{{module_name}}", "lib"]}.
+{dir, ["mod_{{module_name}}", "lib", "css"]}.
+{dir, ["mod_{{module_name}}", "lib", "images"]}.
+{dir, ["mod_{{module_name}}", "lib", "js"]}.
+{dir, ["mod_{{module_name}}", "lib", "apps"]}.
+{dir, ["mod_{{module_name}}", "lib", "modules"]}.
+{dir, ["mod_{{module_name}}", "lib", "misc"]}.
+{dir, ["mod_{{module_name}}", "resources"]}.
+{dir, ["mod_{{module_name}}", "models"]}.
+{dir, ["mod_{{module_name}}", "scomps"]}.
+{dir, ["mod_{{module_name}}", "services"]}.
+{dir, ["mod_{{module_name}}", "templates"]}.
+{dir, ["mod_{{module_name}}", "filters"]}.
+{dir, ["mod_{{module_name}}", "validators"]}.
+{template, "ztmod.erl", "mod_{{module_name}}/mod_{{module_name}}.erl"}.

0 comments on commit e0ff69c

Please sign in to comment.
Something went wrong with that request. Please try again.