Permalink
Browse files

restructuring of how pages are loaded. And also some git structuring…

… which might make this commit look messy
  • Loading branch information...
1 parent d06ac70 commit 3172771c6aea57a919d71fd65949e4fb59761bb3 Mino committed May 6, 2010
View
@@ -0,0 +1 @@
+ebin/*
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
View
@@ -12,6 +12,7 @@
%% CookieCart Env
{tpl_main, "./tpl/CC_main.tpl"},
{tpl_category, "./tpl/CC_main.tpl"},
- {tpl_product, "./tpl/CC_main.tpl"}
+ {tpl_product, "./tpl/CC_main.tpl"},
+ {tpl_cart, "./tpl/CC_main.tpl"}
]}
]}.
View
Binary file not shown.
View
Binary file not shown.
View
Binary file not shown.
View
Binary file not shown.
View
Binary file not shown.
View
Binary file not shown.
View
Binary file not shown.
View
Binary file not shown.
View
Binary file not shown.
View
Binary file not shown.
View
Binary file not shown.
View
@@ -19,9 +19,21 @@
load(CatId) ->
wf:state(category,db:get_category(CatId)).
+load() ->
+ ?PRINT(wf:state(pathInfo)),
+ case wf:state(pathInfo) of
+ "99"++CatId ->
+ load(list_to_integer(CatId)),
+ true;
+ _ -> false
+ end.
%%====================================================================
%% Template Functions
%%====================================================================
+loadFromPath() ->
+ load(),
+ [].
+
%%%%%% Default %%%%%%
list()->
View
@@ -2,4 +2,4 @@
-compile(export_all).
load(_ImgID) ->
- "../img/default.gif/".
+ "/img/default.gif".
View
@@ -20,11 +20,22 @@ load(Product) when is_record(Product,product)->
wf:state(product,Product);
load(ProdId) ->
wf:state(product,db:get_product(ProdId)).
-
-
+
+load() ->
+ ?PRINT(wf:state(pathInfo)),
+ case wf:state(pathInfo) of
+ "112"++ProdId ->
+ load(list_to_integer(ProdId)),
+ true;
+ _ -> false
+ end.
%%====================================================================
%% Template Functions
%%====================================================================
+loadFromPath() ->
+ load(),
+ [].
+
id() ->
(?PRODUCT)#product.id.
View
@@ -53,16 +53,15 @@ eval(emptyCart) ->
_ -> false
end;
eval(product) ->
- case wf:state(product) of
- undefined ->
- false;
- _ -> true
- end;
+ product:load();
eval(category) ->
- case wf:state(category) of
- undefined ->
- false;
- _ -> true
+ category:is_category();
+
+eval(Page) when is_list(Page) ->
+ case wf:get_path_info() of
+ Page ->
+ true;
+ _ -> false
end;
eval(_Con) ->
- true.
+ false.
View
@@ -16,17 +16,16 @@
%%====================================================================
main() ->
PathInfo = wf:get_path_info(),
- case PathInfo of
- [] ->
- #template { file=env(tpl_main)};
- "112" ++ ProdId ->
- product:load(list_to_integer(ProdId)),
- tpl(PathInfo,tpl_product);
- "99" ++ CatId ->
- category:load(list_to_integer(CatId)),
- tpl(PathInfo,tpl_category);
- _ ->
- #template { file="./wwwroot/"++ PathInfo}
+ {Path,Info} = path_info(PathInfo),
+ wf:state(pathInfo,Info),
+
+ File = "./wwwroot/"++Path++".html",
+ case file:read_file_info(File) of
+ {ok,_} ->
+ #template { file=File };
+ {error,_} ->
+ ?PRINT(PathInfo),
+ #template{ file=env(error) }
end.
event(Event) ->
@@ -36,19 +35,20 @@ event(Event) ->
%%====================================================================
%% Internal Functions
%%====================================================================
+path_info(Str) ->
+ {Path,Info} = path_info(lists:reverse(Str),[]),
+ {lists:reverse(Path),Info}.
+path_info([],Acc) ->
+ {"xedni",Acc};
+path_info([$/|Tail],Acc) ->
+ {Tail,Acc};
+path_info([Head|Tail],Acc) ->
+ path_info(Tail,[Head|Acc]).
+
env(Par) ->
{ok,Val} = application:get_env(Par),
Val.
-tpl(IdStr,Default) ->
- Path = "./tpl/" ++ IdStr ++ ".tpl",
- case file:read_file_info(Path) of
- {ok,_} ->
- #template { file=Path };
- {error,_} ->
- #template{ file=env(Default) }
- end.
-
%%====================================================================
%% Debug Functions
View
@@ -1 +1 @@
-[[[cart:list()]]]
+[[[cart:list()]]]
View
@@ -43,7 +43,7 @@
</div> <!-- top-panel end !-->
<div id="header">
- <h1>Cookie Cart</h1>
+ <h1>Cookie Cart</h1>
</div>
<div>
@@ -60,6 +60,7 @@
<div class="block">
<h3>Cart</h3>
[[[cart:list()]]]
+ <a href="./cart">Cart</a>
</div>
<div class="block">
@@ -75,6 +76,7 @@
<div id="content">
[[[template:conditional(product,"./tpl/CC_product.tpl")]]]
[[[template:conditional(category,"./tpl/CC_category.tpl")]]]
+ [[[template:conditional("cart","./tpl/CC_cart.tpl")]]]
</div>
<div class="clear"></div>
@@ -1,3 +1,4 @@
+[[[product:loadFromPath()]]]
<tr>
<td>
<img src=[[[product:img()]]]
View
@@ -0,0 +1 @@
+<h1>HEJ!!</h1>
View
Binary file not shown.
View
Binary file not shown.
View
@@ -0,0 +1,106 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+
+<html xmlns="http://www.w3.org/1999/xhtml">
+ <head>
+ <title>Code Work</title>
+
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+
+ <script src='/nitrogen/jquery.js' type='text/javascript' charset='utf-8'>
+ </script>
+ <script src='/nitrogen/jquery-ui.js' type='text/javascript' charset='utf-8'>
+ </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"
+ type="text/css"
+ href="/css/style.css"
+ media="screen" />
+ </head>
+
+ <body>
+ <div id="wrap">
+ <div id="container">
+ <div id="top-panel">
+ <div class="left">
+ [[[web_index:render_page("smalllogin")]]]
+ </div>
+
+ <div class="right">
+ [[[web_index:render_page("internationalization")]]]
+ </div>
+
+ <div class="right">
+ [[[web_index:render_page("currency")]]]
+ </div>
+
+ <div class="right">
+ [[[web_index:render_page("tax")]]]
+ </div>
+ </div> <!-- top-panel end !-->
+
+ <div id="header">
+ <h1>Cookie Cart</h1>
+ </div>
+
+ <div>
+ <div id="searchpanel">
+ [[[web_index:render_page("mainsearch")]]]
+ </div>
+
+ <div id="locationpanel">
+ [[[web_index:render_page("location")]]]
+ </div>
+ </div>
+
+ <div id="sidebar">
+ <div class="block">
+ <h3>Cart</h3>
+ [[[cart:list()]]]
+ <a href="./cart">Cart</a>
+ </div>
+
+ <div class="block">
+ <h3>Categories</h3>
+ [[[category:list()]]]
+ </div>
+
+ <div class="block">
+ [[[web_index:render_page("Contactinfo")]]]
+ </div>
+ </div> <!-- sidebar end !-->
+
+ <div id="content">
+ [[[template:conditional(product,"./tpl/CC_product.tpl")]]]
+ [[[template:conditional(category,"./tpl/CC_category.tpl")]]]
+ [[[template:conditional("cart","./tpl/CC_cart.tpl")]]]
+ </div>
+
+ <div class="clear"></div>
+
+ <div class="text-center">
+ <img src="/themes/default/img/payment_methods.gif" />
+ </div>
+ </div><!-- container end !-->
+
+ <div id="end"></div>
+
+ <div id="footer">
+ <div id="credits">
+ Powered by <a href="http://klarna.se/">Cookie Cart</a> -
+ <a href="http://www.nitrogenproject.com/">Nitrogen</a> -
+ <a href="http://riak.basho.com/">Riak</a> -
+ <a href="http://code.google.com/p/mochiweb/">Mochiweb</a> -
+ </div>
+ </div> <!-- footer end !-->
+ </div><!-- wrap end !-->
+
+ <script>
+ [[[script]]]
+ </script>
+
+ </body>
+</html>

0 comments on commit 3172771

Please sign in to comment.