/examples/ajax-browse-freebase.lisp

http://github.com/mtravers/wuwei · Lisp · 68 lines · 57 code · 11 blank · 0 comment · 0 complexity · 2f19e1867972a331fa72c35ee121a906 MD5 · raw file

  1. (in-package :wu)
  2. (publish :path "/fb-browse"
  3. :content-type "text/html"
  4. :function 'fb-browse-page)
  5. (setq *default-no-session?* t)
  6. (defun render-frame (f)
  7. (html
  8. ((:div :id (mt:fast-string f) :style "border:1px solid gray")
  9. ((:span :style "background:gray;")
  10. (:b (:princ-safe (frame-human-name f))))
  11. :br
  12. ((:div )
  13. (:table
  14. (dolist (slot (list-limit (frame-slots f))) 100))
  15. (html
  16. (:tr
  17. (:td
  18. (:princ-safe (frame-human-name (car slot))))
  19. (:td
  20. (dolist (val (list-limit
  21. (cdr slot)
  22. 6))
  23. (html (render-value val)
  24. :br)))))))))
  25. (def-cached-function frame-slots (f)
  26. (mql-all-properties f :get-frames? t))
  27. (defun frame-slot-value (f slot)
  28. (assocdr slot (frame-slots f)))
  29. (defun frame-human-name (f)
  30. (frame-slot-value f :name))
  31. (defun framep (thing)
  32. (or (keywordp thing)
  33. (and (stringp thing)
  34. (char= (char thing 0) #\/))))
  35. (defmethod render-value ((thing t))
  36. (if (framep thing)
  37. (render-value thing)
  38. (html (:princ-safe thing))))
  39. (defmethod render-value ((f ocelot-gfp::frame))
  40. (let ((id (string (gensym "id"))))
  41. (html
  42. ((:span :id id)
  43. (link-to-remote (frame-human-name f)
  44. (ajax-continuation ()
  45. (render-update
  46. (:replace id
  47. (render-frame f)))))))))
  48. (defun list-limit (l n)
  49. (subseq l 0 (min n (length l))))
  50. (defun dbrowse-page (req ent)
  51. (with-http-response-and-body (req ent)
  52. (html (:head
  53. (javascript-includes "prototype.js" "effects.js" "dragdrop.js")
  54. )
  55. (:body
  56. (:h1 "Dbrowse")
  57. (render-frame "/en/marvin_minsky")))))