Advertisement
Shinmera

Radiance Basic Usage Demonstration

Jul 5th, 2013
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lisp 1.05 KB | None | 0 0
  1. ;;;; Short code example to demonstrate basic Radiance development.
  2.  
  3. ;; Include radiance package to get access to all the necessary things as well as lQuery for page construction.
  4. (use-package '(:radiance :lquery))
  5. ;; Start Radiance
  6. (manage #'start)
  7.  
  8. ;; Define a new module
  9. (defmodule my-module ()
  10.   "My first radiance module."
  11.   (:name "My Module" :version "0.0.1" :author "The Future"))
  12.  
  13. ;; Create a new method on the module that'll print a page using lQuery.
  14. (defmethod my-page ((module my-module))
  15.   ($ (initialize #p"/path/to/template.html"))
  16.   ($ "h1" (html "Hi!"))
  17.   ($ "p" (html "Welcome to... <b>THE FUTURE!</b>"))
  18.   (first ($ (serialize))))
  19.  
  20. ;; Define a hook for the method and register it with the dispatcher.
  21. (defhook 'my-page (get-module 'my-module) #'my-page)
  22. (register (implementation 'dispatcher) 'my-page)
  23.  
  24. ;; You can now call http://localhost:4545/ in your browser and you should see your page!
  25. ;; Of course, assuming your radiance config is set up to listen on port 4545
  26. ;; and the template file used in my-page actually exists.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement