Erlang Mailing Lists

Author Message

<  Yaws mailing list  ~  yaws 2.0

tobbe
Posted: Sun Mar 04, 2007 5:15 pm Reply with quote
User Joined: 19 Jan 2005 Posts: 274 Location: Stockholm, Sweden
Torbjorn Tornkvist skrev:
> Yariv Sadan skrev:
>> Hi,
>>
>> I have a couple of suggestions:
>>
> ....snip...
>> For supporting new template languages, I think you should consider
>> using ErlyWeb because it already provides the plumbing for separating
>> the controller logic from the view template logic. (I, personally,
>> prefer ErlTL, but I am willing to help with supporting other options.)
>
> After having read this excellent paper:
>
> http://www.cs.usfca.edu/~parrt/papers/mvc.templates.pdf
>
> that 'mikkom' recommended in a comment on the ErlTl blog entry.
> I think it is important to carfully consider how a template
> system for Yaws should be constructed.
>
> Personally, I like the look of Seethrough, but as I understand
> it from reading the paper above it (e.g) breaks an important property
> in that it allows attributes to be injected from the controller/model.
> It is in an early stage though and will/could probably be revised
> many times still.
>
> I haven't used any template system yet for doing Erlang-Web development
> (appart from SSI which the article immediately does away with) and can't
> really state what the requirements on such a system should be.
> However, I've become more and more unhappy with the current situation
> of mixing EHTML with control logic, etc so the article above was
> a really good eye-opener to me.
>
> It would be interesting to have a discussion about this topic.
> For example:
>
> + What do you people think a template system should support?
> + How does ErlTL/Seethrough relate to the definitions in the above article?

Just to give you some ideas:
The following excerpt is taken from stringtemplate.org:

"After examining hundreds of template files that I created over years
of jGuru.com (and now in ANTLR v3) development, I found that I needed
only the following four basic canonical operations (with some variations):

* attribute reference; e.g., $phoneNumber$
* template reference (like #include or macro expansion); e.g., $searchbox()$
* conditional include of subtemplate (an IF statement); e.g., $if(title)$<title>$title$</title>$endif$
* template application to list of attributes; e.g., $names:bold()$

where template references can be recursive."

--Tobbe


>
>> Regarding backend integration with Javascript libraries, I recently
>> saw a good quote by one of the Django developers: "Why use an electric
>> wheelchair if you can walk?" Smile
>
> I've been doing quite a lot of work with jquery (jquery.com) lately
> and I can really recommend it. I think it is especially suited for
> functional programmers which may (like my self) have a hard time
> with all that OOP.
>
> Cheers, Tobbe
>
>
> -------------------------------------------------------------------------
> Take Surveys. Earn Cash. Influence the Future of IT
> Join SourceForge.net's Techsay panel and you'll get the chance to share your
> opinions on IT & business topics through brief surveys-and earn cash
> http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV


-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Erlyaws-list mailing list
Erlyaws-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/erlyaws-list
Post recived from mailinglist
View user's profile Send private message Send e-mail Visit poster's website
noss
Posted: Sun Mar 04, 2007 8:11 pm Reply with quote
User Joined: 09 Oct 2005 Posts: 290
I scanned that paper quickly and want to object to something he concludes
about "pull" vs "push" templates. He claims that that for pull
templates the order
matters which creates dependencies and high suckiness.

This is of course not true for lazy-evaluation!

I went googling to find a lazy-evaluation template language and i find
an interesting comment to this blog post about template languages in
erlang (!!! Smile. 'Anonymous'
mentions lazy-evaluation too after having read the same paper. I mostly agree
with his position on things so ill let him speak for me: (search for
lazy-eval if the
comment permalink doesnt work)

http://www.bluishcoder.co.nz/2006/06/html-template-languages.html#115036710115336873

I'm imagining something like this:

HEAD file:
<html>
<head>
<title>$$Title$$</title>

SEARCH file:
$$render HEAD$$
$$Title= "Search results for the query %s." % {Query}$$
<body>
<table>
<caption>You have $$Searchresult.length$$ hits for $$Query$$.</caption>
$$Query = args["q"]$$
$$Searchresult = search(Query)$$
$$map Searchresult as Row over
{{{
<tr><td>$$Row.title$$ <td> $$Row.summary$$ <td>$$Row.relevance$$ </tr>
}}}
$$
</table>

So invoking the view SEARCH?q=foo+bar would output something like:

<html>
<head>
<title>Search result for the query foo bar.</title>
<body>
<table>
<caption>You have 3 hits for foo bar</caption>
<tr><td>Gurka<td>...</tr>
<tr><td>Sallad<td>...</tr>
<tr><td>Ananas<td>...</tr>
</table>

Now, the syntax i chosed for this imaginary template language is very
open for improvements, it was inspired by pseudo-template-code used in
the pdf article.

The idea is that all templates have access to a few service objects on
which they can
invoke arbitrary computations, so all templates are created equal in
their ability of what view
to present of the model. A push-template will only be able to present a view
of the data that has been computated for it, no more, but less
(meaning unecessary computation has been done for data that wont be
used).

In a MVC pattern, the controller would decide what variables to place initially
in the environment. If the template calls no methods/functions but only expands
variables it is essentially a template of the "push"-kind.

Undoubtably a lazy-evaluation "pull"-template would make it possible
to put "business logic" in the template, but that is an argument
against programmers or deadline demands that do so, and not against a
solution that allows it as a cop out.

PS. Somewhere someone must have created a template language with
lazy-evaluation already? The functional programming purists would have
the idea strike them easier
than others.

On 3/4/07, Torbjorn Tornkvist <tobbe@tornkvist.org> wrote:
> Yariv Sadan skrev:
> > Hi,
> >
> > I have a couple of suggestions:
> >
> ....snip...
> >
> > For supporting new template languages, I think you should consider
> > using ErlyWeb because it already provides the plumbing for separating
> > the controller logic from the view template logic. (I, personally,
> > prefer ErlTL, but I am willing to help with supporting other options.)
>
> After having read this excellent paper:
>
> http://www.cs.usfca.edu/~parrt/papers/mvc.templates.pdf
>
> that 'mikkom' recommended in a comment on the ErlTl blog entry.
> I think it is important to carfully consider how a template
> system for Yaws should be constructed.
>
> Personally, I like the look of Seethrough, but as I understand
> it from reading the paper above it (e.g) breaks an important property
> in that it allows attributes to be injected from the controller/model.
> It is in an early stage though and will/could probably be revised
> many times still.
>
> I haven't used any template system yet for doing Erlang-Web development
> (appart from SSI which the article immediately does away with) and can't
> really state what the requirements on such a system should be.
> However, I've become more and more unhappy with the current situation
> of mixing EHTML with control logic, etc so the article above was
> a really good eye-opener to me.
>
> It would be interesting to have a discussion about this topic.
> For example:
>
> + What do you people think a template system should support?
> + How does ErlTL/Seethrough relate to the definitions in the above article?
>
> >
> > Regarding backend integration with Javascript libraries, I recently
> > saw a good quote by one of the Django developers: "Why use an electric
> > wheelchair if you can walk?" Smile
>
> I've been doing quite a lot of work with jquery (jquery.com) lately
> and I can really recommend it. I think it is especially suited for
> functional programmers which may (like my self) have a hard time
> with all that OOP.
>
> Cheers, Tobbe
>
>

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Erlyaws-list mailing list
Erlyaws-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/erlyaws-list
Post recived from mailinglist
View user's profile Send private message
Guest
Posted: Sun Mar 04, 2007 8:39 pm Reply with quote
Guest
s
tobbe
Posted: Mon Mar 05, 2007 8:01 am Reply with quote
User Joined: 19 Jan 2005 Posts: 274 Location: Stockholm, Sweden
Mikael Karlsson wrote:
>
>>
...snip...
>>
> There is an Erlang template engine inspired by Stringtemplate engine at:
> http://blog.sgconsulting.it/blog.html?idtag=13

This looks very nice!

--Tobbe


-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Erlyaws-list mailing list
Erlyaws-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/erlyaws-list
Post recived from mailinglist
View user's profile Send private message Send e-mail Visit poster's website
filippo
Posted: Mon Mar 05, 2007 11:03 am Reply with quote
User Joined: 22 Nov 2006 Posts: 19 Location: Siena
Hi all,

Torbjorn Tornkvist wrote:
> Yariv Sadan skrev:
>> Hi,
>>
>> I have a couple of suggestions:
>>
> ....snip...
>> For supporting new template languages, I think you should consider
>> using ErlyWeb because it already provides the plumbing for separating
>> the controller logic from the view template logic. (I, personally,
>> prefer ErlTL, but I am willing to help with supporting other options.)
>
> After having read this excellent paper:
>
> http://www.cs.usfca.edu/~parrt/papers/mvc.templates.pdf
>
> that 'mikkom' recommended in a comment on the ErlTl blog entry.
> I think it is important to carfully consider how a template
> system for Yaws should be constructed.

I think following the principles described in the paper is the best way
to build a good template system.
Another important thing to keep in mind, at least for the use I do of
template languages, is how pages, written using the language, works on
WYSIWYG editors.
If they work well designers can work on them without breaking the code
and mantain some aspects of a web site without the need of a programmer.

> Personally, I like the look of Seethrough, but as I understand
> it from reading the paper above it (e.g) breaks an important property
> in that it allows attributes to be injected from the controller/model.
> It is in an early stage though and will/could probably be revised
> many times still.
I like the look of XML based template systems too, but IMHO they have
some problems.
An example from the Seethrough home page:
<td e:content="address"/>

If you open the html page on an editor like Dreamweaver, or in some
browser you can't see the column because empty cells aren't rendered.

You shoud have something like:
<td e:content="address">address</td>
where the cell content is replaced at runtime.

I also think that this kind of templates can break some XHTML validators.

Moreover I think a template language like String Template is more
general. You can also use it to generate for example sql code, simple
text emails, or whatever you like. Though maybe then you don't need yaws
Smile.

> I haven't used any template system yet for doing Erlang-Web development
> (appart from SSI which the article immediately does away with) and can't
> really state what the requirements on such a system should be.
> However, I've become more and more unhappy with the current situation
> of mixing EHTML with control logic, etc so the article above was
> a really good eye-opener to me.

I've used several systems during the years:
- .cgi pages
- mixed code and html like .yaws or .php pages
- cheetah template www.cheetahtemplate.org a python template language
based on Java Velocity I think.

String Template IMVHO is the best I've found so far, and that's why I
tried to implement something similar in Erlang with sgte Smile:
blog.sgconsulting.it/blog.html?idtag=13

It enforces separation of view and model/controller and if you put
template code inside html comments you can also work with designers
without problems.

Cheers,
filippo

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Erlyaws-list mailing list
Erlyaws-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/erlyaws-list
Post recived from mailinglist
View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger
filippo
Posted: Mon Mar 05, 2007 11:18 am Reply with quote
User Joined: 22 Nov 2006 Posts: 19 Location: Siena
Torbjorn Tornkvist wrote:
> Mikael Karlsson wrote:
> ...snip...
>> There is an Erlang template engine inspired by Stringtemplate engine at:
>> http://blog.sgconsulting.it/blog.html?idtag=13
>
> This looks very nice!
>

Thanks,
but it still needs a lot of improvements.

filippo

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Erlyaws-list mailing list
Erlyaws-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/erlyaws-list
Post recived from mailinglist
View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger
filippo
Posted: Mon Mar 05, 2007 12:37 pm Reply with quote
User Joined: 22 Nov 2006 Posts: 19 Location: Siena
Christian S wrote:
> I scanned that paper quickly and want to object to something he concludes
> about "pull" vs "push" templates. He claims that that for pull
> templates the order
> matters which creates dependencies and high suckiness.
>
> This is of course not true for lazy-evaluation!
>
> I went googling to find a lazy-evaluation template language and i find
> an interesting comment to this blog post about template languages in
> erlang (!!! Smile. 'Anonymous'
> mentions lazy-evaluation too after having read the same paper. I mostly agree
> with his position on things so ill let him speak for me: (search for
> lazy-eval if the
> comment permalink doesnt work)
>
> http://www.bluishcoder.co.nz/2006/06/html-template-languages.html#115036710115336873
>
I read the comment and I don't agree very much with the poster. It's
true that with lazy evaluation you don't have the problem described in
the paper, but if your template can execute code arbitrarily it can also
alter the model.
In this way you end up again with the model and view entangled together
and template languages were born just to avoid this Smile

If I have a template language which is a turing complete language or
something similar I know in the end I'll use the features mixing view
and model (most of the time due to time constraints) and regretting it
at the first change I have to do Smile. It happened me more than once.

> I'm imagining something like this:
> ... snip ...
>
> The idea is that all templates have access to a few service objects on
> which they can
> invoke arbitrary computations, so all templates are created equal in
> their ability of what view
> to present of the model.
> A push-template will only be able to present a view
> of the data that has been computated for it, no more, but less
> (meaning unecessary computation has been done for data that wont be
> used).
Unnecessary computation in a push template can be avoided with lazy
evaluation too. For example in an if branch you can have a closure
called when the template is rendered.
Having push IMHO doesn't mean you can't executed code in the template,
only that the code is in the model and it's pushed in the view.
I think it's more a problem of who's "responsible" for the code.

>
> In a MVC pattern, the controller would decide what variables to place initially
> in the environment. If the template calls no methods/functions but only expands
> variables it is essentially a template of the "push"-kind.
>
> Undoubtably a lazy-evaluation "pull"-template would make it possible
> to put "business logic" in the template, but that is an argument
> against programmers or deadline demands that do so, and not against a
> solution that allows it as a cop out.
Yes it's exactly as I said above.
You have to balance the conveniences, executing code arbitrarily, gives
you and the drawback you have when you mix model and view keeping in
mind you need a template language and not a programming language.

Cheers,
filippo

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Erlyaws-list mailing list
Erlyaws-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/erlyaws-list
Post recived from mailinglist
View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger
tobbe
Posted: Mon Mar 05, 2007 1:40 pm Reply with quote
User Joined: 19 Jan 2005 Posts: 274 Location: Stockholm, Sweden
Filippo Pacini wrote:
> Hi all,
...snip...
>
> Moreover I think a template language like String Template is more
> general. You can also use it to generate for example sql code, simple
> text emails, or whatever you like. Though maybe then you don't need yaws
> Smile.

Yes, I noticed that when I read your examples and I liked it a lot!

Perhaps Yaws could/should define a simple API to make it possible to
plug in an 'arbitrary' template engine ?

Cheers, Tobbe


-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Erlyaws-list mailing list
Erlyaws-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/erlyaws-list
Post recived from mailinglist
View user's profile Send private message Send e-mail Visit poster's website
vladdu
Posted: Mon Mar 05, 2007 1:57 pm Reply with quote
User Joined: 28 Feb 2005 Posts: 397 Location: Gothenburg, Sweden
Hi,

On 3/5/07, Torbjorn Tornkvist <tobbe@tornkvist.org> wrote:
> Perhaps Yaws could/should define a simple API to make it possible to
> plug in an 'arbitrary' template engine ?

Just a silly question: doesn't yaws already support php? Why is an API
needed? I mean, yaws is a web server - isn't the template machinery an
orthogonal issue? Or at least, shouldn't it be?

regards,
Vlad

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Erlyaws-list mailing list
Erlyaws-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/erlyaws-list
Post recived from mailinglist
View user's profile Send private message
noss
Posted: Mon Mar 05, 2007 2:24 pm Reply with quote
User Joined: 09 Oct 2005 Posts: 290
On 3/5/07, Torbjorn Tornkvist <tobbe@tornkvist.org> wrote:
> Yes, I noticed that when I read your examples and I liked it a lot!
>
> Perhaps Yaws could/should define a simple API to make it possible to
> plug in an 'arbitrary' template engine ?

Probably. Giving up on .yaws page support is not an alternative.

I have been pondering scanning the docroot file tree at startup for
all the files in it and placing it in an ets table. Then looking up
all http requests against this ets table to find which filesystem name
(or other) to access.

I would be able to remove all .yaws-suffixed names in the ets table
and store the names without the suffix.

Appmod references from the configuration could be stored in this ets table.

Index files such as index.html and index.yaws could be removed from
the ets table and only be accessible from a single name, the
trailing-slash-on-a-dir, reversely, a http request path that ends with
a trailing / could always be mapped to /index instead.

If my docroot has a /st/style.css and /st/style.css.gz then i could first map up
/st/style as a single exposed name for the resource, and for those
clients that accept a gzip content encoding i can serve the
pre-compressed version.

The downside is for directories under docroot that change. I mostly
write database-driven sites so it is not really my concern. The
solution would be to install an appmod that solves that.

PS
Yes, I have a perverted quest for clean urls.

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Erlyaws-list mailing list
Erlyaws-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/erlyaws-list
Post recived from mailinglist
View user's profile Send private message
Guest
Posted: Mon Mar 05, 2007 3:20 pm Reply with quote
Guest
> PS
> Yes, I have a perverted quest for clean urls.

I too would love to see easy, non-external, url rewriting. I tried to
write a redirecting module that would redirect people from
www.domain.tld to domain.tld (to obtain no-www.org's class B status).
Not every having hacked around with YAWS, I fell flat on my face and
gave up.

Chris

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Erlyaws-list mailing list
Erlyaws-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/erlyaws-list
Post recived from mailinglist
noss
Posted: Mon Mar 05, 2007 3:28 pm Reply with quote
User Joined: 09 Oct 2005 Posts: 290
That is pretty easy though.

<server example.com>
main conf here
</server>

<server www.example.com>
port, listen and docroot conf still required
<redirect>
/ = example.com
</redirect>
</server>

Or does it not suffice?

On 3/5/07, Christopher Covington <covracer@gmail.com> wrote:
> > PS
> > Yes, I have a perverted quest for clean urls.
>
> I too would love to see easy, non-external, url rewriting. I tried to
> write a redirecting module that would redirect people from
> www.domain.tld to domain.tld (to obtain no-www.org's class B status).
> Not every having hacked around with YAWS, I fell flat on my face and
> gave up.
>
> Chris
>
> -------------------------------------------------------------------------
> Take Surveys. Earn Cash. Influence the Future of IT
> Join SourceForge.net's Techsay panel and you'll get the chance to share your
> opinions on IT & business topics through brief surveys-and earn cash
> http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
> _______________________________________________
> Erlyaws-list mailing list
> Erlyaws-list@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/erlyaws-list
>

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Erlyaws-list mailing list
Erlyaws-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/erlyaws-list
Post recived from mailinglist
View user's profile Send private message
filippo
Posted: Mon Mar 05, 2007 4:43 pm Reply with quote
User Joined: 22 Nov 2006 Posts: 19 Location: Siena
First of all sorry for the long answer Smile

Torbjorn Tornkvist wrote:
> Filippo Pacini wrote:
>> Hi all,
> ...snip...
>> Moreover I think a template language like String Template is more
>> general. You can also use it to generate for example sql code, simple
>> text emails, or whatever you like. Though maybe then you don't need yaws
>> Smile.
>
> Yes, I noticed that when I read your examples and I liked it a lot!
>
> Perhaps Yaws could/should define a simple API to make it possible to
> plug in an 'arbitrary' template engine ?
>

This would be a nice feature to have.

Maybe you could do something like apache mod_python (www.modpython.org).
Don't know if you are familiar with it. It's very similar to appmods.

In the apache configuration you have something like this:
<Directory /some/directory/htdocs/test>
AddHandler mod_python .py
PythonHandler mptest
</Directory>

This tells apache that .py urls in the dir. /some/directory/htdocs/test
are managed by the handler mptest.

Then mptest must has a function handler (like out in yaws appmods) that
manages the request.

Till now it's like an appmod. Then on top of these you have an handler
called Publisher. What the publisher basically does is map an url like
foo.py/bar to the function call bar in the file foo.py

In this way urls are conveniently mapped to python modules.
Here you don't have templates, but in foo.py you can use the template
language you prefer.

Don' t know if this can help, but at the moment I'm developing
applications like this. This is a basic appmod:

out(A) ->
%% this matches urls to erlang modules and functions
MatchSpec = [{"/", fun login_res:render/1},
{{regexp, "/summary/?"}, fun summary_res:render/1},
...],
case sgweb:resource_matcher(MatchSpec, A#arg.appmoddata) of
{no_match, {status, NotFound}} -> %% 404 error page not found
error(A, NotFound);
Resource -> %% call the function that render the web resource
Resource(A)
end.


Then an example of a resource module to be rendered:
I've defined a behaviour because all resources have the same structure

-module(summary_res).
-behaviour(sgweb_resource).

%% behaviour callbacks
-export([tmpl/1, render/1, handle_req/1]).

%% this returns the file containing the template to be rendered
tmpl(Arg) ->
TmplDir = Arg#arg.docroot,
{file, TmplDir ++ "/summary.html"}.

%% This handles a get request and returns the data to be passed to the
template
handle_req({'GET', Arg}) ->
%%here I load all the Data needed, update data in mnesia, etc...
{ok, [DataAndCallbacksForTheTemplate]}

%% the render of the resource has a default implementation
%% it first get the template, then call handle_req to get the data
%% and finally calls the render of the template passing data
render(Arg) ->
sgweb_resource:render(Arg, ?MODULE).

With something like this I think switching between different template
systems should be easy. You should only need a small wrapper (e.g. I
called render in sgte what in Seethrough is called apply_template).

filippo

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Erlyaws-list mailing list
Erlyaws-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/erlyaws-list
Post recived from mailinglist
View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger
Guest
Posted: Mon Mar 05, 2007 4:46 pm Reply with quote
Guest
Thanks a bunch. That's exactly what I wanted. I might have been
reading an old (1.5Cool version of the yaws.conf manual when I tried to
figure out how to do that before. I guess Yaws already has easy,
non-external redirection implemented Smile.

Chris

On 3/5/07, Christian S <chsu79@gmail.com> wrote:
> That is pretty easy though.
>
> <server example.com>
> main conf here
> </server>
>
> <server www.example.com>
> port, listen and docroot conf still required
> <redirect>
> / = example.com
> </redirect>
> </server>
>
> Or does it not suffice?
>
> On 3/5/07, Christopher Covington <covracer@gmail.com> wrote:
> > > PS
> > > Yes, I have a perverted quest for clean urls.
> >
> > I too would love to see easy, non-external, url rewriting. I tried to
> > write a redirecting module that would redirect people from
> > www.domain.tld to domain.tld (to obtain no-www.org's class B status).
> > Not every having hacked around with YAWS, I fell flat on my face and
> > gave up.
> >
> > Chris
> >
> > -------------------------------------------------------------------------
> > Take Surveys. Earn Cash. Influence the Future of IT
> > Join SourceForge.net's Techsay panel and you'll get the chance to share your
> > opinions on IT & business topics through brief surveys-and earn cash
> > http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
> > _______________________________________________
> > Erlyaws-list mailing list
> > Erlyaws-list@lists.sourceforge.net
> > https://lists.sourceforge.net/lists/listinfo/erlyaws-list
> >
>

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Erlyaws-list mailing list
Erlyaws-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/erlyaws-list
Post recived from mailinglist
Guest
Posted: Mon Mar 05, 2007 9:31 pm Reply with quote
Guest
m

Display posts from previous:  

All times are GMT
Page 2 of 3
Goto page Previous  1, 2, 3  Next
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 can attach files in this forum
You can download files in this forum