OK so I've got a first draft of something simple.

As opposed to what has been requested before this is NOT a web
development framework in the sense of RoR or even Ring.

Instead I've opted to create a simple environment from which
frameworks utilizing conventions and such can be built, both a RoR
type of thing or a simpler Ring style framework is possible to create
from pl-web.

What we have is a few basic things:

1.) An ability to inspect the current look of the URL (se line 87 and
120 in pl-web.l).

2.) File based sessions (ugly yes but will not make demands on how any
database should look like). See line 109 in pl-web.l.

3.) Trying as hard as we can to utilize Linux system
functions/commands in order to alleviate the need for libraries (see
cmd.l).

How to test:

1.) Unpack the attached file into /opt/picolisp and create
/tmp/pl-web/sessions/.

2.) Create a folder called simple-web-app in /opt/picolisp/projects
and paste the following into a main.l file there:

(load
   "pl-web/pl-web.l"
   "pl-web/pl-html.l")

(de login (Msg)
   (<plw-form> NIL ""
      (<span> NIL "Username:")
      (<plw-field> "text" "username" (gReq "username"))
      (<br>)
      (<span> NIL "Password:")
      (<plw-field> "password" "password" "")
      (<br>)
      (<submit> "Submit")
      (<br>)
      (<span> NIL Msg) ) )

(de app ()
   (fatApp
      (html 0 "PL Web" *Css NIL
         (<div> NIL (println "Post: " *Post " Cookies: " *Cookies))
         (cond
            ((= (car *Urll) "login")
             (ifn (and (= (gReq "password") "test") (= (gReq
"username") "test"))
                (login (if (gReq "username")
                          "User not found."
                          "Please login." ) )
                (sSess 'logged-in-user "test")
                (<div> NIL "Login successful.") ) )
            ((= (car *Urll) "whoami")
             (<div> NIL (prin "You are: " (gSess 'logged-in-user))) )
            (T ("Nothing to do.")) ) ) ) )

(de start ()
   (off *JS))

(de go ()
   (server 8080 "!start") )

3.) Start it: henrik@henrik-laptop:/opt/picolisp$ ./pil
projects/simple-web-app/main.l -go

4.) Browse to: http://localhost:8080/login and submit the form with
test in both fields.

5.) Browse to: http://localhost:8080/whoami

That's it, I think inspection of the code plus testing in #4 and #5
above should be enough to understand how this works.

A few TODO/Thoughts:

1.) Swiping stale sessions in the sessions folder. Some kind of
timeout value might be needed, if combined with a random initializer
we have recreated the ugliness of PHP session handling to perfection.

2.) Port of the current xhtml.l library (which we are currently
relying heavily on), as can be seen I've started a little in the
pl-html.l file, all that *JS stuff etc needs to go.

3.) Some brave soul needs to create a real, clever, framework from
this that is beautiful enough that it might get some attention. What
was that earlier suggestion, Bumblebee? Don't know about the name
though as it brings to mind something that looks so heavy it should
not be able to fly, yet does. Perhaps not something we want associated
with PicoLisp.

4.) If it would be possible for PL to have several databases open at
the same time (I have a vague memory of discussing this at some point
in the past) stuff like session handling could done through a DB
instead and without making demands on the main application E/R.

Comments?

/Henrik Sarvell

Attachment: pl-web.tar.bz2
Description: BZip2 compressed data

Reply via email to