1. Miki Tebeka
  2. dr-evil


Miki Tebeka  committed a4de9a3

Start of the EVIL macro (+ html function)

  • Participants
  • Parent commits a1d5778
  • Branches default

Comments (0)

Files changed (2)

File src/dr/evil.clj

View file
 (ns dr.evil
   (:use compojure.core)
-  (:use ring.util.response)
   (:use [clojure.stacktrace :only (print-stack-trace)])
   (:use [clojure.contrib.json :only (json-str)]))
 (defn evil [params]
   (json-str (eval-expr (params "expr"))))
-(declare *html*)
+(declare html)
-(defroutes app
-  (GET "/" [] *html*)
-  (POST "/" {params :params} (evil params))
-  (ANY "/*" [path] (redirect "/")))
+(defn EVIL [path]
+  (GET path [] (html path))
+  (POST path {params :params} (evil params)))
-; HTML goes here.
+; HTML goes here (this is at the end since it's long).
 ; We embed the HTML in the clojure file so we won't have to muck around with
 ; serving files from unknown locations
-(def *html* "<html>
+(defn html [path] 
+  (format "<html>
         <title>Dr. Evil Web Debugger</title>
                 type: 'POST',
-                url: '/',
+                url: '%s',
                 data: { \"expr\" : expr },
                 success: on_result,
                 dataType: 'json'
+</html>" path))

File src/run.clj

View file
 (ns dr.evil.run
-  (:require dr.evil)
-  (:use ring.adapter.jetty))
+  (:use dr.evil)
+  (:use compojure.core)
+  (:use ring.adapter.jetty)
+  (:require [compojure.route :as route]))
-(run-jetty #'dr.evil/app {:port 8080})
+(defroutes app
+  (GET "/" [] "NOTHING HERE! (try /evil)")
+  (EVIL "/evil")
+  (route/not-found "Dude! I can't find it."))
+(run-jetty app {:port 8080})