Erlang Mailing Lists

Author Message

<  Erlyweb mailing list  ~  Making a blog with ErlyWeb

Guest
Posted: Sat Dec 22, 2007 12:10 pm Reply with quote
Guest
I want to have different sidebars, sorry for the confusing
explanation.

Using your hook/1, this is the setup I have now for a sidebar that is
always the same:

html_container_controller.erl:

index(A, Ewc) ->
Ewc.

html_container_view.et:

<%@ index(Data) %>
<html>
<head>
</head>
<body>
<div id="header">
header
</div>

<div id="content">
<% Data %>
</div>

<div id="footer">
footer
</div>
</body>
</html>


main_layout_controller.erl:

index(A, Ewc) ->
[Ewc, {ewc, sidebar, [A]}].

main_layout_view.et:

<%@ index([Data, Sidebar]) %>
<div id="main">
<% Data %>
</div>
<div id="sidebar">
<% Sidebar %>
</div>

For a different sidebar on each page, does it mean to get rid of the
main_layout_controller/view and put the stuff in entry_controller/view
and so on?

e.g.:

entry_controller.erl:

index(A) ->
Entries = entry:find_with({order_by, [{id, desc}]}),
[[{ewc, entry, entry, [A, Entry]} || Entry <- Entries], {ewc,
sidebar, entry_index, [A]}].

entry_view.et:

<%@ index([Entry, Sidebar]) %>
<div id="main">
<h1>Entries</h1>
<% Entry %>
</div>
<div id="sidebar">
<% Sidebar %>
</div>

<%@ entry(...) %>
...

This would mean to repeat the #main and #sidebar divs in every view,
so it doesn
ketralnis
Posted: Sat Dec 22, 2007 6:09 pm Reply with quote
User Joined: 20 Jul 2007 Posts: 151 Location: San Francisco, CA
> I want to have different sidebars, sorry for the confusing
> explanation.

You could pass up which sidebar you want (or even the full ewc for it)
in a phased_var

>
>
> Using your hook/1, this is the setup I have now for a sidebar that is
> always the same:
>
> html_container_controller.erl:
>
> index(A, Ewc) ->
> Ewc.
>
> html_container_view.et:
>
> <%@ index(Data) %>
> <html>
> <head>
> </head>
> <body>
> <div id="header">
> header
> </div>
>
> <div id="content">
> <% Data %>
> </div>
>
> <div id="footer">
> footer
> </div>
> </body>
> </html>
>
>
> main_layout_controller.erl:
>
> index(A, Ewc) ->
> [Ewc, {ewc, sidebar, [A]}].
>
> main_layout_view.et:
>
> <%@ index([Data, Sidebar]) %>
> <div id="main">
> <% Data %>
> </div>
> <div id="sidebar">
> <% Sidebar %>
> </div>
>
> For a different sidebar on each page, does it mean to get rid of the
> main_layout_controller/view and put the stuff in entry_controller/view
> and so on?
>
> e.g.:
>
> entry_controller.erl:
>
> index(A) ->
> Entries = entry:find_with({order_by, [{id, desc}]}),
> [[{ewc, entry, entry, [A, Entry]} || Entry <- Entries], {ewc,
> sidebar, entry_index, [A]}].
>
> entry_view.et:
>
> <%@ index([Entry, Sidebar]) %>
> <div id="main">
> <h1>Entries</h1>
> <% Entry %>
> </div>
> <div id="sidebar">
> <% Sidebar %>
> </div>
>
> <%@ entry(...) %>
> ...
>
> This would mean to repeat the #main and #sidebar divs in every view,
> so it doesn
View user's profile Send private message AIM Address
Guest
Posted: Sun Dec 23, 2007 6:09 pm Reply with quote
Guest
I would if I could...but I need an example of a
html_container_controller.erl/html_container_view.et and a component
making use of the phased_vars, other than that I am completely lost. I
have tried to get a guess how this works but nothing worked.

On 22 Dez., 19:08, David King <dk...@ketralnis.com> wrote:
> > I want to have different sidebars, sorry for the confusing
> > explanation.
>
> You could pass up which sidebar you want (or even the full ewc for it)
> in a phased_var
>
>
>
> > Using your hook/1, this is the setup I have now for a sidebar that is
> > always the same:
>
> > html_container_controller.erl:
>
> > index(A, Ewc) ->
> > Ewc.
>
> > html_container_view.et:
>
> > <%@ index(Data) %>
> > <html>
> > <head>
> > </head>
> > <body>
> > <div id="header">
> > header
> > </div>
>
> > <div id="content">
> > <% Data %>
> > </div>
>
> > <div id="footer">
> > footer
> > </div>
> > </body>
> > </html>
>
> > main_layout_controller.erl:
>
> > index(A, Ewc) ->
> > [Ewc, {ewc, sidebar, [A]}].
>
> > main_layout_view.et:
>
> > <%@ index([Data, Sidebar]) %>
> > <div id="main">
> > <% Data %>
> > </div>
> > <div id="sidebar">
> > <% Sidebar %>
> > </div>
>
> > For a different sidebar on each page, does it mean to get rid of the
> > main_layout_controller/view and put the stuff in entry_controller/view
> > and so on?
>
> > e.g.:
>
> > entry_controller.erl:
>
> > index(A) ->
> > Entries = entry:find_with({order_by, [{id, desc}]}),
> > [[{ewc, entry, entry, [A, Entry]} || Entry <- Entries], {ewc,
> > sidebar, entry_index, [A]}].
>
> > entry_view.et:
>
> > <%@ index([Entry, Sidebar]) %>
> > <div id="main">
> > <h1>Entries</h1>
> > <% Entry %>
> > </div>
> > <div id="sidebar">
> > <% Sidebar %>
> > </div>
>
> > <%@ entry(...) %>
> > ...
>
> > This would mean to repeat the #main and #sidebar divs in every view,
> > so it doesn
Guest
Posted: Tue Dec 25, 2007 7:43 am Reply with quote
Guest
David gave me a lesson on IRC. Visit his blog: http://www.ketralnis.com/roller/dking/
to read the log and you should be able to use phased_vars. Smile

On 23 Dez., 19:08, maddiin <madd...@googlemail.com> wrote:
> I would if I could...but I need an example of a
> html_container_controller.erl/html_container_view.et and a component
> making use of the phased_vars, other than that I am completely lost. I
> have tried to get a guess how this works but nothing worked.
>
> On 22 Dez., 19:08, David King <dk...@ketralnis.com> wrote:
>
> > > I want to have different sidebars, sorry for the confusing
> > > explanation.
>
> > You could pass up which sidebar you want (or even the full ewc for it)
> > in a phased_var
>
> > > Using your hook/1, this is the setup I have now for a sidebar that is
> > > always the same:
>
> > > html_container_controller.erl:
>
> > > index(A, Ewc) ->
> > > Ewc.
>
> > > html_container_view.et:
>
> > > <%@ index(Data) %>
> > > <html>
> > > <head>
> > > </head>
> > > <body>
> > > <div id="header">
> > > header
> > > </div>
>
> > > <div id="content">
> > > <% Data %>
> > > </div>
>
> > > <div id="footer">
> > > footer
> > > </div>
> > > </body>
> > > </html>
>
> > > main_layout_controller.erl:
>
> > > index(A, Ewc) ->
> > > [Ewc, {ewc, sidebar, [A]}].
>
> > > main_layout_view.et:
>
> > > <%@ index([Data, Sidebar]) %>
> > > <div id="main">
> > > <% Data %>
> > > </div>
> > > <div id="sidebar">
> > > <% Sidebar %>
> > > </div>
>
> > > For a different sidebar on each page, does it mean to get rid of the
> > > main_layout_controller/view and put the stuff in entry_controller/view
> > > and so on?
>
> > > e.g.:
>
> > > entry_controller.erl:
>
> > > index(A) ->
> > > Entries = entry:find_with({order_by, [{id, desc}]}),
> > > [[{ewc, entry, entry, [A, Entry]} || Entry <- Entries], {ewc,
> > > sidebar, entry_index, [A]}].
>
> > > entry_view.et:
>
> > > <%@ index([Entry, Sidebar]) %>
> > > <div id="main">
> > > <h1>Entries</h1>
> > > <% Entry %>
> > > </div>
> > > <div id="sidebar">
> > > <% Sidebar %>
> > > </div>
>
> > > <%@ entry(...) %>
> > > ...
>
> > > This would mean to repeat the #main and #sidebar divs in every view,
> > > so it doesn
Guest
Posted: Thu Dec 27, 2007 1:51 am Reply with quote
Guest
I'm updating the documentation about phased rendering. I hope it'll be
made clearer.

Yariv

On Dec 24, 2007 11:42 PM, maddiin <maddiin@googlemail.com> wrote:
>
> David gave me a lesson on IRC. Visit his blog: http://www.ketralnis.com/roller/dking/
> to read the log and you should be able to use phased_vars. Smile
>
>
> On 23 Dez., 19:08, maddiin <madd...@googlemail.com> wrote:
> > I would if I could...but I need an example of a
> > html_container_controller.erl/html_container_view.et and a component
> > making use of the phased_vars, other than that I am completely lost. I
> > have tried to get a guess how this works but nothing worked.
> >
> > On 22 Dez., 19:08, David King <dk...@ketralnis.com> wrote:
> >
> > > > I want to have different sidebars, sorry for the confusing
> > > > explanation.
> >
> > > You could pass up which sidebar you want (or even the full ewc for it)
> > > in a phased_var
> >
> > > > Using your hook/1, this is the setup I have now for a sidebar that is
> > > > always the same:
> >
> > > > html_container_controller.erl:
> >
> > > > index(A, Ewc) ->
> > > > Ewc.
> >
> > > > html_container_view.et:
> >
> > > > <%@ index(Data) %>
> > > > <html>
> > > > <head>
> > > > </head>
> > > > <body>
> > > > <div id="header">
> > > > header
> > > > </div>
> >
> > > > <div id="content">
> > > > <% Data %>
> > > > </div>
> >
> > > > <div id="footer">
> > > > footer
> > > > </div>
> > > > </body>
> > > > </html>
> >
> > > > main_layout_controller.erl:
> >
> > > > index(A, Ewc) ->
> > > > [Ewc, {ewc, sidebar, [A]}].
> >
> > > > main_layout_view.et:
> >
> > > > <%@ index([Data, Sidebar]) %>
> > > > <div id="main">
> > > > <% Data %>
> > > > </div>
> > > > <div id="sidebar">
> > > > <% Sidebar %>
> > > > </div>
> >
> > > > For a different sidebar on each page, does it mean to get rid of the
> > > > main_layout_controller/view and put the stuff in entry_controller/view
> > > > and so on?
> >
> > > > e.g.:
> >
> > > > entry_controller.erl:
> >
> > > > index(A) ->
> > > > Entries = entry:find_with({order_by, [{id, desc}]}),
> > > > [[{ewc, entry, entry, [A, Entry]} || Entry <- Entries], {ewc,
> > > > sidebar, entry_index, [A]}].
> >
> > > > entry_view.et:
> >
> > > > <%@ index([Entry, Sidebar]) %>
> > > > <div id="main">
> > > > <h1>Entries</h1>
> > > > <% Entry %>
> > > > </div>
> > > > <div id="sidebar">
> > > > <% Sidebar %>
> > > > </div>
> >
> > > > <%@ entry(...) %>
> > > > ...
> >
> > > > This would mean to repeat the #main and #sidebar divs in every view,
> > > > so it doesn
Guest
Posted: Sun Jan 06, 2008 3:06 pm Reply with quote
Guest
I am working on archive pages for the blog application right now and
couldn
ketralnis
Posted: Sun Jan 06, 2008 11:11 pm Reply with quote
User Joined: 20 Jul 2007 Posts: 151 Location: San Francisco, CA
> The next thing I am struggling with are error pages. Looking at vimagi
> and wrotit, they respond with error pages if a record wasn
View user's profile Send private message AIM Address
Guest
Posted: Wed Jan 09, 2008 7:55 pm Reply with quote
Guest
Just want to know how this looks to you, if I should move on or if its
just weird. At least you know now what I try to achieve and I would be
happy to see something the like in ErlyWeb, as archive pages are a
common use case (blog, news-sites, etc).

It generates queries like (for mysql):

1>entry:find_date(created, [year]).
mysql_conn:426: fetch <<"SELECT DISTINCT year(created) FROM entry">>
(id <0.73.0>)
[{entry,false,2007},{entry,false,2008}]
2>entry:find_date(created, ['YEAR','MONTH']).
mysql_conn:426: fetch <<"SELECT DISTINCT YEAR(created),MONTH(created)
FROM entry">> (id <0.73.0>)
[{entry,false,2007,12},{entry,false,2008,1}]

For postgres a query would look like:
<<"SELECT DISTINCT
date_part('year',created),date_part('month',created),date_part('day',created)
FROM entry">>

find_date(Module, Field, Dates, Where, Extras) ->
do_find_date(Module, Field, Dates, Where, Extras).

do_find_date(Module, Field, Dates, Where, Extras) ->
do_find_date(Module, Field, Dates, Where, Extras, true).

do_find_date(Module, Field, Dates, Where, Extras, AsModule) ->
select(Module, make_find_query_for_date(Module, Field, Dates,
Where, Extras), AsModule).

make_find_query_for_date(Module, Field, Dates, Where, Extras) ->
{Driver,_} = Module:driver(),
case Driver of
erlydb_mysql ->
{esql,
{select, distinct, [list_to_atom(atom_to_list(Date)++"("+
+atom_to_list(Field)++")") || Date <- Dates], {from,
db_table(Module)},
make_where_expr(Module, Where),
Extras}};
erlydb_psql ->
{esql,
{select, distinct, [list_to_atom("date_part('"+
+atom_to_list(Date)++"',"++atom_to_list(Field)++")") || Date <-
Dates], {from, db_table(Module)},
make_where_expr(Module, Where),
Extras}};
erlydb_mnesia ->
mnesia_not_yet_added;
_ ->
unknown_driver
end.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "erlyweb" group.
To post to this group, send email to erlyweb@googlegroups.com
To unsubscribe from this group, send email to erlyweb-unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.com/group/erlyweb?hl=en
-~----------~----~----~----~------~----~------~--~---

Post recived from mailinglist
Guest
Posted: Thu Jan 10, 2008 7:42 am Reply with quote
Guest
On Jan 6, 2008 3:10 PM, David King <dking@ketralnis.com> wrote:
>
> > The next thing I am struggling with are error pages. Looking at vimagi
> > and wrotit, they respond with error pages if a record wasn
Guest
Posted: Thu Jan 10, 2008 8:01 am Reply with quote
Guest
ErlSQL has the expression 'call' for function calls in SQL. So,

{select, {call, foo, [1,2,3]}}

would be translated to

"SELECT foo(1,2,3)"

I think we should use it and add another expression on top of it as a
special case for date-related functions so they can be translated to
the proper dialiect. E.g.

{select, {date_part, year, created}}

would be translated to the intermediate

{select, {call, year, [created]}} (in MySQL) or
{select, {call, date_part, [<<"year">>, created]}} (in Postgres).

It would be an easy change to make. Without changing any ErlyDB code,
you could use this expression in SELECTs as follows:

entry:find({{date_part, year, created},'=',2008}).

This would call "SELECT * FROM entry WHERE year(created) = 2008".

Would that satisfy your requirements?

Btw, using list_to_atom is dangerous because atoms aren't garbage
collected. Although in this case the number of possible atoms is
limited, it's still better to avoid list_to_atom.

Yariv

On Jan 9, 2008 11:54 AM, maddiin <maddiin@googlemail.com> wrote:
>
> Just want to know how this looks to you, if I should move on or if its
> just weird. At least you know now what I try to achieve and I would be
> happy to see something the like in ErlyWeb, as archive pages are a
> common use case (blog, news-sites, etc).
>
> It generates queries like (for mysql):
>
> 1>entry:find_date(created, [year]).
> mysql_conn:426: fetch <<"SELECT DISTINCT year(created) FROM entry">>
> (id <0.73.0>)
> [{entry,false,2007},{entry,false,2008}]
> 2>entry:find_date(created, ['YEAR','MONTH']).
> mysql_conn:426: fetch <<"SELECT DISTINCT YEAR(created),MONTH(created)
> FROM entry">> (id <0.73.0>)
> [{entry,false,2007,12},{entry,false,2008,1}]
>
> For postgres a query would look like:
> <<"SELECT DISTINCT
> date_part('year',created),date_part('month',created),date_part('day',created)
> FROM entry">>
>
> find_date(Module, Field, Dates, Where, Extras) ->
> do_find_date(Module, Field, Dates, Where, Extras).
>
> do_find_date(Module, Field, Dates, Where, Extras) ->
> do_find_date(Module, Field, Dates, Where, Extras, true).
>
> do_find_date(Module, Field, Dates, Where, Extras, AsModule) ->
> select(Module, make_find_query_for_date(Module, Field, Dates,
> Where, Extras), AsModule).
>
> make_find_query_for_date(Module, Field, Dates, Where, Extras) ->
> {Driver,_} = Module:driver(),
> case Driver of
> erlydb_mysql ->
> {esql,
> {select, distinct, [list_to_atom(atom_to_list(Date)++"("+
> +atom_to_list(Field)++")") || Date <- Dates], {from,
> db_table(Module)},
> make_where_expr(Module, Where),
> Extras}};
> erlydb_psql ->
> {esql,
> {select, distinct, [list_to_atom("date_part('"+
> +atom_to_list(Date)++"',"++atom_to_list(Field)++")") || Date <-
> Dates], {from, db_table(Module)},
> make_where_expr(Module, Where),
> Extras}};
> erlydb_mnesia ->
> mnesia_not_yet_added;
> _ ->
> unknown_driver
> end.
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "erlyweb" group.
To post to this group, send email to erlyweb@googlegroups.com
To unsubscribe from this group, send email to erlyweb-unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.com/group/erlyweb?hl=en
-~----------~----~----~----~------~----~------~--~---

Post recived from mailinglist
Guest
Posted: Thu Jan 10, 2008 2:49 pm Reply with quote
Guest
> entry:find({{date_part, year, created},'=',2008}).
>
> This would call "SELECT * FROM entry WHERE year(created) = 2008".
>
> Would that satisfy your requirements?

Yes, for finding entries by a given date that would be good.

How about finding dates where entries have been posted in?

So I could display on my archive index the years (eg. 2008,2007,2006)
if there are entries posted in this years. If I am on a year detail
page, I want to show the month entries have been posted in.

Instead of the star selector I want to query for "SELECT YEAR(created)
FROM entry" and "SELECT MONTH(created) FROM entry WHERE YEAR(created)
= 2008". I also need it for the sidebar and that would meet all the
requirements then for making archive pages.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "erlyweb" group.
To post to this group, send email to erlyweb@googlegroups.com
To unsubscribe from this group, send email to erlyweb-unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.com/group/erlyweb?hl=en
-~----------~----~----~----~------~----~------~--~---

Post recived from mailinglist
Guest
Posted: Fri Jan 11, 2008 1:45 am Reply with quote
Guest
On Jan 10, 2008 6:48 AM, maddiin <maddiin@googlemail.com> wrote:
>
> > entry:find({{date_part, year, created},'=',2008}).
> >
> > This would call "SELECT * FROM entry WHERE year(created) = 2008".
> >
> > Would that satisfy your requirements?
>
> Yes, for finding entries by a given date that would be good.
>
> How about finding dates where entries have been posted in?
>
> So I could display on my archive index the years (eg. 2008,2007,2006)
> if there are entries posted in this years. If I am on a year detail
> page, I want to show the month entries have been posted in.
>
> Instead of the star selector I want to query for "SELECT YEAR(created)
> FROM entry" and "SELECT MONTH(created) FROM entry WHERE YEAR(created)
> = 2008". I also need it for the sidebar and that would meet all the
> requirements then for making archive pages.

One option you have is to use the ErlyDB driver module directly, e.g.

erlydb_mysql:q({select, {date_field, year, created}}, from, entry}, Options),

but that's not a nice solution because of the dependency on the driver
and the need to write the full query and include the Options
parameter.

I think a better solution would be do add a function to erlydb_base
called "find_fields", which you could use to query for one or more
fields from a table mapped to a module, e.g.

entry:find_fields([id, {date_field, year, created}])

would return a list where each item is a tuple representing the row's
value, e.g. {1, 2007}.

You would also add a WHERE and LIMIT clauses as in other functions.

Would that be better?

Yariv
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "erlyweb" group.
To post to this group, send email to erlyweb@googlegroups.com
To unsubscribe from this group, send email to erlyweb-unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.com/group/erlyweb?hl=en
-~----------~----~----~----~------~----~------~--~---

Post recived from mailinglist
Guest
Posted: Tue Jan 22, 2008 11:47 pm Reply with quote
Guest
Yes, that would be fine. Having both mentioned solutions in ErlyWeb
would be all thats needed for archive pages.

I recently started working on some documentation/tutorials for
ErlyWeb. I made a table of contents and I am halfway done with a
"getting your feet wet" tutorial building on the blog application.

The table of contents is just an outline for a tutorials section and
should be discussed on the list, but I think its necessary to have, so
people can pick out parts they want to write documentation for. If I
have finished the first tutorial (maybe tomorrow) I

Display posts from previous:  

All times are GMT
Page 2 of 2
Goto page Previous  1, 2
This forum is locked: you cannot post, reply to, or edit topics.

Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum