Skip to content
Browse files

Refactored param handling

  • Loading branch information...
1 parent 1e75954 commit 57efb7b532ca17b5b6aa2932e8f1415fc39c5245 @pmbauer pmbauer committed Sep 21, 2011
Showing with 20 additions and 9 deletions.
  1. +20 −9 src/cs_cs/web.clj
View
29 src/cs_cs/web.clj
@@ -10,20 +10,31 @@
"TRUE" true
false))
-(defn compile-cs
+(defn parse-params [params]
+ (let [{:keys [cs-code optimizations pretty-print]
+ :or {optimizations "advanced"
+ pretty-print "true"}} params]
+ [cs-code (keyword optimizations) (str-to-bool pretty-print)]))
+
+(defn call-build [[code opt pp]]
+ (try
+ [200 (comp/build code {:optimizations opt, :pretty-print pp})]
+ (catch Exception e
+ [400 (str "caught exception: " (.getMessage e))])))
+
+(defn format-response
"Need m0ar functionality"
- [code opt-str pp-str]
- {:status 200
+ [[status body]]
+ {:status status
:headers {"Content-Type" "text/plain"}
- :body (comp/build code {:optimizations (keyword opt-str)
- :pretty-print (str-to-bool pp-str)})})
+ :body body})
(defroutes routes
(POST "/compile" [& params]
- (let [{:keys [cs-code optimizations pretty-print]
- :or {optimizations "advanced"
- pretty-print "true"}} params]
- (compile-cs cs-code optimizations pretty-print))))
+ (->> params
+ parse-params
+ call-build
+ format-response)))
(def app
(handler/site routes))

0 comments on commit 57efb7b

Please sign in to comment.
Something went wrong with that request. Please try again.