2013-03-05 57 views
0

我創建了一個具有clojure noir框架的Web項目,並且想要試驗路由前的宏。clojure預路由設置過濾器不起作用

這裏是我的test.clj

(ns website.views.test 
(:require [website.views.common :as common] [noir.content.getting-started]) 
(:use [noir.core :only [defpage]]) 
(:use [hiccup.core :only [html]]) 
(:require noir.core)) 

(defn is-admin? [] false) 
(pre-route '/admin/*' (when-not (is-admin?) (redirect '/login')))  
(defpage "/login" [] (common/layout [:p "login to website"])) 
(defpage "/admin" [] (common/layout [:p "Welcome to admin page"]))   
(defpage "/admin/test1" [] (common/layout [:p "Welcome to admin test1 page"]))   
(defpage "/admin/test2" [] (common/layout [:p "Welcome to admin test2"])) 

我碰到下面的堆棧跟蹤,當我執行「雷音運行」

Caused by: java.lang.RuntimeException: Invalid token: /admin/*' 
at clojure.lang.Util.runtimeException(Util.java:170) 
at clojure.lang.LispReader.interpretToken(LispReader.java:321) 
at clojure.lang.LispReader.read(LispReader.java:206) 
at clojure.lang.LispReader$WrappingReader.invoke(LispReader.java:537) 
at clojure.lang.LispReader.readDelimitedList(LispReader.java:1126) 
at clojure.lang.LispReader$ListReader.invoke(LispReader.java:962) 
at clojure.lang.LispReader.read(LispReader.java:180) 
at clojure.lang.Compiler.load(Compiler.java:6949) 
... 51 more 

任何想法可能是什麼此異常的原因(沒有按」當我註釋掉路由前的宏時)?

+1

我沒有使用'noir',但前路線中的單引號看起來很腥。如果這些是字符串雙引號'「...」'而不是? – 2013-03-06 01:16:11

回答

2

(pre-route '/admin/*' (when-not (is-admin?) (redirect '/login')))

應該是:

(pre-route "/admin/*" (when-not (is-admin?) (redirect "/login")))

因爲'是引用讀者宏。