summaryrefslogtreecommitdiff
path: root/utilities.lisp
blob: 5499755da922a251c2b84d5d17ff209c5dd72112 (plain)
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
;;; utilities.lisp

(in-package :arclade)

(defun read-from-file (path)
  (read-from-string
   (alexandria:read-file-into-string path)))

(defvar *epoch* (encode-universal-time 0 0 0 1 1 1970)
  "Jan 1 1970 Unix Epoch time in CL universal time.")

(defun format-time (time)
  (multiple-value-bind (_ min hour day month year)
      (decode-universal-time time)
    (declare (ignore _))
    (format nil "~2,'0d-~2,'0d-~a ~2,'0d:~2,'0d"
	    month day year hour min)))

(defun host-path (str)
  (with-slots (host port) *config*
    (quri:render-uri
     (quri:make-uri-http :host host :port port :path str))))

(defmacro with-page ((&key title) &body body)
  "A helper macro for defining some standard page boilerplate."
  (let ((title-var (gensym)))
   `(let ((,title-var ,title))
      (with-html-string
        (:doctype)
        (:html
         (:head
	  (:script :src "http://localhost:8080/skewer")
	  (:link :href ,(host-path "css/style.css") :rel "stylesheet")
          (:title ,title-var))
         (:body
          ,@body))))))