meth wasn't accepting correctly its parameters
Now also accepts more than 1 statement in the code part of the macro refactored to use only 1 codebase (no more route != route-with-macros)
This commit is contained in:
parent
8970662dcb
commit
f913c2aa8c
@ -1,31 +1,30 @@
|
|||||||
;;; Meth
|
;;; Meth
|
||||||
;; based on paultag's meth library to access a Flask based application
|
;; based on paultag's meth library to access a Flask based application
|
||||||
|
|
||||||
(defmacro route [name path params code]
|
(defmacro route-with-methods [name path methods params &rest code]
|
||||||
"Default get request"
|
|
||||||
`(let [[deco (.route app ~path)]]
|
|
||||||
(with-decorator deco
|
|
||||||
(defn ~name ~params ~@code))))
|
|
||||||
|
|
||||||
(defmacro route-with-methods [name path params code methods]
|
|
||||||
"Same as route but with an extra methods array to specify HTTP methods"
|
"Same as route but with an extra methods array to specify HTTP methods"
|
||||||
`(let [[deco (kwapply (.route app ~path)
|
`(let [[deco (kwapply (.route app ~path)
|
||||||
{"methods" ~methods})]]
|
{"methods" ~methods})]]
|
||||||
(with-decorator deco
|
(with-decorator deco
|
||||||
(defn ~name ~params ~@code))))
|
(defn ~name ~params
|
||||||
|
(progn ~@code)))))
|
||||||
|
|
||||||
;; Some macro examples
|
;; Some macro examples
|
||||||
(defmacro post-route [name path params code]
|
(defmacro route [name path params &rest code]
|
||||||
"Post request"
|
"Post request"
|
||||||
`(route-with-methods ~name ~path ~params ~code ["POST"]))
|
`(route-with-methods ~name ~path ["GET"] ~params ~@code))
|
||||||
|
|
||||||
(defmacro put-route [name path params code]
|
(defmacro post-route [name path params &rest code]
|
||||||
|
"Post request"
|
||||||
|
`(route-with-methods ~name ~path ["POST"] ~params ~@code))
|
||||||
|
|
||||||
|
(defmacro put-route [name path params &rest code]
|
||||||
"Put request"
|
"Put request"
|
||||||
`(route-with-methods ~name ~path ~params ~code ["PUT"]))
|
`(route-with-methods ~name ~path ["PUT"] ~params ~@code))
|
||||||
|
|
||||||
(defmacro delete-route [name path params code]
|
(defmacro delete-route [name path params &rest code]
|
||||||
"Delete request"
|
"Delete request"
|
||||||
`(route-with-methods ~name ~path ~params ~code ["DELETE"]))
|
`(route-with-methods ~name ~path ["DELETE"] ~params ~@code))
|
||||||
|
|
||||||
|
|
||||||
;;; Simple example application
|
;;; Simple example application
|
||||||
@ -34,7 +33,7 @@
|
|||||||
;; (import [flask [Flask]])
|
;; (import [flask [Flask]])
|
||||||
;; (setv app (Flask "__main__"))
|
;; (setv app (Flask "__main__"))
|
||||||
|
|
||||||
;; (require methy)
|
;; (require hy.contrib.meth)
|
||||||
|
|
||||||
;; (print "setup / with GET")
|
;; (print "setup / with GET")
|
||||||
;; (route get-index "/" [] (str "Hy world!"))
|
;; (route get-index "/" [] (str "Hy world!"))
|
||||||
|
Loading…
Reference in New Issue
Block a user