Dragonfly - a web framework for newLISP

Started by hilti, June 26, 2009, 02:51:13 AM

Previous topic - Next topic

cormullion

#45
Thanks for the help! I'm not sure I really know what a route is.



In the last version, I had code in the 'view' that took action depending on the selector:


<div id="right">    
    <% (Dragonfly:load-database "blog.nldb") %>
   
    <% (if (= "" Dragonfly:selector)
           (set 'query (nldb:select-rows 'nldb:stories true true 'nldb:story-date >))
           (set 'query (nldb:select-rows 'nldb:stories '(= nldb:story-id Dragonfly:selector)))) %>
   
    <% (unless query (set 'query (nldb:select-rows 'nldb:stories '(= nldb:story-id "aboutthissite")))) %>

    <% (set 'story (first query)) %>
    <% (println {<h1>} (story 2) {</h1>}) %>
    <% (println {<small>} (story 0) {</small>}) %>
    <% (println (last story)) %>

</div>


Do I put this code in a .lsp file in 'plugins-active' (the static route you're talking about)? I would have thought it belonged in the view.



Forgive the stupid questions - I'm trying to catch you up but you're going too fast for me.:)

itistoday

#46
cormullion, I've updated the dragonfly_routes page with some more detail, read through it carefully, it should explain what they are and how they work. Also, take a look at the page on creating templates (also in the guide).



As of this post it's not up on rundragonfly.com, so view the example-site in your web browser locally using newlisp as the server (again, see the INSTALL and README files if you don't know how to do this). Before doing that though you'll need to pull the latest changes as I showed above first.
Get your Objective newLISP groove on.

itistoday

#47
Quote from: "cormullion"In the last version, I had code in the 'view' that took action depending on the selector:


<% (if (= "" Dragonfly:selector)


BTW, Dragonfly:selector has been removed. Views no longer have selectors or actions, if you want something like that either make a resource (see the guide on the RESTful route) or use GET/POST parameters with your views instead, or create your own route. If you need help, check the docs, they probably have the answer to your question, but if they don't let us know!
Get your Objective newLISP groove on.

cormullion

#48
Thanks guys, Dragonfly is looking pretty impressive now. I've been reading the docs again. You've done a nice job.



Here's my problem. I already have the URLs I want (see above). I don't think I can use "RESTful routes" because the first value in these (the resource) has to be the name of the context whereas in my URLs I want it to be the name of the ID (the specific object in the collection). I don't want to create static routes because I don't want to create a page for each ID.



I suppose I'll have to use .htaccess to rewrite the incoming URL to  insert a 'resource' identifier before the ID, and then use the 'action' to store the ID and pass it on to the .lsp resource. And then I can just go 'print' to output HTML? But then what happened to the template...

itistoday

#49
Quote from: "cormullion"I don't want to create static routes because I don't want to create a page for each ID.


I looked at your URLs again (I hadn't really read your original post) and it seems like creating a page for each of those is the solution you're looking for, otherwise you're not really using Dragonfly to your advantage and end up rewriting a lot of the stuff that it handles efficiently and cleanly for you. You also end up with a massive single file that has a huge if/else block in it...



I'd consider splitting all of your pages into separate files the way the example-site does, but if you don't want to do that then just disable both of the default handlers in config.lsp and create your own route (as described in the guide). Your route would simply grab the first part of the request URL, set the DF:selector, and display your main file. Or you could even check the $GET parameters, i.e.: (if (nil? ($GET "downloads/foo")) ...)



Documentation on all of that ($GET, how to display files, etc.) is in the Core API (linking to my copy since rundragonfly.com currently isn't updated):



http://www.taoeffect.com/dragonfly-newlisp/example-site/dragonfly_api">http://www.taoeffect.com/dragonfly-newl ... gonfly_api">http://www.taoeffect.com/dragonfly-newlisp/example-site/dragonfly_api
Get your Objective newLISP groove on.

Lutz

#50
Congratulations! Is this the official link to the Dragonfly docs?



http://www.taoeffect.com/dragonfly-newlisp/example-site/dragonfly_api">http://www.taoeffect.com/dragonfly-newl ... gonfly_api">http://www.taoeffect.com/dragonfly-newlisp/example-site/dragonfly_api



let me know when I can link to this (or other address) from the http://www.newlisp.org/modules/">http://www.newlisp.org/modules/ page.

itistoday

#51
Quote from: "Lutz"Congratulations! Is this the official link to the Dragonfly docs?



http://www.taoeffect.com/dragonfly-newlisp/example-site/dragonfly_api">http://www.taoeffect.com/dragonfly-newl ... gonfly_api">http://www.taoeffect.com/dragonfly-newlisp/example-site/dragonfly_api


That's just my personal testing ground for Dragonfly with Apache, the official link will be on the rundragonfly site once 0.50 is released:



http://www.rundragonfly.com/dragonfly_api">//http://www.rundragonfly.com/dragonfly_api



That site isn't up-to-date as of this posting though.


Quotelet me know when I can link to this (or other address) from the http://www.newlisp.org/modules/">http://www.newlisp.org/modules/ page.


Definitely! :-)



I think 0.50 should be around the corner very soon, the core I think is done and so is the User's Guide. Here's a link to the first page:



http://www.taoeffect.com/dragonfly-newlisp/example-site/dragonfly_welcome">//http://www.taoeffect.com/dragonfly-newlisp/example-site/dragonfly_welcome
Get your Objective newLISP groove on.

cormullion

#52
Quote from: "itistoday"it seems like creating a page for each of those is the solution you're looking for [...]



... I'd consider splitting all of your pages into separate files


Each of those URLs is (when stripped of the domain name) the ID of an entry in a database. It made sense to me to have a single 'design' or template which was then applied to the information when extracted from the database. I'll have another look at the documents and work out  how to do it the new way.

itistoday

#53
Quote from: "cormullion"Each of those URLs is (when stripped of the domain name) the ID of an entry in a database. It made sense to me to have a single 'design' or template which was then applied to the information when extracted from the database. I'll have another look at the documents and work out  how to do it the new way.


Ah! Gotcha, sorry, I didn't know that's what you were doing, and my sincere apologies if you mentioned it (I must have missed that part *whoops*).



In that case then a custom-route is the way to go, and yours should be extremely simple. For info on how to create a route (as well as an example) see this page:



http://www.taoeffect.com/dragonfly-newlisp/example-site/dragonfly_create_routes">//http://www.taoeffect.com/dragonfly-newlisp/example-site/dragonfly_create_routes



Or once it's updated, the official page:



http://www.rundragonfly.com/dragonfly_create_routes">//http://www.rundragonfly.com/dragonfly_create_routes



If you're not going to be using the other routes you can disable them, or place yours at the head of the 'dragonfly-routes' list so that it's evaluated first (for efficiency).
Get your Objective newLISP groove on.

hilti

#54
Quote from: "Lutz"Congratulations! Is this the official link to the Dragonfly docs?



http://www.taoeffect.com/dragonfly-newlisp/example-site/dragonfly_api">http://www.taoeffect.com/dragonfly-newl ... gonfly_api">http://www.taoeffect.com/dragonfly-newlisp/example-site/dragonfly_api



let me know when I can link to this (or other address) from the http://www.newlisp.org/modules/">http://www.newlisp.org/modules/ page.


The official Dragonfly docs are here now: http://www.rundragonfly.com/dragonfly-api/index.html">//http://www.rundragonfly.com/dragonfly-api/index.html

Or in our site design: http://www.rundragonfly.com/dragonfly_api">//http://www.rundragonfly.com/dragonfly_api



Cheers

Marc
--()o Dragonfly web framework for newLISP

http://dragonfly.apptruck.de\">http://dragonfly.apptruck.de

Lutz

#55
... Dragonfly docs-index and site are now also accessible from here:



http://www.newlisp.org/modules/">http://www.newlisp.org/modules/



and here:



http://www.newlisp.org/index.cgi?Code_Contributions">http://www.newlisp.org/index.cgi?Code_Contributions



Not sure if the home page links for the authors Marc and Greg are correct on that last page.



Ps: The http://www.newlisp.org/code/modules/sqlite3.lsp.html">http://www.newlisp.org/code/modules/sqlite3.lsp.html module and help page has also been updated again.

cormullion

#56
I've nearly got my site working on Dragonfly 0.50. It's just me being slow - it's like waking up and finding that someone's moved all the furniture... :)



I can't quite work out one thing - how to make the forms work. For example, in the old version, I had this sort of thing for 'search':


<div class="form">
      <form id="search" action="/search/for" method="POST" />
      <p>
      <input type="text" class="input" name="inputstring" size="8" value="" />
      <input type="submit" name="search" value="Search">
      </p>
      </form>
    </div>


where the "/search/for" got translated somehow, and the template called 'search' was loaded; the search string was obtained by


<% (set 'search-text (lookup "inputstring" Web:POST)) %>

My mind's now gone blank and I can't work out how to set this up in a completely different way.



I have many questions - but first i want to say "awesome job" for all this cool stuff!

hilti

#57
Hi Cormullion!



Great to hear You're working with the new Dragon :)



The POST variables can be accessed like this for Your form.


<% (print ($POST "inputstring")) %>

Hope this helps!



Cheers

Hilti



Example with form:


<div class="form">
      <form id="search" action="" method="POST" />
      <p>
      <input type="text" class="input" name="inputstring" size="8" value="" />
      <input type="submit" name="search" value="Search">
      </p>
      </form>
</div>

<p>
<% (print ($POST "inputstring")) %>
</p>
--()o Dragonfly web framework for newLISP

http://dragonfly.apptruck.de\">http://dragonfly.apptruck.de

m35

#58
I'm quite impressed the site! It's very clean and simple to navigate and understand. The Getting Started walk-though made sense and should make it easy for people to get started.



I've never done any serious web development, but if ever I did, Dragonfly would be a serious contender for my api. It has that very accessible bar of entry, just like newLISP does.

cormullion

#59
Quote from: "hilti"Hope this helps!

Yes, thanks! That's nice and easy.



I'm now running Dragonfly 0.50 at http://unbalanced-parentheses.nfshost.com/">//http://unbalanced-parentheses.nfshost.com/, and it's working quite well. There's a long list of things to do though.. :)



What's the best way to do Atom/Rss? I've got the code to provide the information, not sure about the routes...



How do you set the title of a page? Looks like the function call in header or something...


<title><% (title) %></title>

Also, I'm puzzled by how the question mark in the URL routes (eg "?welcome") disappears when I'm using  Apache, but appears when using newLISP server. Why is that? It's making the search fall over but it works locally using newLISP server...



Anyway, thanks again to Team Dragonfly!