Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
choptastic committed Dec 2, 2010
0 parents commit 30c3ffb
Show file tree
Hide file tree
Showing 62 changed files with 2,755 additions and 0 deletions.
11 changes: 11 additions & 0 deletions .prototypes/action.erl
@@ -0,0 +1,11 @@
%% -*- mode: nitrogen -*-
-module (action_[[[NAME]]]).
-compile (export_all).
-include_lib ("nitrogen/include/wf.hrl").
-include("records.hrl").

%% Move the following line to records.hrl:
-record([[[NAME]]], {?ACTION_BASE(action_[[[NAME]]]), attr1, attr2}).

render_action(_Record = #[[[NAME]]]{}) ->
"alert('Hello, from [[[NAME]]]!');".
13 changes: 13 additions & 0 deletions .prototypes/element.erl
@@ -0,0 +1,13 @@
%% -*- mode: nitrogen -*-
-module (element_[[[NAME]]]).
-compile(export_all).
-include_lib("nitrogen/include/wf.hrl").
-include("records.hrl").

%% Move the following line to records.hrl:
-record([[[NAME]]], {?ELEMENT_BASE(element_[[[NAME]]]), attr1, attr2}).

reflect() -> record_info(fields, [[[NAME]]]).

render_element(_Record = #[[[NAME]]]{}) ->
"<b>Hello from [[[NAME]]]</b>".
25 changes: 25 additions & 0 deletions .prototypes/page.erl
@@ -0,0 +1,25 @@
%% -*- mode: nitrogen -*-
-module ([[[NAME]]]).
-compile(export_all).
-include_lib("nitrogen/include/wf.hrl").
-include("records.hrl").

main() -> #template { file="./site/templates/bare.html" }.

title() -> "Hello from [[[NAME]]].erl!".

body() ->
[
#panel { style="margin: 50px 100px;", body=[
#span { text="Hello from [[[NAME]]].erl!" },

#p{},
#button { text="Click me!", postback=click },

#p{},
#panel { id=placeholder }
]}
].

event(click) ->
wf:insert_top(placeholder, "<p>You clicked the button!").
13 changes: 13 additions & 0 deletions Emakefile
@@ -0,0 +1,13 @@
{
[
"./src/*",
"./src/*/*",
"./src/*/*/*",
"./src/*/*/*/*"
],
[
{ i, "./include" },
{ outdir, "./ebin" },
debug_info
]
}.
Empty file added ebin/.empty
Empty file.
Empty file added include/records.hrl
Empty file.
Empty file added src/actions/.ignore
Empty file.
34 changes: 34 additions & 0 deletions src/bindpostback.erl
@@ -0,0 +1,34 @@
-module(bindpostback).
-compile(export_all).
-include_lib("nitrogen/include/wf.hrl").

main() -> #template{file="site/templates/bare.html"}.

title() -> "Data binding with postback demo".

get_data() ->
[{"Apples","5"},{"Bananas","4"},{"Oranges","6"}].

body() ->
Data = get_data(),
Map = {fruit@body,qty@body},
#table{rows=[
#bind{data=Data,map=Map,transform=fun format_data/2,body=[
#tablerow{cells=[
#tablecell{id=fruit},
#tablecell{id=qty},
#tablecell{body=#link{id=wishlist,text="Wishlist"}},
#tablecell{body=#link{id=buy,text="Add to Cart"}}
]}
]}
]}.

format_data({Fruit,_} = DataRow,Acc) ->
{DataRow,Acc,[{wishlist@postback,{wishlist,Fruit}},{buy@postback,{buy,Fruit}}]}.

event({Action,Name}) ->
wf:info({Action,Name}),
CurList = wf:session_default(Action,[]),
NewList = [Name | CurList],
wf:session(Action,NewList),
wf:wire(#alert{text=wf:f("New ~p: ~p",[Action,NewList])}).
22 changes: 22 additions & 0 deletions src/cluster.erl
@@ -0,0 +1,22 @@
-module (cluster).
-compile(export_all).
-include_lib("nitrogen/include/wf.hrl").
-include("records.hrl").

main() -> #template { file="./site/templates/bare.html" }.

title() -> "Clustering Demo".

body() ->
Counter = case wf:session(counter) of
undefined -> 0;
N -> N
end,
wf:session(counter,Counter + 1),
[
"Node: ",wf:to_list(node()),
#br{},
wf:to_list(Counter),#br{}
].

event(_) -> ok.
17 changes: 17 additions & 0 deletions src/comet.erl
@@ -0,0 +1,17 @@
-module(comet).
-compile(export_all).
-include_lib("nitrogen/include/wf.hrl").

main() -> #template{file="site/templates/bare.html"}.

title() -> "Simple Comet Example".

body() ->
wf:comet(fun()-> count(0) end),
["Counter: ",#span{id=countspan}].

count(Counter) ->
timer:sleep(1000),
wf:update(countspan,"blah" ++ wf:to_list(Counter)),
wf:flush(), % flush commands to browser
?MODULE:count(Counter + 1).
16 changes: 16 additions & 0 deletions src/effect.erl
@@ -0,0 +1,16 @@
-module(effect).
-compile(export_all).
-include_lib("nitrogen/include/wf.hrl").

main() -> #template{file="site/templates/bare.html"}.

title() -> "Effect demo".

body() ->
wf:wire(doit,effected,#event{
type=click,actions=#effect{effect=shake}
}),
[
#panel{id=effected,body="Doing Something"},
#button{id=doit,text="Do it"}
].
Empty file added src/elements/.ignore
Empty file.
13 changes: 13 additions & 0 deletions src/elements/element_canvas.erl
@@ -0,0 +1,13 @@
%% -*- mode: nitrogen -*-
-module (element_canvas).
-compile(export_all).
-include_lib("nitrogen/include/wf.hrl").
-include("records.hrl").

%% Move the following line to records.hrl:
-record(canvas, {?ELEMENT_BASE(element_canvas), attr1, attr2}).

reflect() -> record_info(fields, canvas).

render_element(_Record = #canvas{}) ->
"<b>Hello from canvas</b>".
35 changes: 35 additions & 0 deletions src/index.erl
@@ -0,0 +1,35 @@
%% -*- mode: nitrogen -*-
-module (index).
-compile(export_all).
-include_lib("nitrogen/include/wf.hrl").

main() -> #template { file="./site/templates/bare.html" }.

title() -> "Welcome to Nitrogen".

body() ->
#container_12 { body=[
#grid_8 { alpha=true, prefix=2, suffix=2, omega=true, body=inner_body() }
]}.

inner_body() ->
[
#h1 { text="Welcome to Nitrogen" },
#p{},
"
If you can see this page, then your Nitrogen server is up and
running. Click the button below to test postbacks.
",
#p{},
#button { id=button, text="Click me!", postback=click },
#p{},
"
Run <b>./bin/dev help</b> to see some useful developer commands.
"
].

event(click) ->
wf:replace(button, #panel {
body="You clicked the button!",
actions=#effect { effect=highlight }
}).
11 changes: 11 additions & 0 deletions src/live/basic.erl
@@ -0,0 +1,11 @@
-module(basic).
-compile(export_all).
-include_lib("nitrogen/include/wf.hrl").

main() -> #template{file="site/templates/bare.html"}.

title() -> "".

body() -> ok.

event(_) -> ok.
21 changes: 21 additions & 0 deletions src/live/hello.erl
@@ -0,0 +1,21 @@
-module(hello).
-compile(export_all).
-include_lib("nitrogen/include/wf.hrl").

main() -> #template{file="site/templates/bare.html"}.

body() ->
wf:wire(whatever,field,#validate{validators=[
#is_required{text="Please enter something"}
]}),
[
#textbox{id=field,class=textbox,text="Something"},
#button{id=whatever,text="Click ME",postback=clicked}
].




event(clicked) ->
FieldValue = wf:q(field),
wf:wire(#alert{text=FieldValue}).
34 changes: 34 additions & 0 deletions src/loginbar.erl
@@ -0,0 +1,34 @@
-module(loginbar).
-compile(export_all).
-include_lib("nitrogen/include/wf.hrl").

logged_in(U) -> [
#span{class=user,text=U},
" | ",
#link{postback=logout,delegate=?MODULE,text="Log Out"}
].

logged_out() -> [
#textbox{id=login,text="Your Name"},
#button{postback=login,delegate=?MODULE,text="Log In"}
].

login_body() ->
case wf:user() of
undefined -> logged_out();
U -> logged_in(U)
end.

loginbar() ->
#panel{id=loginbox,body=login_body()}.

event(login) ->
Login = wf:q(login),
wf:user(Login),
wf:update(loginbox,login_body()),
menubar:update();
event(logout) ->
wf:logout(),
wf:update(loginbox,login_body()),
menubar:update().

27 changes: 27 additions & 0 deletions src/menubar.erl
@@ -0,0 +1,27 @@
-module(menubar).
-compile(export_all).
-include_lib("nitrogen/include/wf.hrl").

menu() ->
Data = case wf:user() of
undefined -> [];
_ -> [
{"/update","Update"},
{"/replace","Replace"},
{"/replaceeffect","Replace with Effect"},
{"/effect","Effect"},
{"/cluster","Clustering"},
{"/comet","Comet"},
{"/bindpostback","Advanced Bind"},
{"/twitter","Twitter Search"}
]
end,
Map = {menulink@url,menulink@text},
#bind{data=Data,map=Map,empty_body="Log In for Menu",body=[
#list{class=menu,body=[
#listitem{body=#link{id=menulink}}
]}
]}.

update() ->
wf:update("div.menu",menu()).
7 changes: 7 additions & 0 deletions src/nitrogen_init.erl
@@ -0,0 +1,7 @@
-module(nitrogen_init).
-export ([init/0]).

%% Called during application startup.
%% Put other initialization code here.
init() ->
application:start(nprocreg).
8 changes: 8 additions & 0 deletions src/nitrogen_yaws.erl
@@ -0,0 +1,8 @@
-module(nitrogen_yaws).
-export ([out/1]).

out(Arg) ->
RequestBridge = simple_bridge:make_request(yaws_request_bridge, Arg),
ResponseBridge = simple_bridge:make_response(yaws_response_bridge, Arg),
nitrogen:init_request(RequestBridge, ResponseBridge),
nitrogen:run().
23 changes: 23 additions & 0 deletions src/replace.erl
@@ -0,0 +1,23 @@
-module(replace).
-compile(export_all).
-include_lib("nitrogen/include/wf.hrl").

main() -> #template{file="site/templates/bare.html"}.


title() -> "Update Demo".

body() ->
#panel{id=wrapper,body=[
"Click below<br />",
#button{id=but,text="Click Me!",postback=replace}
]}.

event(replace) ->
wf:replace(but,[
"You clicked it<br />",
#link{
url="http://erlang.org",
text="Here's Erlang"
}
]).
21 changes: 21 additions & 0 deletions src/replaceeffect.erl
@@ -0,0 +1,21 @@
-module(replaceeffect).
-compile(export_all).
-include_lib("nitrogen/include/wf.hrl").

main() -> #template{file="site/templates/bare.html"}.


title() -> "Update Demo".


body() ->
#button{id=but,text="Click Me!",postback=replace}.

event(replace) ->
wf:replace(but,
#link{
url="http://erlang.org",
text="Here's Erlang",
actions=#show{effect=puff}
}
).

0 comments on commit 30c3ffb

Please sign in to comment.