2013-02-13 66 views
0

我使用catnip/leiningen試圖學習Clojure ...所以我有一個簡單的網站,現在我想在我的頁面中添加一個clojure腳本。從html訪問clojurescript

所以我拿了一個簡單的例子,但現在被困在如何從我的網站訪問我的腳本。

我project.clj

(defproject hello-world "0.1.0-SNAPSHOT" 
    :description "FIXME: write description" 
    :url "http://example.com/FIXME" 
    :dependencies [[org.clojure/clojure "1.4.0"] 
       [compojure "1.1.5"] 
       [hiccup "1.0.2"]] 
    :plugins [[lein-ring "0.8.2"]] 
    :cljsbuild {:builds 
       [{:source-path "src" 
       :compiler 
       {:output-to "resources/public/cljs/main.js" 
       :output-dir "resources/public/cljs" 
       :optimizations :simple 
       :pretty-print true}}]} 
    :ring {:handler hello-world.handler/app} 
    :profiles 
    {:dev {:dependencies [[ring-mock "0.1.3"]]}}) 

handler.clj

(defn header [title] 
    (html 
    [:head 
    [:title title] 
    [:script "/cljs/play.js"]])) 

的有關部分。如果我跑雷音環服務器在http://localhost:8080/resources/public/cljs/main.js有什麼。如何映射js的請求,以便我的網站可以找到它們?

回答

1

的問題是在

[:script {:src "/cljs/main.js"}] 

(include-js "/cljs/main.js") 

以產生corrent鏈接到的JavaScript文件:[:腳本],需要加以改寫爲任一-tag。

0

您的JavaScript文件應可訪問http://localhost:8080/cljs/main.js而不是http://localhost:8080/resources/public/cljs/main.js。否則,您的實際代碼看起來沒問題。

您是否運行了lein cljsbuild once並創建了一個在/resources/public/cljs/下的JavaScript文件?

+0

問題出在[:script] -tag。我用(include-js「/cljs/main.js」)取代了它並開始工作。所以我的代碼不好... – Roland 2013-02-13 13:19:10

+0

@Roland True。你也可以使用'[:script {:src「/cljs/main.js」}]' – ponzao 2013-02-13 13:27:37

+0

更新你的答案,以便我可以將它設置爲一個很好的答案:-) – Roland 2013-02-13 15:31:31