Erlang/OTP Forums

Author Message

<  Advanced Erlang/OTP  ~  Yaws, SSI and YSSI...

seancharles
Posted: Sat Jan 05, 2008 10:45 am Reply with quote
User Joined: 18 Jul 2007 Posts: 57
Help!

SUMMARY: Multiple nested includes of .yaws files within .yaws files, how to make them all expand properly ?

Read on...

I am stuck in a quandary and before I get too much further I need to get some decisions made but I am a little confused / stuck / ignorant of the possibilities.

Currently I am using yaws for my web application but I am finding it a little 'tricky' to do what I want.

When it sees a '.yaws' file it compiles and processes the page. I am using the {ssi, File, [], []} form in my returned code to yaws but when I change it to the {yssi, File} form it blows chunks and I can 'understand' the error but don't know how to circumvent it.

I want to be able to put code like this:
Code:

<erl>
out(A)-> page:contact_form.
</er>
in my files that are dragged in via {ssi,...} but the <erl> tags won't be expanded.

Is there a way then to be able to have a page that is ssi-d to also include yaws code.

I tried calling the yaws_compile:compile_file() function directly and the tuple it hands back didn't really leave me any the wiser as to how to get to the generated content!

So, is it worth continuing with yaws or should I drop it and use the standard 'web-server' and the jungerl 'stl' module, both of which I have evaluated and like but yaws seems to be a little more 'with it' in terms of features etc etc but that could be based on my as yet rank amateur status as an Erlang developer!

So, has anybody got any good ideas on how to get this done?

Cheers
->Sean Charles
PS: Happy New Year Everybody Smile
View user's profile Send private message
rbucker881
Posted: Sat Jan 05, 2008 5:07 pm Reply with quote
User Joined: 11 Oct 2007 Posts: 17
First of all... don't give up. In the absence of a "compile and includenow" method the solution to the challenge is pretty simple but it means thinking upside down. (sort of).

PS: I've been considering adding a {yssi,filename,[],[]} that works like {yssi,filename} but I've been able to work my way out each time.

As for the solution... think MVC. In my case I implemented a generic appmod that I use for all applications. Looks like:

Code:

out(A) ->
    Opts = A#arg.opaque,
    ?TESTCALL(Target = bs:getoption(Opts,"BasePage")),
    ?LOG(["OUT -> WORKING ::",[Target]]),
    {yssi,Target}.


In my yaws.conf file I indicate which YAWS file to launch. That file is now my controller even though yaws is also a controller.

This main yaws file is broken into two parts. The first part results in a {bindings,[stuff]} where I get my common headers, footers and such...


Code:

        Opts = A#arg.opaque ++ [{"Menu",Menu},{"Adspace",Adspace},{"Footer",Footer},{"Header",Header}],
        {bindings,Opts}.


then the second section is the switch:


Code:

    out(A) ->
        Opts = A#arg.opaque,
        YSSI = bs:getoption(Opts,"YSSI"),
        {P1,P2} = case A#arg.appmoddata of
            undefined -> {"",""};
            P -> {P,bdt:filter(P)}
        end,
        if
            P2 =:= "" ->
                {yssi,YSSI++"/homepage.yaws"};
            P2 =:= "rss" ->
                {yssi,YSSI++"/zrss.yaws"};
            P2 =:= "doc" ->
                {yssi,YSSI++"/"++P2++"page.yaws"};
            true -> []
        end.


inside the YSSI file I'll do my "controller" work, add the value(s) to a list that I then forward to {ssi,filename.[].[]}.

Take a look at some of the apis:


Code:

[FooterB] =  yaws_api:ehtml_expander({ssi,SSI++"/footer.ssi","%%",POpts}),
Footer = binary_to_list(FooterB),


Also, I've had troubles expanding text from text.... I'll be improving this.

Code:

expandssi(Template,Delim,Bindings) ->
    Data = yaws_server:delim_split_file(Delim,Template,data,[]),
    Parts = yaws_server:expand_parts(Data,Bindings,[]),
    lists:append(Parts).



PS: this code was cut/pasted from my various projects. I'm working on a "template" project which I will publish soon enough.
View user's profile Send private message
rbucker881
Posted: Sun Jan 06, 2008 4:58 am Reply with quote
User Joined: 11 Oct 2007 Posts: 17
FYI: I tried to implement the {yssi,filename} inside yaws_api and yaws_server and it was just too hard. When I got deep into it I discovered it was just out of the scope of the project unless that part of the server is refactored.

yaws_compile:compile_file(), by itself is insufficient, it requires something to call/render the compiled code. In the server code it looks like:


Code:

       {ok, [{errors, Errs}| Spec]} =
      yaws_compile:compile_file(UT#urltype.fullpath),
            . . .
       deliver_dyn_file(CliSock, Spec, ARG, UT, N)


I did not dig too deeply into deliver_dyn_file(), however, I was left with the impression that it delivers the resulting output to the "CliSock" which appears to be the output socket, instead of a string(list) that could be manipulated.

So, my first recommendation stands. Use an MVC approach. It works really well. Add to that; you might create some library classes to fill in the gaps.

And one last possibility... implement you code as a series of private REST calls to a private REST server.

Good luck,
Richard
View user's profile Send private message
seancharles
Posted: Mon Jan 07, 2008 12:12 am Reply with quote
User Joined: 18 Jul 2007 Posts: 57
Agree!

I am already past these issues; I've created a nice little system for myself. The end product is a 'killer-app' (I hope) and it only requires that I be able to quickly put together content with EHTML.

EHTML is now a second language!

I've got a nice form handling / command routing system in place too. Might detail it one day.

Cheers guys!
Smile
->Sean Charles
View user's profile Send private message

Display posts from previous:  

All times are GMT
Page 1 of 1
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