Last active
December 10, 2015 01:34
-
-
Save edtsech/4359055 to your computer and use it in GitHub Desktop.
Get Rails like controller syntax from Compojure DSL in 5 minutes with few very simple macros.
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
(defroutes posts-routes | |
(context "/posts" [] | |
(GET "/" request ...) | |
(GET "/new" request ...) | |
(POST "/" request ...))) |
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
(defmacro defcontroller | |
([nm & exprs] | |
`(defroutes ~(symbol (str (name nm) "-routes")) | |
(context ~(str "/" (name nm)) [] | |
~@exprs)))) | |
(defmacro index [bindings & exprs] | |
`(GET "/" ~bindings ~@exprs)) | |
(defmacro new [bindings & exprs] | |
`(GET "/new" ~bindings ~@exprs)) | |
(defmacro create [bindings & exprs] | |
`(POST "/" ~bindings ~@exprs)) |
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
(defcontroller posts | |
(index request ...) | |
(new request ...) | |
(create request ...)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment