Permalink
Browse files

reorg in progress

  • Loading branch information...
1 parent 0c4c494 commit 4a5223e7d54d34dd8755c5352b4013175defb758 @swannodette committed Sep 1, 2010
Showing with 33 additions and 15 deletions.
  1. +2 −2 project.clj
  2. +9 −12 src/tutorial/template1.clj
  3. +22 −1 src/tutorial/utils.clj
View
@@ -4,6 +4,6 @@
[org.clojure/clojure-contrib "1.2.0"]
[enlive "1.0.0-SNAPSHOT"]
[ring "0.2.5"]
- [net.cgrand/moustache "1.0.0-SNAPSHOT"]
- [swank-clojure "1.3.0-SNAPSHOT"]]
+ [net.cgrand/moustache "1.0.0-SNAPSHOT"]]
+ :dev-dependencies [[swank-clojure "1.3.0-SNAPSHOT"]]
:source-path "src")
View
@@ -1,9 +1,7 @@
(ns tutorial.template1
(:require [net.cgrand.enlive-html :as html])
- (:use tutorial.utils)
- (:use [ring.middleware.reload :only [wrap-reload]]
- [ring.adapter.jetty :only [run-jetty]]
- [net.cgrand.moustache :only [app delegate]]))
+ (:use [net.cgrand.moustache :only [app delegate]]
+ [tutorial.utils :only [run-server* render-to-response]]))
(html/deftemplate index "tutorial/template1.html"
[ctxt]
@@ -13,12 +11,11 @@
;; The App
;; ========================================
-(def template1
+(def routes
(app
- [""] index (render (index {}))
- ["change"] (render (index {:message "We changed the message!"}))
- [&] [404 "Page Not Found"]))
-
-(defonce *server* (run-jetty #'template1 {:port 8080 :join? false}))
-
-
+ [""] #(render-to-response (index {}))
+ ["change"] #(render-to-response (index {:message "We changed the message!"}))
+ [&] {:status 404
+ :body "Page Not Found"}))
+
+(defonce *server* (run-server* routes))
View
@@ -1,12 +1,33 @@
(ns tutorial.utils
- (:require [net.cgrand.enlive-html :as html]))
+ (:require [net.cgrand.enlive-html :as html])
+ (:use [ring.adapter.jetty :only [run-jetty]]
+ [ring.util.response :only [response]]
+ [ring.middleware.reload :only [wrap-reload]]
+ [ring.middleware.stacktrace :only [wrap-stacktrace]]))
(defn render [t]
(apply str t))
(defn render-snippet [s]
(apply str (html/emit* s)))
+(def render-to-response
+ (comp response render))
+
+(defn run-server* [app & {:keys [port] :or {port 8080}}]
+ (let [nses (if-let [m (meta app)]
+ [(-> (:ns (meta app)) str symbol)]
+ [])]
+ (println "run-server*" nses)
+ (run-jetty
+ (-> app
+ #_(wrap-reload nses)
+ (wrap-stacktrace))
+ {:port port :join? false})))
+
+(defmacro run-server [app]
+ `(run-server* (var ~app)))
+
(defmulti parse-int type)
(defmethod parse-int java.lang.Integer [n] n)
(defmethod parse-int java.lang.String [s] (Integer/parseInt s))

0 comments on commit 4a5223e

Please sign in to comment.