Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 30c3ffb
Showing
62 changed files
with
2,755 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -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]]]!');". |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -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>". |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -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!"). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,13 @@ | |||
{ | |||
[ | |||
"./src/*", | |||
"./src/*/*", | |||
"./src/*/*/*", | |||
"./src/*/*/*/*" | |||
], | |||
[ | |||
{ i, "./include" }, | |||
{ outdir, "./ebin" }, | |||
debug_info | |||
] | |||
}. |
Empty file.
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -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])}). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -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). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -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>". |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -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 } | |||
}). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -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}). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -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(). | |||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -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()). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,7 @@ | |||
-module(nitrogen_init). | |||
-export ([init/0]). | |||
|
|||
%% Called during application startup. | |||
%% Put other initialization code here. | |||
init() -> | |||
application:start(nprocreg). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -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(). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -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" | |||
} | |||
]). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -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} | |||
} | |||
). |
Oops, something went wrong.