Created
July 7, 2009 10:15
-
-
Save lenst/141998 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;;; 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