File tree 2 files changed +18
-7
lines changed
2 files changed +18
-7
lines changed Original file line number Diff line number Diff line change 667
667
'compojure.api.sweet/resource
668
668
'compojure.api.resource/resource))
669
669
670
- (defn- static-endpoint? [&env body]
671
- (and (seq? body)
670
+ (def routes-vars #{'compojure.api.sweet/routes
671
+ 'compojure.api.resource/routes})
672
+
673
+ (declare static-body? )
674
+
675
+ (defn- static-endpoint? [&env form]
676
+ (and (seq? form)
672
677
(boolean
673
- (let [sym (first body )]
678
+ (let [sym (first form )]
674
679
(when (symbol? sym)
675
680
(when-some [v (resolve &env sym)]
676
681
(when (var? v)
677
- (endpoint-vars
678
- (symbol v)))))))))
679
-
680
- (declare static-body? )
682
+ (or (endpoint-vars (symbol v))
683
+ (and (routes-vars (symbol v))
684
+ (static-body? &env (next form)))))))))))
681
685
682
686
(def context-vars (into #{}
683
687
(mapcat (fn [n]
789
793
(defn- static-body? [&env body]
790
794
(every? #(or (static-endpoint? &env %)
791
795
(contains? &env %) ; ;local
796
+ (when (symbol? %)
797
+ (var? (resolve &env %))) ; ;var deref
792
798
((some-fn keyword? number? boolean?) %)
793
799
(static-cond? &env %)
794
800
(static-context? &env %)
Original file line number Diff line number Diff line change 13
13
14
14
(fact " all compojure.api.core macros are interpreted"
15
15
(let [app (context " /a" []
16
+ :static true ; ;FIXME nested static/dynamic?
16
17
(routes
17
18
(context " /b" []
19
+ :dynamic true
18
20
(let-routes []
19
21
(GET " /c" [] identity)
20
22
(POST " /d" [] identity)
26
28
(GET " /k/:l/m/:n" [] identity))))]
27
29
28
30
(extract-paths app)
31
+ #_#_
29
32
=> {" /a/b/c" {:get {}}
30
33
" /a/b/d" {:post {}}
31
34
" /a/b/e" {:put {}}
47
50
(fact " route-macros are expanded"
48
51
(extract-paths
49
52
(context " /api" []
53
+ :static true
50
54
(optional-routes true (GET " /true" [] identity))
51
55
(optional-routes false (PUT " /false" [] identity)))) => {" /api/true" {:get {}}})
52
56
53
57
(fact " endpoint-macros are expanded"
54
58
(extract-paths
55
59
(context " /api" []
60
+ :static true
56
61
(GET+ " /true" [] identity))) => {" /api/xxx/true" {:get {}}})
57
62
58
63
(fact " Vanilla Compojure defroutes are NOT followed"
You can’t perform that action at this time.
0 commit comments