Commits

Anonymous committed 957fc02

Adding named routing and eopenid support.

Comments (0)

Files changed (14)

 
   % All modules used by the application.
   {modules,
-   [{{appid}}_app
+   [{{appid}}
+    ,{{appid}}_app
+    ,{{appid}}_sup
     ,{{appid}}_deps
+    ,{{appid}}_common
+    ,{{appid}}_inets
+    ,{{appid}}_web_index
+    ,{{appid}}_web_login
+    ,{{appid}}_web_logout
+    ,{{appid}}_web_auth
    ]},
 
   % configuration parameters similar to those in the config file specified on the command line
          ,{port, 8282}
 	 ,{log_dir, "/tmp"}
 	 ,{doc_root, "./www"}
-	]}
- ]
-}.
+	 ,{acl, ["{{openid}}"
+                ]}
+         ,{users,[{"{{openid}}",
+                   [{name, "{{name}}"}
+                    ,{email, "{{email}}"}]}
+                 ]}
+        ]
+  }
+]}.
+/***** 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;
+}
+%%% @author {{name}} <{{email}}>
+%%% @copyright (C) YYYY, {{name}}
+
+-module({{appid}}).
+
+-export([hostname/0
+         , default_port/0
+         , i2l/1
+        ]).
+
+-include_lib("nitrogen/include/wf.hrl").
+           
+
+default_port() -> 8080.
+
+hostname() ->
+    {ok,Host} = inet:gethostname(),
+    Host.
+
+i2l(I) when is_integer(I) -> integer_to_list(I);
+i2l(L) when is_list(L)    -> L.
+    
+
+REQUIREMENTS
+------------
+Get Nitrogen (and perhaps EOpenId):
+
+ mkdir $HOME/git
+ cd $HOME/git
+ git clone http://github.com/rklophaus/nitrogen.git
+ (git clone http://github.com/etnt/eopenid.git)
+
+Build the above code by running make in their resp. top dir.
+
+
+SETUP
+----
+In the {{appid}} directory, first edit the paths in the 'dep.inc' file.
+
+Then run:
+
+ make init
+
+To compile the source code of the polish application:
+
+ make
+
+Now, change the config settings in ebin/{{appid}}.app before starting
+the system as:
+
+ ./start.sh

nitro.style.css

-/***** 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"}
+{variables, [{appid,        "myapp"}
+             ,{name,        "Torbjorn Tornkvist"}
+             ,{email,       "etnt@redhoterlang.com"}
+	     ,{openid,      "http://etnt.myopenid.com/"}
+             ,{nitro_dir,   "/home/tobbe/git/nitrogen"}
+	     ,{www,         "http://www.redhoterlang.com"}
+	     ,{year,        "2010"}
             ]}.
 {template, "Emakefile",            "Emakefile"}.
 {template, "Makefile",             "Makefile"}.
-{template, "README",               "README"}.
+{template, "nitro.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.erl",            "src/{{appid}}.erl"}.
 {template, "nitro_sup.erl",        "src/{{appid}}_sup.erl"}.
 {template, "nitro_inets.erl",      "src/{{appid}}_inets.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_web_index.erl",  "src/{{appid}}_web_index.erl"}.
+{template, "nitro_web_auth.erl",   "src/{{appid}}_web_auth.erl"}.
+{template, "nitro_web_login.erl",  "src/{{appid}}_web_login.erl"}.
+{template, "nitro_web_logout.erl", "src/{{appid}}_web_logout.erl"}.
+{template, "nitro_common.erl",     "src/{{appid}}_common.erl"}.
+{template, "nitro.css",            "www/css/{{appid}}.css"}.
 {template, "nitro.grid.template",  "templates/grid.html"}.
 -include_lib("nitrogen/include/wf.hrl").
 
 start(_, _) ->
+    %% Uncomment below iff using eopenid!
+    %%eopenid:start(),
     Res = {{appid}}_sup:start_link(),
     {ok,_Pid} = {{appid}}_inets:start_link(), % ends up under the inets supervisors
     Res.
 
 stop(_) ->
+    %% Uncomment below iff using eopenid!
+    %%eopenid:stop(),
     ok.
 
 
+%% @author {{name}} <{{email}}>
+%% @copyright {{year}} {{name}}
+
+-module({{appid}}_common).
+
+-include_lib ("nitrogen/include/wf.hrl").
+
+-export([title/0
+         , header/1
+         , footer/0
+         , right/0
+         , left/0
+        ]).
+
+title() ->
+    "{{appid}}".
+
+
+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=logout, url='/logout',      text="Logout"  },
+        #link { id=about,  url='/about',       text="About"  }
+    ]}.
+
+
+footer() ->
+    [#br{},
+     #panel { class=credits, body=[
+        "
+        Copyright &copy; {{year}} <a href='{{www}}'>{{name}}</a>. 
+        Released under the MIT License.
+        "
+    ]}].
+
 
 -include_lib("nitrogen/include/wf.hrl").
 
--define(PORT, 8080).
 
+%%% @doc This is the routing table.
+routes() ->
+    [{"/",            {{appid}}_web_index}
+     , {"/login",     {{appid}}_web_login}
+     , {"/logout",    {{appid}}_web_logout}
+     , {"/auth",      {{appid}}_web_auth}
+     , {"/ajax",      {{appid}}_web_ajax}
+     , {"/nitrogen",  static_file}
+     , {"/js",        static_file}
+     , {"/css",       static_file}
+    ].
 
 start_link() ->
     inets:start(),
     {ok, Pid} =
         inets:start(httpd,
-                    [{port, {{appid}}_deps:get_env(port,?PORT)}
-                     ,{server_name,  hostname() }
+                    [{port, {{appid}}_deps:get_env(port, {{appid}}:default_port())}
+                     ,{server_name,  {{appid}}_deps:get_env(hostname, {{appid}}:hostname())}
                      ,{server_root, "."}
                      ,{document_root, {{appid}}_deps:get_env(doc_root,"./www")}
                      ,{modules, [?MODULE]}
     {ok, Pid}.
 
 stop() ->
-    httpd:stop_service({any, ?PORT}),
+    httpd:stop_service({any, {{appid}}_deps:get_env(port, {{appid}}:default_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),
+    replace_route_handler(),
     nitrogen:run().
 
-hostname() ->
-    {ok,Host} = inet:gethostname(),
-    Host.
-
+replace_route_handler() ->
+    wf_handler:set_handler(named_route_handler, routes()).
 
     %Server = worker(server),
 
-    {ok, {{one_for_one, 10, 10}, 
+    {ok, { {one_for_one, 10, 10}, 
           [%Server
-          ]}}.
+          ]} }.
 
 

nitro_web_index.erl

+%% @author {{name}} {{email}}
+%% @copyright YYYY {{name}}.
+
+-module({{appid}}_web_index).
+
+-include_lib("nitrogen/include/wf.hrl").
+
+-export([main/0
+         , title/0
+         , layout/0
+	 , event/1
+	]).
+
+
+main() ->
+    #template { file="./templates/grid.html" }.
+
+title() ->
+    {{appid}}_common:title().
+
+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() }
+             ]}.
+
+event(Event) ->
+    io:format("Event=~p~n",[Event]),
+    ok.

nitro_web_login.erl

     
 
 login_header() ->
-    #panel { class = "login_header", body = ["{{Appid}} logo here..."] }.
+    #panel { class = "login_header", body = ["{{appid}} logo here..."] }.
 
 
 login_form() ->

nitro_web_logout.erl

+%%% @author {{name}} <{{email}}>
+%%% @copyright (C) 2010, {{name}}
+
+-module({{appid}}_web_logout).
+
+-export([main/0]).
+
+-include_lib ("nitrogen/include/wf.hrl").
+
+
+main() -> 
+    wf:user(undefined),
+    wf:session(authenticated, false),
+    wf:redirect("/").
+
+
+	
 erl \\
     -sname ${NAME} \\
     -pa ./ebin ${NITROGEN_EBIN} ${SIMPLE_BRIDGE_EBIN} ${NPROCREG_EBIN} \\
+        ${EOPENID_EBIN} \\
+    -pa ./ebin ${NITROGEN_EBIN} ${SIMPLE_BRIDGE_EBIN} ${NPROCREG_EBIN} \\
     -eval "application:start(nprocreg)" \\
     -eval "application:start({{appid}})"
 
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.