Skip to content

Instantly share code, notes, and snippets.

@cmoore
Created November 19, 2011 06:37
Show Gist options
  • Save cmoore/1378548 to your computer and use it in GitHub Desktop.
Save cmoore/1378548 to your computer and use it in GitHub Desktop.
(ql:quickload 'hunchentoot)
(ql:quickload 'cl-who)
(ql:quickload 'routes)
(ql:quickload 'css-lite)
(defpackage :rss-view
(:use :cl :hunchentoot :cl-who :css-lite)
(:export :rss-start :rss-stop))
(in-package :rss-view)
(defparameter *site-acceptor*
(make-instance 'hunchentoot:easy-acceptor :port 8080))
(defun rss-start ()
(hunchentoot:start *site-acceptor*))
(defun rss-stop ()
(hunchentoot:stop *site-acceptor*))
(defun setup-dispatch ()
(setq *dispatch-table*
(list
(create-regex-dispatcher "^/css" 'handler-css)
(create-regex-dispatcher "^/$" 'handler-index))))
(setup-dispatch)
(defmacro with-page (title body)
`(with-html-output-to-string
(*standard-output* nil :prologue nil :indent nil)
(:html
(:head
(:meta :charset "utf-8"
(:title ,title)
(:link :rel "stylesheet"
:type "text/css"
:href "/css")
(:link :rel "stylesheet"
:type "text/css"
:href "http://fonts.googleapis.com/css?family=Ubuntu+Mono|\
Ubuntu")
(:script :type "text/javascript"
:src "https://ajax.googleapis.com/ajax/libs/jquery/1.6.4\
/jquery.min.js")))
(:body
(,@body)))))
(defun handler-index ()
(start-session)
(with-page "Hello"
(:div :class "container"
(:div :class "menu"
(:table
(:tr
(:td :colspan "2" (:strong "Menu")))
(:tr
(:td "Feeds")
(:td (:a :href "/feeds" "->")))))
(:h2 "Hello"))))
(defun handler-css ()
(css
(("body") (:font-family "Ubuntu"))
(("div.menu") (:font-size "12px"
:float "right"
:padding "4px"
:border "1px solid #ccc"))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment