Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 53 lines (44 sloc) 1.525 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
;;;; example 2

(asdf:operate 'asdf:load-op :cl-who)
(asdf:operate 'asdf:load-op :restas)

(restas:defsite :restas.example-2
  (:use :cl :iter))

(in-package :restas.example-2)

(restas:define-site-plugin default (:restas.example-2))

(define-route root ("")
  (who:with-html-output-to-string (out)
    (:html
     (:head
      (:title "Example 2: Index"))
     (:body
      (:h1 "Index")
      (:ul
       (iter (for x from 1 to 10)
             (who:htm (:li
                       ((:a :href (genurl 'chapter-?.html :id x))
                        (who:fmt "Chapter ~A" x))))))))))

(define-route chapter-?.html ("chapter-:(id).html")
  (who:with-html-output-to-string (out)
    (:html
     (:head
      (:title (who:fmt "Example 2. Chapter ~A" id)))
     (:body
      (:h1 (who:fmt "Chapter ~A" id))
      (:ul
       (iter (for x from 1 to 10)
             (who:htm (:li
                       ((:a :href (genurl 'chapter-?-?.html :id1 id :id2 x))
                        (who:fmt "Chapter ~A-~A" id x))))))
      ((:a :href (genurl 'root))
       "Back to Index")))))

(define-route chapter-?-?.html ("chapter-:(id1)-:(id2).html")
  (who:with-html-output-to-string (out)
    (:html
     (:head
      (:title (who:fmt "Example 2. Chapter ~A-~A" id1 id2)))
     (:body
      (:h1 (who:fmt "Chapter ~A-~A" id1 id2))
      (:p (who:fmt "This is a chapter ~A-~A" id1 id2))
      ((:a :href (genurl 'chapter-?.html :id id1))
       (who:fmt "Back to Chapter ~A" id1))))))
  
(restas:start-site :restas.example-2 :port 8080)
Something went wrong with that request. Please try again.