Created
January 2, 2012 22:41
-
-
Save j0ni/1552453 to your computer and use it in GitHub Desktop.
rest resource macro
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
(ns j0ni.whatever | |
(:use compojure.core)) | |
(defmacro explode-resource [rsrc controller-fn attrs] | |
`(context ~(str "/" rsrc) [] | |
(GET "/" | |
[] | |
(~(symbol (controller-fn "index")))) | |
(GET "/new" | |
[] | |
(~(symbol (controller-fn "new")))) | |
(POST "/" | |
[~@(map #(symbol (name %)) attrs)] | |
(~(symbol (controller-fn "create")) ~@(map #(symbol (name %)) attrs))) | |
(GET "/:id" | |
[~(symbol "id")] | |
(~(symbol (controller-fn "show")) ~(symbol "id"))) | |
(DELETE "/:id" | |
[~(symbol "id")] | |
(~(symbol (controller-fn "destroy")) ~(symbol "id"))) | |
(GET "/:id/edit" | |
[~(symbol "id")] | |
(~(symbol (controller-fn "edit")) ~(symbol "id"))) | |
(PUT "/:id" | |
[~(symbol "id") ~@(map #(symbol (name %)) attrs)] | |
(~(symbol (controller-fn "update")) ~(symbol "id") ~@(map #(symbol (name %)) attrs))))) | |
(defmacro resource | |
([rsrc attrs] | |
`(explode-resource ~rsrc ~#(str %) ~attrs)) | |
([rsrc ns attrs] | |
`(explode-resource ~rsrc ~#(str ns "/" %) ~attrs))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
one day this fucker will work