Dragonfly - a web framework for newLISP

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

Previous topic - Next topic

itistoday

#60
Quote from: "cormullion"What's the best way to do Atom/Rss? I've got the code to provide the information, not sure about the routes...


If you're serving a static file for your feed then you can just add its extension to the STATIC_TRIGGER_EXTENSIONS in the config.lsp.



You're probably generating it on-the-fly though, so that's probably not what you want.



Instead just make a view (i.e. /feed) and place your newLISP code that outputs your Atom/RSS feed in it. Make sure to set the proper MIME-type though somewhere in there. I.e. place a call like this in your feed view somewhere:


(Response:content-type Response:xml-type)

Or provide your own string:


(Response:content-type "application/atom+xml")

In summary, this would be best done with a view + proper MIME type, there's no need to create a route for this (I don't think).


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


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


That function is from the example-site, it's defined in plugins-active/dragonfly_basic.lsp and uses the symbol DF:viewname (which is set by the STATIC_TRANSFORMATIONS in config.lsp).


QuoteAlso, 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...


newLISP doesn't support the .htaccess redirection that apache does (see the explanation in the Getting Started part of the User Guide), and Dragonfly uses the QUERY_STRING to determine which view/resource is being accessed.



However, I've just added functionality to the mercurial repository that removes the need for the ? even when using the built-in newLISP server.



For more information, see the comments in this thread: http://newlispfanclub.alh.net/forum/viewtopic.php?f=2&t=3168">//http://newlispfanclub.alh.net/forum/viewtopic.php?f=2&t=3168



BTW, when 0.51 is released (or if you're using the latest mercurial), use the newlispServer script to run the newlisp server (as it's no longer as simple as it was). Like this:


$ cd path/to/example-site
$ ./newlispServer
Get your Objective newLISP groove on.

cormullion

#61
Wow, great tech support too! Thanks. I'll try to get this all working today...



By the way, when you update the framework, you won't overwrite all my changes in "plugins-active" will you? :)

itistoday

#62
Quote from: "cormullion"By the way, when you update the framework, you won't overwrite all my changes in "plugins-active" will you? :)


Nope. As long as you're not modifying the files that come with Dragonfly and are creating your own plugins your changes won't be overwritten and no conflicts should arise.
Get your Objective newLISP groove on.

cormullion

#63
Got most things working OK. One exception: an Atom feed. I'm struggling to make any progress with this - ran out of time for now - but hope to address the problem soon.



As I see it, this is the process that ought to work:



1 user request is for 'atom' - http://blah.com/atom">http://blah.com/atom



2 dragonfly converts this to a request to display the view file 'atom.html' in views/ ('html'? - well, your RSS file is 'dragonfly_rssfeed.html' in 'views/'.)



3 the 'atom.html' file generates the XML output:
<% (Response:content-type "application/atom+xml") %>
<% (Dragonfly:display-partial "head") %>
code to generate XML using partial templates
<%  (Dragonfly:display-partial "story") %>
<% (Dragonfly:display-partial "foot") %>


where the partial files are called head.xml story.xml and foot.xml. (Or should they be 'html'?)



5 the header for the main web page refers to the XML feed using this function:


(rss "Dragonfly web framework RSS Feed" (web-root "?dragonfly_rssfeed/xml"))

or does there need to be an 'atom' version of this?



Anyway, apart from this one area I've yet to get to grips with, things are looking good!

cormullion

#64
I found a strange bug relating to the nldb database code... I'm using a revised version of nldb.lsp in plugins-active, but don't know whether you want to add it - or let me add it someday...

itistoday

#65
Quote from: "cormullion"2 dragonfly converts this to a request to display the view file 'atom.html' in views/ ('html'? - well, your RSS file is 'dragonfly_rssfeed.html' in 'views/'.)


.html if the VIEW_EXTENSION is .html.


Quote3 the 'atom.html' file generates the XML output:
<% (Response:content-type "application/atom+xml") %>
<% (Dragonfly:display-partial "head") %>
code to generate XML using partial templates
<%  (Dragonfly:display-partial "story") %>
<% (Dragonfly:display-partial "foot") %>


Not really, I'm not sure why you're outputting the head/story/footer as you're not displaying an HTML document but an RSS/Atom feed.


Quotewhere the partial files are called head.xml story.xml and foot.xml. (Or should they be 'html'?)


Check http://www.rundragonfly.com/dragonfly_templates">the docs for VIEW_EXTENSION. It's also documented via comments in config.lsp.



If VIEW_EXTENSION is .html, they should be .html if you're using the display-partial/display-view functions. Use display-file/include if you want to avoid the use of VIEW_EXTENSION. See the Dragonfly API for details.


Quote5 the header for the main web page refers to the XML feed using this function:


(rss "Dragonfly web framework RSS Feed" (web-root "?dragonfly_rssfeed/xml"))


Hmm... that's actually outdated (from pre-0.50), I'll fix that. 'web-root' should not have the ? specified in the string and there's no need for the "/xml" after "dragonfly_rssfeed".


Quoteor does there need to be an 'atom' version of this?


If you want to display an atom feed include the appropriate markup to display atom feeds. I personally don't recommend relying too heavily on Dragonfly's markup-shortcut functions like 'rss', it's just as easy to include the actual HTML markup (check what 'rss' does, it's defined in dragonfly_basic.lsp, it's just a shortcut for the the 'link' tag to include an rss file in the page). If you're confused, http://www.google.com/search?q=display+atom+feed">check with google.
Get your Objective newLISP groove on.

cormullion

#66
OK, gotcha. I've probably been assuming that I should switch to '.xml' extensions at some stage but sticking with 'html' all the way helps - at least, hitting http://unbalanced-parentheses.nfshost.com/atom">//http://unbalanced-parentheses.nfshost.com/atom seems to want to produce Atom XML.



The head/story/footer stuff is just so that I can output the XML heading stuff (author update etc) and then loop through each of the last x items.



Thanks again for the help!

cormullion

#67
I have one more problem... I'm finding that some pages are being processed through Dragonfly but I didn't think they were going to be (they're not views). For example, if you go to http://unbalanced-parentheses.nfshost.com/downloads/mycroft.nl.html">//http://unbalanced-parentheses.nfshost.com/downloads/mycroft.nl.html - it's a page generated by newlispdoc - and click on source, the resulting HTML file is being passed through Dragonfly:eval-template. Unfortunately that file contains text (probably multiple [text][/text] pairs) that causes eval-template to fail. It's not  supposed to be a template.


ERR: missing parenthesis : "..."'(){}.0123456789[/text])
called from user defined function Dragonfly:eval-template
called from user defined function Route.Static:run
called from user defined function Dragonfly:listener
called from user defined function run


I thought that files came through 'as they were' if they didn't match anything else. I'm wondering whether I've done something that makes Dragonfly try to evaluate all files...

itistoday

#68
cormullion, please take a look at how Route.Static works:



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



It will match all files that end in VIEW_EXTENSION, and your source page does as well. Therefore if there are any "code islands" (i.e. stuff that comes after OPEN_TAG: <%) then that will be interpreted as newLISP code and it will be evaluated.



If you don't want that file getting sent through eval-template then there are several things you can do:



- Update your .htaccess file with a RewriteCond to prevent files ending in .src.html from being sent to the index.cgi script. This requires knowledge of .htaccess files (search google for mod_rewrite).



- Do it instead through a custom route that checks if the QUERY_STRING represents one of your source files and then simply pass it through the 'display-file' function. Make sure this route is added to the front of 'DF:dragonfly-routes' so that it gets evaluated before Route.Static.



- Change your VIEW_EXTENSION to something else (and change all your template files as well to that other extension).



In a future version of Dragonfly we could probably add a hook to Route.Static that will allow you to define a function that determines whether the file should be passed through display-view or display-file (as the former sends it through eval-template and the latter doesn't), but for now your easiest solution is to add a custom route, which isn't difficult to do (again, the docs really help you here).



EDIT] Whoops, that's DF:include, not DF:display-file. DF:display-view calls DF:display-file which calls DF:eval-template. Apparently I don't know what my own code does. :-p
Get your Objective newLISP groove on.

cormullion

#69
OK, thanks! I can solve it by passing it to DF:include... I didn't fully appreciate the fact that every matching file, not just a view file, is passed through eval-template. Makes sense now, though.



I have to admit that I've studied the documents, but still find it hard to solve problems - I'm not a web developer, so I don't have the basics down yet.

itistoday

#70
Quote from: "cormullion"OK, thanks! I can solve it by passing it to DF:include... I didn't fully appreciate the fact that every matching file, not just a view file, is passed through eval-template. Makes sense now, though.


Ack! Sorry for giving you bad information, I've edited my post to mention that DF:include is what you want, not DF:display-file. You figured it out though. :-)


QuoteI have to admit that I've studied the documents, but still find it hard to solve problems - I'm not a web developer, so I don't have the basics down yet.


Just takes practice, you'll get it. :-)



BTW, I *love* your magical rainbow code highlighter stuff.
Get your Objective newLISP groove on.

cormullion

#71
Quote from: "itistoday"BTW, I *love* your magical rainbow code highlighter stuff.


:) I'm still trying to decide whether it's just cool or useful as well!



I realized I haven't uploaded the code for that; it's now uploaded as Module Nestor.

joejoe

Re:
#72
Quote from: "hilti"
* changed license from MIT to GNU (GPL v3)

Hi, just noticed the ohloh.net Dragonfly listing still has the old license.



http://www.ohloh.net/p/dragonfly-newlisp">http://www.ohloh.net/p/dragonfly-newlisp



Just wanted to let hilti know so he could update it there when he has a chance.



thanks!

hilti

#73
Changed! :-)



Thanks JoeJoe!

Hilti
--()o Dragonfly web framework for newLISP

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

joejoe

#74
super duper! :D