Hoplon是Web编程更简单的方式,该项目包含Web编程的一些方法和库。采用Clojure和ClojureScript编写应用。
ClojureScript代码示例:
(page "foo/bar.html" (:require [my.lib :as lib]))(defc clicks 0)(html (head (title "Hello World") (link :rel "stylesheet" :href "css/main.css")) (body (lib/heading-large "Hello, world!") (p (text "You've clicked ~{clicks} times.")) (button :on-click #(swap! clicks inc) "Click me!")))对应的HTML代码:
<script type="text/hoplon"> (page "foo/bar.html" (:require [my.lib :as lib])) (defc clicks 0)</script><html> <head> <title>Hello World</title> <link rel="stylesheet" href="css/main.css"> </head> <body> <lib.heading-large>Hello, world!</lib.heading-large> <p><text>You've clicked ~{clicks} times.</text></p> <button on-click="{{ #(swap! clicks inc) }}"> Click me! </button> </body></html>
评论