Skip to content

Instantly share code, notes, and snippets.

@lenst
Created July 7, 2009 10:15
Show Gist options
  • Save lenst/141998 to your computer and use it in GitHub Desktop.
Save lenst/141998 to your computer and use it in GitHub Desktop.
;;; Example from compojure rewritten for use with webpub.
;;; Look no dependencies!
(ns example)
(defn html-doc
[title & body]
[:html
[:head
[:title title]]
[:body
[:div
[:h2
[:a :href "." "Home"]]]
(cons nil body)]])
(def sum-form
(html-doc
"Sum"
[:form :method "GET" :action "calc"
[:p
[:input :size 3 :name "x"]
"+"
[:input :size 3 :name "y"]
[:input :type "SUBMIT" :value "="]]]))
(defn result
{:webargs ["x" "y"]}
[x y]
(let [x (Integer/parseInt x)
y (Integer/parseInt y)]
(html-doc "Result"
[:p x " + " y " = " (+ x y)])))
(def web-root
{"" {nil #'sum-form}
"calc" {nil #'result}})
(comment
(require 'net.cddr.webpub)
(net.cddr.webpub/publish "ex1" #'web-root))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment