Skip to content

Instantly share code, notes, and snippets.

@gtrak
Created August 10, 2012 15:23
Show Gist options
  • Save gtrak/3314988 to your computer and use it in GitHub Desktop.
Save gtrak/3314988 to your computer and use it in GitHub Desktop.
(def servlets
"Map of servlet classes to ring handlers, add here. Needs to be quoted so symbols resolve to themselves."
'{:my.servlet.class.Servlet hr/app})
(defmacro make-servlet
"Call to generate a servlet class given the class name and a ring handler."
[servlet handler]
(let [servlet (name servlet)
prefix (str servlet "-")]
`(do (println "Compiling Servlet" ~servlet)
(gen-class :name ~servlet
:prefix ~prefix
:extends javax.servlet.http.HttpServlet)
(s/defservice ~prefix ~handler))))
(defmacro make-servlets
[]
(let [gens (for [[name handler] servlets]
`(make-servlet ~name ~handler))]
`(do ~@gens)))
(make-servlets)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment