Remove contrib.meth
This seems to be specific to Flask, a web framework.
This commit is contained in:
parent
407a79591a
commit
91b26d1fdd
@ -1,31 +0,0 @@
|
|||||||
;;; Hy on Meth
|
|
||||||
;;; based on paultag's meth library to access a Flask based application
|
|
||||||
|
|
||||||
(defmacro route-with-methods [name path methods params &rest code]
|
|
||||||
"Same as route but with an extra methods array to specify HTTP methods"
|
|
||||||
`(let [deco (apply app.route [~path]
|
|
||||||
{"methods" ~methods})]
|
|
||||||
(with-decorator deco
|
|
||||||
(defn ~name ~params
|
|
||||||
(do ~@code)))))
|
|
||||||
|
|
||||||
(defn rwm [name path method params code]
|
|
||||||
`(do (require hy.contrib.meth)
|
|
||||||
(hy.contrib.meth.route-with-methods ~name ~path ~method ~params ~@code)))
|
|
||||||
|
|
||||||
;; Some macro examples
|
|
||||||
(defmacro route [name path params &rest code]
|
|
||||||
"Get request"
|
|
||||||
(rwm name path ["GET"] params code))
|
|
||||||
|
|
||||||
(defmacro post-route [name path params &rest code]
|
|
||||||
"Post request"
|
|
||||||
(rwm name path ["POST"] params code))
|
|
||||||
|
|
||||||
(defmacro put-route [name path params &rest code]
|
|
||||||
"Put request"
|
|
||||||
(rwm name path ["PUT"] params code))
|
|
||||||
|
|
||||||
(defmacro delete-route [name path params &rest code]
|
|
||||||
"Delete request"
|
|
||||||
(rwm name path ["DELETE"] params code))
|
|
@ -16,7 +16,6 @@ from .native_tests.shadow import * # noqa
|
|||||||
from .native_tests.with_test import * # noqa
|
from .native_tests.with_test import * # noqa
|
||||||
from .native_tests.extra.anaphoric import * # noqa
|
from .native_tests.extra.anaphoric import * # noqa
|
||||||
from .native_tests.contrib.loop import * # noqa
|
from .native_tests.contrib.loop import * # noqa
|
||||||
from .native_tests.contrib.meth import * # noqa
|
|
||||||
from .native_tests.contrib.walk import * # noqa
|
from .native_tests.contrib.walk import * # noqa
|
||||||
from .native_tests.contrib.multi import * # noqa
|
from .native_tests.contrib.multi import * # noqa
|
||||||
from .native_tests.contrib.sequences import * # noqa
|
from .native_tests.contrib.sequences import * # noqa
|
||||||
|
@ -1,53 +0,0 @@
|
|||||||
(require [hy.contrib.meth [route post-route put-route delete-route]])
|
|
||||||
|
|
||||||
(defclass FakeMeth []
|
|
||||||
"Mocking decorator class"
|
|
||||||
[rules {}]
|
|
||||||
(defn route [self rule &kwargs options]
|
|
||||||
(fn [f]
|
|
||||||
(assoc self.rules rule (, f options))
|
|
||||||
f)))
|
|
||||||
|
|
||||||
(defn test_route []
|
|
||||||
(let [app (FakeMeth)]
|
|
||||||
(route get-index "/" [] (str "Hy world!"))
|
|
||||||
(setv app-rules (getattr app "rules"))
|
|
||||||
(assert (in "/" app-rules))
|
|
||||||
(let [(, rule-fun rule-opt) (get app-rules "/")]
|
|
||||||
(assert (not (empty? rule-opt)))
|
|
||||||
(assert (in "GET" (get rule-opt "methods")))
|
|
||||||
(assert (= (getattr rule-fun "__name__") "get_index"))
|
|
||||||
(assert (= "Hy world!" (rule-fun))))))
|
|
||||||
|
|
||||||
(defn test_post_route []
|
|
||||||
(let [app (FakeMeth)]
|
|
||||||
(post-route get-index "/" [] (str "Hy world!"))
|
|
||||||
(setv app-rules (getattr app "rules"))
|
|
||||||
(assert (in "/" app-rules))
|
|
||||||
(let [(, rule-fun rule-opt) (get app-rules "/")]
|
|
||||||
(assert (not (empty? rule-opt)))
|
|
||||||
(assert (in "POST" (get rule-opt "methods")))
|
|
||||||
(assert (= (getattr rule-fun "__name__") "get_index"))
|
|
||||||
(assert (= "Hy world!" (rule-fun))))))
|
|
||||||
|
|
||||||
(defn test_put_route []
|
|
||||||
(let [app (FakeMeth)]
|
|
||||||
(put-route get-index "/" [] (str "Hy world!"))
|
|
||||||
(setv app-rules (getattr app "rules"))
|
|
||||||
(assert (in "/" app-rules))
|
|
||||||
(let [(, rule-fun rule-opt) (get app-rules "/")]
|
|
||||||
(assert (not (empty? rule-opt)))
|
|
||||||
(assert (in "PUT" (get rule-opt "methods")))
|
|
||||||
(assert (= (getattr rule-fun "__name__") "get_index"))
|
|
||||||
(assert (= "Hy world!" (rule-fun))))))
|
|
||||||
|
|
||||||
(defn test_delete_route []
|
|
||||||
(let [app (FakeMeth)]
|
|
||||||
(delete-route get-index "/" [] (str "Hy world!"))
|
|
||||||
(setv app-rules (getattr app "rules"))
|
|
||||||
(assert (in "/" app-rules))
|
|
||||||
(let [(, rule-fun rule-opt) (get app-rules "/")]
|
|
||||||
(assert (not (empty? rule-opt)))
|
|
||||||
(assert (in "DELETE" (get rule-opt "methods")))
|
|
||||||
(assert (= (getattr rule-fun "__name__") "get_index"))
|
|
||||||
(assert (= "Hy world!" (rule-fun))))))
|
|
Loading…
x
Reference in New Issue
Block a user