2013-02-13 64 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