> I really like erlyweb. Once of the problems I'm having with it is
> that some of the idioms required to do common things in the view
> require a bit more erlang knowledge than I would like and it would
> be good if this could be abstracted for the common cases to allow
> designers without erlang knowledge to still maintain the templates.
Then people that don't want to learn Erlang will have to learn your
FOREACH construct. Then someone will come along asking for an easier
way to do your FOREACH construct, and so on.
IMHO, I'm afraid you'll just have to learn the idioms. Your best bet
is to not do this in the view at all. In fact, I don't recommend
passing artist objects into the views at all, only the viewable text
itself.
Erlyweb has a good component system. I recommend learning it, and
using it instead of trying to do much in the view. Yes, this means
learning some Erlang.
------------------------------
-module(artist_controller).
-compile(export_all).
h(Text) ->
sanitise_html().
show(A,ArtistName) ->
Artist=artist:find_name(ArtistName),
[ {data, h(ArtistName)},
[ {ewc, artist, album, [A,Album]}
|| Album <- artist:albums(Artist) ]].
album(A,Album) ->
Title=album:title(Album),
[ {data, h(Title) },
[ {ewc,artist,song,[A,Song]
|| Song <- album:songs(Album) ]].
song(A,Song) ->
[ {data,h(song:title(Song)) },
{data,h(song:lyrics(Song)) } ].
------------------------------
And the view:
------------------------------
<%@ show([ArtistName, Albums]) %>
<h1><% ArtistName %></h1>
<h2>Albums</h2>
<ul>
Albums
</ul>
<%@ album([Title, Songs]) %>
<li>
<% Title %>
<ul>
<% Songs %>
</ul>
</li>
<%@ song([Title,Lyrics]) %>
<li>
<h3><% Title %></h3>
<pre><% Lyrics %></pre>
</li>
------------------------------
With the appropriate models, that should do what you're looking for.
The "foreach" bits are the list comprehensions, like this:
[ Expr || Expr <- generator() ].
That could also be done with a map:
lists:map(fun(Expr) ->
Expr
end, generator()).
>
>
> For example, to loop over a list the documentation suggests that I
> define a function and pass the list off to that. I'd suggest a
> simpler
> interface for that would be a FOREACH loop, e.g. :
>
> <% FOREACH {Title, Artist, Songs} = Data %>
> Title: <b><% Title %></b><br>
> Artist: <b><% Artist %></b><br>
> <% FOREACH {Number, Name} = Songs %>
> Song <% integer_to_list(Number) %> - <% Name %><br>
> <% END %>
> <% END %>
>
> This is nothing new, of course, it is a familair construct from
> templating systems in other languages and that is really the point,
> i.e.
> designers are familiar with it.
>
> It would still work the same way under the hood, of course, with the
> body of the FOREACH most likely being compiled to an erlang function,
> however the interface IMO is nicer. I can have a go at putting
> together
> a patch if there is any interest.
>
> Any thoughts?
>
> Thanks.
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"erlyweb" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/erlyweb?hl=en
-~----------~----~----~----~------~----~------~--~---