Created
January 6, 2010 19:10
-
-
Save devn/270537 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
;============================== | |
; Communicate with the server | |
;============================== | |
(defn get-doc [doc] | |
(str (sh *markdown-command* (str *core-docs* doc) "-x" "codehilite") | |
(if (examples-which-exist doc) | |
(sh *markdown-command* (str *examples-dir* doc) "-x" "codehilite")))) | |
;============================== | |
; Layout | |
;============================== | |
(defn app-layout [& body] | |
(html | |
(doctype :html4) | |
[:html | |
[:head | |
[:title *site-title*] | |
(include-css "/css/pygments.css" "/css/global.css")] | |
[:body | |
[:div#header [:h1 *site-title*]] | |
[:div#nav (unordered-list [(link-to "/" "[index]") | |
(link-to "http://github.com/defn/cljex" "[contribute]")])] | |
[:div#left (ordered-list (gen-doc-index-inline))] | |
[:div#right ,,,,,body,,,,,]]])) | |
(defn get-doc-index [] | |
(rest (file-seq (java.io.File. *core-docs*)))) | |
(defn gen-doc-index [] | |
(app-layout | |
(interpose [:br] | |
(map #(link-to (str "/docs/" (.getName %)) | |
(rest (seq (.getName %)))) | |
(get-doc-index)))))y | |
(defn gen-doc-index-inline [] | |
(interpose [:br] | |
(map #(link-to (str "docs/" (.getName %)) | |
(rest (seq (.getName %)))) | |
(get-doc-index)))) | |
(defn doc-page [doc] | |
(app-layout (get-doc doc))) | |
(defn doc-page-inline [doc] | |
(get-doc doc)) | |
(def welcome | |
(html | |
[:h2 "Gentlemen, we have a whole lot of work to do..."])) | |
;============================== | |
; Define Routes | |
;============================== | |
(defroutes doc-routes | |
(GET "/" (app-layout welcome)) | |
(GET "/docs/:name" (doc-page (:name params)))) | |
(defroutes static-routes | |
(GET "/*" (serve-file "/Users/defn/git/cljex/src/cljex/public/"(params :*)))) | |
(defroutes error-routes | |
(ANY "/*" [404 "404 Page Not Found"])) | |
(defroutes all-routes | |
doc-routes | |
static-routes | |
error-routes) | |
;============================== | |
; Start Your Engines | |
;============================== | |
(run-server | |
{:port 8083} | |
"/*" (servlet all-routes)) | |
;============================== | |
; Main | |
;============================== | |
(defn -main [& args] | |
(if (= (first args) "--server") | |
(run-server | |
{:port 8080} | |
"/*" (servlet all-routes)) | |
(println "What are you? Nuts?"))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment