Anonymous avatar Anonymous committed 8d219a5

init commit

Comments (0)

Files changed (23)

+{ './src/*', [
+	{ i, "./include" },
+	{ i, "{{nitro_dir}}/apps" },
+	{ outdir, "./ebin" },
+	debug_info
+]}.
+Copyright (c) 2010, {{name}}
+ 
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
+
+all:
+	erl -make
+
+init:
+	-mkdir ebin
+	-mkdir dep
+	-mkdir -p www/css/
+	-mkdir -p www/js
+	-mkdir -p www/nitrogen
+	-(cd www/nitrogen; ln -s {{nitro_dir}}/apps/nitrogen/www/nitrogen.css .)
+	-(cd www/nitrogen; ln -s {{nitro_dir}}/apps/nitrogen/www/nitrogen.js .)
+	-(cd www/nitrogen; ln -s {{nitro_dir}}/apps/nitrogen/www/livevalidation.js .)
+	-mkdir templates
+	-chmod +x ./start.sh
+	-(for i in \`ls dep/*\`; do cd \${i}; make; done)
+	cp src/{{appid}}.app.src ebin/{{appid}}.app 
+	$(MAKE) all
+
+clean:
+	rm -rf ./ebin/*.beam
+
+SETUP
+----
+In the {{appid}} directory:
+
+ make init
+
+To compile the source code of the {{appid}} application:
+
+ make
+
+
+
+%% @author {{name}} {{email}}
+%% @copyright YYYY {{name}}.
+
+%% @doc Various config/check functions, e.g:
+%%      Ensure that the relatively-installed dependencies are on the code
+%%      loading path, and locate resources relative
+%%      to this application's path.
+
+-module({{appid}}_deps).
+
+-export([get_env/2
+         , ensure/0
+         , ensure/1
+         , get_base_dir/0
+         , get_base_dir/1
+         , local_path/1
+         , local_path/2
+         , deps_on_path/0
+         , new_siblings/1
+        ]).
+
+%% @spec get_env() -> String
+%% @doc Get an application environment variable; fallback to a default value.
+get_env(Key, Default) ->
+    case application:get_env({{appid}}, Key) of
+        {ok, Value} -> Value;
+        _           -> Default
+    end.
+
+%% @spec deps_on_path() -> [ProjNameAndVers]
+%% @doc List of project dependencies on the path.
+deps_on_path() ->
+    F = fun (X, Acc) ->
+                ProjDir = filename:dirname(X),
+                case {filename:basename(X),
+                      filename:basename(filename:dirname(ProjDir))} of
+                    {"ebin", "deps"} ->
+                        [filename:basename(ProjDir) | Acc];
+                    _ ->
+                        Acc
+                end
+        end,
+    ordsets:from_list(lists:foldl(F, [], code:get_path())).
+    
+%% @spec new_siblings(Module) -> [Dir]
+%% @doc Find new siblings paths relative to Module that aren't already on the
+%%      code path.
+new_siblings(Module) ->
+    Existing = deps_on_path(),
+    SiblingEbin = filelib:wildcard(local_path(["deps", "*", "ebin"], Module)),
+    Siblings = [filename:dirname(X) || X <- SiblingEbin,
+                           ordsets:is_element(
+                             filename:basename(filename:dirname(X)),
+                             Existing) =:= false],
+    lists:filter(fun filelib:is_dir/1, 
+                 lists:append([[filename:join([X, "ebin"]),
+                                filename:join([X, "include"])] ||
+                                  X <- Siblings])).
+        
+
+%% @spec ensure(Module) -> ok
+%% @doc Ensure that all ebin and include paths for dependencies
+%%      of the application for Module are on the code path.
+ensure(Module) ->
+    code:add_paths(new_siblings(Module)),
+    code:clash(),
+    ok.
+
+%% @spec ensure() -> ok
+%% @doc Ensure that the ebin and include paths for dependencies of
+%%      this application are on the code path. Equivalent to
+%%      ensure(?Module).
+ensure() ->
+    ensure(?MODULE).
+
+%% @spec get_base_dir(Module) -> string()
+%% @doc Return the application directory for Module. It assumes Module is in
+%%      a standard OTP layout application in the ebin or src directory.
+get_base_dir(Module) ->
+    {file, Here} = code:is_loaded(Module),
+    filename:dirname(filename:dirname(Here)).
+
+%% @spec get_base_dir() -> string()
+%% @doc Return the application directory for this application. Equivalent to
+%%      get_base_dir(?MODULE).
+get_base_dir() ->
+    get_base_dir(?MODULE).
+
+%% @spec local_path([string()], Module) -> string()
+%% @doc Return an application-relative directory from Module's application.
+local_path(Components, Module) ->
+    filename:join([get_base_dir(Module) | Components]).
+
+%% @spec local_path(Components) -> string()
+%% @doc Return an application-relative directory for this application.
+%%      Equivalent to local_path(Components, ?MODULE).
+local_path(Components) ->
+    local_path(Components, ?MODULE).
+{application, {{appid}}, 
+ [
+  {description,  "{{appid}} - bla bla..."},
+
+  % The Module and Args used to start this application.
+  {mod, { {{appid}}_app, []} },
+
+  % All modules used by the application.
+  {modules,
+   [{{appid}}_app
+    ,{{appid}}_deps
+   ]},
+
+  % configuration parameters similar to those in the config file specified on the command line
+  {env, [{ip, "0.0.0.0"}
+         ,{port, 8282}
+	 ,{log_dir, "/tmp"}
+	 ,{doc_root, "./www"}
+	]}
+ ]
+}.
+%% @author {{name}} {{email}}
+%% @copyright YYYY {{name}}.
+
+-module({{appid}}_common).
+-include_lib ("nitrogen/include/wf.hrl").
+-export([header/1
+         , footer/0
+         , right/0
+         , left/0
+        ]).
+
+
+right() ->
+    #panel { class=menu, body=["RIGHT"] }.
+
+
+left() ->
+    #panel { class=menu, body=["LEFT"] }.
+
+
+header(Selected) ->
+    wf:wire(Selected, #add_class { class=selected }),
+    #panel { class=menu, body=[
+        #link { id=home,  url='/',         text="HOME"  },
+        #link { id=load,  url='/load',     text="LOAD"  },
+        #link { id=about, url='/about',    text="ABOUT" }
+    ]}.
+
+
+footer() ->
+    #panel { class=credits, body=[
+        "
+        Copyright &copy; 2010 <a href='http://www.redhoterlang.com'>{{name}}</a>. 
+        Released under the MIT License.
+        "
+    ]}.
+

nitro.grid.template

+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+  <head>
+    <title>[[[page:title()]]]</title>
+    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.1/jquery.min.js"></script>
+    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.0/jquery-ui.min.js"></script>
+    <script src='/nitrogen/livevalidation.js' type='text/javascript' charset='utf-8'></script>
+    <script src='/nitrogen/nitrogen.js' type='text/javascript' charset='utf-8'></script>
+    <link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/smoothness/jquery-ui.css" type="text/css" media="screen" charset="utf-8" />
+    <link rel="stylesheet" href="/nitrogen/nitrogen.css" type="text/css" media="screen" charset="utf-8" />
+    <link rel="stylesheet" href="/css/{{appid}}.css" type="text/css" media="screen" charset="utf-8" />
+  </head>
+  <body>
+    [[[page:layout()]]]
+
+    <script>
+      [[[script]]]
+    </script>
+  </body>
+</html>
+%% @author {{name}} {{email}}
+%% @copyright YYYY {{name}}.
+
+-module(index).
+-include_lib("nitrogen/include/wf.hrl").
+-export([main/0, title/0, layout/0]).
+
+main() ->
+    #template { file="./templates/grid.html" }.
+
+title() ->
+    "{{appid}}".
+
+layout() ->
+    #container_12 {
+        body=[#grid_12 { class=header, body={{appid}}_common:header(home) },
+              #grid_clear {},
+
+              #grid_6 { alpha=true, body={{appid}}_common:left() },
+              #grid_6 { omega=true, body={{appid}}_common:right() },
+              #grid_clear {},
+              
+              #grid_12 { body={{appid}}_common:footer() }
+             ]}.
+
+
+/***** CSS RESET *****/
+html,body,div,span,applet,object,iframe,h1,h2,h3,h4,h5,h6,p,blockquote,pre,a,abbr,acronym,address,big,cite,code,del,dfn,em,font,img,ins,kbd,q,s,samp,small,strike,strong,sub,sup,tt,var,b,u,i,center,dl,dt,dd,ol,ul,li,fieldset,form,label,legend,table,caption,tbody,tfoot,thead,tr,th,td{margin:0;padding:0;border:0;outline:0;font-size:100%;vertical-align:baseline;background:transparent}body{line-height:1}ol,ul{list-style:none}blockquote,q{quotes:none}blockquote:before,blockquote:after,q:before,q:after{content:'';content:none}:focus{outline:0}ins{text-decoration:none}del{text-decoration:line-through}table{border-collapse:collapse;border-spacing:0}
+
+/***** GRID *****/
+
+div.header {
+    margin: 0px;
+    padding: 0px;
+    margin-bottom: 1.0em;
+}
+
+.grid {
+    font-size: 1em; /* 13px */
+    line-height: 2em; /* 26px */
+    margin: 1em 0em;
+}
+
+.pad_right {
+    padding-right: 20px;
+}
+
+/***** STYLE *****/
+
+body { 
+    font-family: "Lucida Grande","Segoe UI","Trebuchet MS",Tahoma,Helvetica,Arial,sans-serif; 
+    font-size: 13px;
+    line-height: 1.5385em;
+    color: #222;
+}
+
+/***** MENU *****/
+
+
+.menu { 
+    color: #888;
+    background-color: #dfe2ea;
+    text-align: center;
+    font-size: 12px;
+    line-height: 12px;
+    padding: 8px;
+}
+
+.menu a {
+    color: #888;
+    padding: 3px 0px;
+    margin: 0px 10px;
+}
+
+.menu a:HOVER {
+    color: #FC2752;
+    text-decoration: none;
+}
+
+.menu a.selected {
+    color: #000;
+    background-color: #dfe2ea;
+    border-bottom: solid 3px #FC2752;
+}
+{variables, [{appid, "myapp"}
+             ,{name, "Torbjorn Tornkvist"}
+             ,{email, "<tobbe@tornkvist.org>"}
+             ,{nitro_dir, "/home/tobbe/git/nitrogen"}
+            ]}.
+{template, "Emakefile",            "Emakefile"}.
+{template, "Makefile",             "Makefile"}.
+{template, "README",               "README"}.
+{template, "LICENSE",              "LICENSE"}.
+{template, "nitrodep.inc",         "dep.inc"}.
+{template, "nitrostart.sh",        "start.sh"}.
+{template, "nitro.app.src",        "src/{{appid}}.app.src"}.
+{template, "nitro_app.erl",        "src/{{appid}}_app.erl"}.
+{template, "nitro_sup.erl",        "src/{{appid}}_sup.erl"}.
+{template, "nitro_inets.erl",      "src/{{appid}}_inetsp.erl"}.
+{template, "deps.erl",             "src/{{appid}}_deps.erl"}.
+{template, "nitro.index.erl",      "src/index.erl"}.
+{template, "nitro.common.erl",     "src/{{appid}}_common.erl"}.
+{template, "nitro.style.css",      "www/css/{{appid}}.css"}.
+{template, "nitro.grid.template",  "templates/grid.html"}.
+%% @author {{name}} {{email}}
+%% @copyright YYYY {{name}}.
+
+%% @doc Callbacks for the {{appid}} application.
+
+-module({{appid}}_app).
+-behaviour(application).
+
+-export([start/2, stop/1, do/1]).
+
+-include_lib("nitrogen/include/wf.hrl").
+
+start(_, _) ->
+    Res = {{appid}}_sup:start_link(),
+    {ok,_Pid} = {{appid}}_inets:start_link(), % ends up under the inets supervisors
+    Res.
+
+stop(_) ->
+    ok.
+
+
+
+%% @author {{name}} {{email}}
+%% @copyright YYYY {{name}}.
+
+%% @doc Callbacks for the polish application.
+
+-module({{appid}}_inets).
+
+-export([start_link/0, stop/0, do/1]).
+
+-include_lib("nitrogen/include/wf.hrl").
+
+-define(PORT, 8080).
+
+
+start_link() ->
+    inets:start(),
+    {ok, Pid} =
+        inets:start(httpd,
+                    [{port, {{appid}}_deps:get_env(port,?PORT)}
+                     ,{server_name,  hostname() }
+                     ,{server_root, "."}
+                     ,{document_root, {{appid}}_deps:get_env(doc_root,"./www")}
+                     ,{modules, [?MODULE]}
+                     ,{mime_types, [{"css",  "text/css"},
+                                    {"js",   "text/javascript"},
+                                    {"html", "text/html"}]}
+                    ]),
+    link(Pid),
+    {ok, Pid}.
+
+stop() ->
+    httpd:stop_service({any, ?PORT}),
+    ok.
+
+do(Info) ->
+    RequestBridge = simple_bridge:make_request(inets_request_bridge, Info),
+    ResponseBridge = simple_bridge:make_response(inets_response_bridge, Info),
+    nitrogen:init_request(RequestBridge, ResponseBridge),
+    nitrogen:run().
+
+hostname() ->
+    {ok,Host} = inet:gethostname(),
+    Host.
+
+%% @author {{name}} {{email}}
+%% @copyright YYYY {{name}}.
+
+%% @doc Callbacks for the polish application.
+
+-module({{appid}}_inets).
+
+-export([start_link/0, stop/0, do/1]).
+
+-include_lib("nitrogen/include/wf.hrl").
+
+-define(PORT, 8080).
+
+
+start_link() ->
+    inets:start(),
+    {ok, Pid} =
+        inets:start(httpd,
+                    [{port, ?PORT}
+                     ,{server_name,  hostname() }
+                     ,{server_root, "."}
+                     ,{document_root, {{appid}}_deps:get_env(doc_root,"./www")}
+                     ,{modules, [?MODULE]}
+                     ,{mime_types, [{"css", "text/css"},
+                                    {"js", "text/javascript"},
+                                    {"html", "text/html"}]}
+                    ]),
+    link(Pid),
+    io:format("~p: ~p~n", [?MODULE,Pid]),
+    {ok, Pid}.
+
+stop() ->
+    httpd:stop_service({any, ?PORT}),
+    ok.
+
+do(Info) ->
+    RequestBridge = simple_bridge:make_request(inets_request_bridge, Info),
+    ResponseBridge = simple_bridge:make_response(inets_response_bridge, Info),
+    nitrogen:init_request(RequestBridge, ResponseBridge),
+    nitrogen:run().
+
+hostname() ->
+    {ok,Host} = inet:gethostname(),
+    Host.
+
+%% @author {{name}} {{email}}
+%% @copyright YYYY {{name}}.
+
+-module({{appid}}_sup).
+
+-behaviour(supervisor).
+
+%% External exports
+-export([start_link/0, upgrade/0]).
+
+%% supervisor callbacks
+-export([init/1]).
+
+%% @spec start_link() -> ServerRet
+%% @doc API for starting the supervisor.
+start_link() ->
+    supervisor:start_link({local, ?MODULE}, ?MODULE, []).
+
+server(Name, Type) ->
+    server(Name, Type, 2000).
+
+server(Name, Type, Shutdown) ->
+    {Name, {Name, start_link, []}, permanent, Shutdown, Type, [Name]}.
+
+worker(Name) -> server(Name, worker).
+
+%% @spec upgrade() -> ok
+%% @doc Add processes if necessary.
+upgrade() ->
+    {ok, {_, Specs}} = init([]),
+
+    Old = sets:from_list(
+	    [Name || {Name, _, _, _} <- supervisor:which_children(?MODULE)]),
+    New = sets:from_list([Name || {Name, _, _, _, _, _} <- Specs]),
+    Kill = sets:subtract(Old, New),
+
+    sets:fold(fun (Id, ok) ->
+		      supervisor:terminate_child(?MODULE, Id),
+		      supervisor:delete_child(?MODULE, Id),
+		      ok
+	      end, ok, Kill),
+
+    [supervisor:start_child(?MODULE, Spec) || Spec <- Specs],
+    ok.
+
+%% @spec init([]) -> SupervisorTree
+%% @doc supervisor callback.
+init([]) ->
+
+    %Server = worker(server),
+
+    {ok, {{one_for_one, 10, 10}, 
+          [%Server
+          ]}}.
+
+
+NAME={{appid}}
+NITROGEN_TOP_DIR={{nitro_dir}}
+NITROGEN_EBIN=$NITROGEN_TOP_DIR/apps/nitrogen/ebin
+SIMPLE_BRIDGE_EBIN=$NITROGEN_TOP_DIR/apps/simple_bridge/ebin
+NPROCREG_EBIN=$NITROGEN_TOP_DIR/apps/nprocreg/ebin
+#!/usr/bin/env sh
+cd `dirname $0`
+
+. ./dep.inc
+
+echo "Starting Nitrogen..."
+erl \\
+    -sname ${NAME} \\
+    -pa ./ebin ${NITROGEN_EBIN} ${SIMPLE_BRIDGE_EBIN} ${NPROCREG_EBIN} \\
+    -eval "application:start(nprocreg)" \\
+    -eval "application:start({{appid}})"
+
+{application, {{appid}}, 
+ [
+  {description,  "{{appid}} - bla bla..."},
+
+  % The Module and Args used to start this application.
+  {mod, {{appid}},_app, []},
+
+  % All modules used by the application.
+  {modules,
+   [{{appid}}_app
+    ,{{appid}}_sup
+   ]},
+
+  % configuration parameters similar to those in the config file specified on the command line
+  {env, [{ip, "0.0.0.0}
+         ,{port, 8282}
+	 ,{log_dir, "/tmp"}
+	]}
+ ]
+}.
+{variables, [{appid, "myapp"}
+             ,{name, "Torbjorn Tornkvist"}
+             ,{email, "<tobbe@tornkvist.org>"}
+            ]}.
+{template, "webmEmakefile", "Emakefile"}.
+{template, "webmMakefile",  "Makefile"}.
+{template, "webm.app.src",  "src/{{appid}}.app.src"}.
+{template, "webm_app.erl",  "src/{{appid}}_app.erl"}.
+{template, "webm_sup.erl",  "src/{{appid}}_sup.erl"}.
+{ './src/*', [
+	{ i, "./include" },
+	{ outdir, "./ebin" },
+	debug_info
+]}.
+
+all:
+	erl -make
+
+init: all
+	mkdir ebin
+	(for i in \`ls dep/*\`; do cd \${i}; make; done)
+	cp src/{{appid}}.app.src ebin/{{appid}}.app 
+
+clean:
+	rm -rf ./ebin/*.beam
+
+%% @author {{name}} {{email}}
+%% @copyright YYYY {{name}}.
+
+%% @doc Callbacks for the {{appid}} application.
+
+-module({{appid}}_app).
+-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.
+%% @author {{name}} {{email}}
+%% @copyright YYYY {{name}}.
+
+%% @doc Supervisor for the {{appid}} application.
+
+-module({{appid}}_sup).
+-behaviour(supervisor).
+
+%% External exports
+-export([start_link/0, upgrade/0]).
+
+%% supervisor callbacks
+-export([init/1]).
+
+%% @spec start_link() -> ServerRet
+%% @doc API for starting the supervisor.
+start_link() ->
+    supervisor:start_link({local, ?MODULE}, ?MODULE, []).
+
+%% @spec upgrade() -> ok
+%% @doc Add processes if necessary.
+upgrade() ->
+    {ok, {_, Specs}} = init([]),
+
+    Old = sets:from_list([Name || {Name, _, _, _}
+                                      <- supervisor:which_children(?MODULE)]),
+    New = sets:from_list([Name || {Name, _, _, _, _, _} <- Specs]),
+    Kill = sets:subtract(Old, New),
+
+    sets:fold(fun (Id, ok) ->
+                      supervisor:terminate_child(?MODULE, Id),
+                      supervisor:delete_child(?MODULE, Id),
+                      ok
+              end, ok, Kill),
+
+    [supervisor:start_child(?MODULE, Spec) || Spec <- Specs],
+    ok.
+
+%% @spec init([]) -> SupervisorTree
+%% @doc supervisor callback.
+init([]) ->
+    Ip = case os:getenv("WEBMACHINE_IP") of false ->
+                 "0.0.0.0";
+             _Ip -> _Ip end,
+    Port = case os:getenv("WEBMACHINE_PORT") of false -> 8000; _Port -> l2i(_Port) end,
+    {ok, Dispatch} = file:consult(filename:join(
+                                    [filename:dirname(code:which(?MODULE)),
+                                     "..", "priv", "dispatch.conf"])),
+    WebConfig = [
+                 {ip, Ip},
+                 {port, Port},
+                 {log_dir, "priv/log"},
+                 {dispatch, Dispatch}],
+    Web = {webmachine_mochiweb,
+           {webmachine_mochiweb, start, [WebConfig]},
+           permanent, 5000, worker, dynamic},
+    Processes = [Web],
+    {ok, { { one_for_one, 10, 10}, Processes } }.
+
+l2i(L) when is_list(L)    -> list_to_integer(L);
+l2i(I) when is_integer(I) -> I.
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.