clementine 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (139) hide show
  1. data/.gitignore +1 -0
  2. data/Gemfile +4 -2
  3. data/LICENSE.txt +22 -0
  4. data/README.md +11 -6
  5. data/Rakefile +22 -0
  6. data/clementine.gemspec +2 -1
  7. data/ext/clojure-clojurescript-bef56a7/.gitignore +13 -0
  8. data/ext/clojure-clojurescript-bef56a7/Clojurescript.iml +12 -0
  9. data/ext/clojure-clojurescript-bef56a7/README.md +29 -0
  10. data/ext/clojure-clojurescript-bef56a7/benchmark/cljs/benchmark_runner.cljs +155 -0
  11. data/ext/clojure-clojurescript-bef56a7/bin/cljsc +21 -0
  12. data/ext/clojure-clojurescript-bef56a7/bin/cljsc.bat +18 -0
  13. data/{vendor/assets → ext/clojure-clojurescript-bef56a7}/bin/cljsc.clj +0 -0
  14. data/ext/clojure-clojurescript-bef56a7/devnotes/README.org +35 -0
  15. data/ext/clojure-clojurescript-bef56a7/devnotes/bcrepl.org +13 -0
  16. data/ext/clojure-clojurescript-bef56a7/devnotes/cljs.org +500 -0
  17. data/ext/clojure-clojurescript-bef56a7/devnotes/corelib.org +583 -0
  18. data/ext/clojure-clojurescript-bef56a7/devnotes/day1.org +203 -0
  19. data/ext/clojure-clojurescript-bef56a7/devnotes/day2.org +44 -0
  20. data/ext/clojure-clojurescript-bef56a7/devnotes/talk.org +126 -0
  21. data/ext/clojure-clojurescript-bef56a7/devnotes/testing +13 -0
  22. data/ext/clojure-clojurescript-bef56a7/devnotes/todo.org +121 -0
  23. data/ext/clojure-clojurescript-bef56a7/epl-v10.html +261 -0
  24. data/ext/clojure-clojurescript-bef56a7/pom.template.xml +88 -0
  25. data/ext/clojure-clojurescript-bef56a7/samples/dom/.gitignore +2 -0
  26. data/ext/clojure-clojurescript-bef56a7/samples/dom/src/dom/test.cljs +48 -0
  27. data/ext/clojure-clojurescript-bef56a7/samples/dom/test.html +30 -0
  28. data/ext/clojure-clojurescript-bef56a7/samples/hello-js/.gitignore +2 -0
  29. data/ext/clojure-clojurescript-bef56a7/samples/hello-js/README.md +53 -0
  30. data/ext/clojure-clojurescript-bef56a7/samples/hello-js/externed-lib.js +7 -0
  31. data/ext/clojure-clojurescript-bef56a7/samples/hello-js/externs.js +3 -0
  32. data/ext/clojure-clojurescript-bef56a7/samples/hello-js/hello-extern.html +14 -0
  33. data/ext/clojure-clojurescript-bef56a7/samples/hello-js/hello-js-dev.html +18 -0
  34. data/ext/clojure-clojurescript-bef56a7/samples/hello-js/hello-js.html +17 -0
  35. data/ext/clojure-clojurescript-bef56a7/samples/hello-js/my-external-lib.js +3 -0
  36. data/ext/clojure-clojurescript-bef56a7/samples/hello-js/src/hello-js/core.cljs +9 -0
  37. data/ext/clojure-clojurescript-bef56a7/samples/hello-js/src/hello-js/extern-example.cljs +5 -0
  38. data/ext/clojure-clojurescript-bef56a7/samples/hello/.gitignore +2 -0
  39. data/ext/clojure-clojurescript-bef56a7/samples/hello/README.md +34 -0
  40. data/ext/clojure-clojurescript-bef56a7/samples/hello/hello-dev.html +18 -0
  41. data/ext/clojure-clojurescript-bef56a7/samples/hello/hello.html +13 -0
  42. data/ext/clojure-clojurescript-bef56a7/samples/hello/src/hello/core.cljs +8 -0
  43. data/ext/clojure-clojurescript-bef56a7/samples/hello/src/hello/foo/bar.cljs +4 -0
  44. data/ext/clojure-clojurescript-bef56a7/samples/nodehello.cljs +18 -0
  45. data/ext/clojure-clojurescript-bef56a7/samples/nodels.cljs +17 -0
  46. data/ext/clojure-clojurescript-bef56a7/samples/repl/.gitignore +2 -0
  47. data/ext/clojure-clojurescript-bef56a7/samples/repl/README.md +101 -0
  48. data/ext/clojure-clojurescript-bef56a7/samples/repl/index.html +27 -0
  49. data/ext/clojure-clojurescript-bef56a7/samples/repl/src/repl/test.cljs +73 -0
  50. data/ext/clojure-clojurescript-bef56a7/samples/twitterbuzz/.gitignore +2 -0
  51. data/ext/clojure-clojurescript-bef56a7/samples/twitterbuzz/README.md +42 -0
  52. data/ext/clojure-clojurescript-bef56a7/samples/twitterbuzz/index-advanced.html +80 -0
  53. data/ext/clojure-clojurescript-bef56a7/samples/twitterbuzz/index.html +88 -0
  54. data/ext/clojure-clojurescript-bef56a7/samples/twitterbuzz/reset.css +48 -0
  55. data/ext/clojure-clojurescript-bef56a7/samples/twitterbuzz/src/twitterbuzz/anneal.cljs +66 -0
  56. data/ext/clojure-clojurescript-bef56a7/samples/twitterbuzz/src/twitterbuzz/core.cljs +307 -0
  57. data/ext/clojure-clojurescript-bef56a7/samples/twitterbuzz/src/twitterbuzz/dom-helpers.cljs +95 -0
  58. data/ext/clojure-clojurescript-bef56a7/samples/twitterbuzz/src/twitterbuzz/layout.cljs +100 -0
  59. data/ext/clojure-clojurescript-bef56a7/samples/twitterbuzz/src/twitterbuzz/leaderboard.cljs +40 -0
  60. data/ext/clojure-clojurescript-bef56a7/samples/twitterbuzz/src/twitterbuzz/radial.cljs +91 -0
  61. data/ext/clojure-clojurescript-bef56a7/samples/twitterbuzz/src/twitterbuzz/showgraph.cljs +121 -0
  62. data/ext/clojure-clojurescript-bef56a7/samples/twitterbuzz/src/twitterbuzz/timeline.cljs +39 -0
  63. data/ext/clojure-clojurescript-bef56a7/samples/twitterbuzz/style.css +301 -0
  64. data/ext/clojure-clojurescript-bef56a7/samples/twitterbuzz/test_data.txt +1 -0
  65. data/ext/clojure-clojurescript-bef56a7/samples/twitterbuzz/tweet_maps.txt +1 -0
  66. data/ext/clojure-clojurescript-bef56a7/script/benchmark +30 -0
  67. data/ext/clojure-clojurescript-bef56a7/script/bootstrap +70 -0
  68. data/ext/clojure-clojurescript-bef56a7/script/browser-repl +16 -0
  69. data/ext/clojure-clojurescript-bef56a7/script/build +59 -0
  70. data/ext/clojure-clojurescript-bef56a7/script/clean +5 -0
  71. data/ext/clojure-clojurescript-bef56a7/script/closure-library-release/google-closure-library-third-party.pom.template +59 -0
  72. data/ext/clojure-clojurescript-bef56a7/script/closure-library-release/google-closure-library.pom.template +54 -0
  73. data/ext/clojure-clojurescript-bef56a7/script/closure-library-release/make-closure-library-jars.sh +87 -0
  74. data/ext/clojure-clojurescript-bef56a7/script/compile +41 -0
  75. data/ext/clojure-clojurescript-bef56a7/script/repl +13 -0
  76. data/ext/clojure-clojurescript-bef56a7/script/repl.bat +13 -0
  77. data/ext/clojure-clojurescript-bef56a7/script/repljs +15 -0
  78. data/ext/clojure-clojurescript-bef56a7/script/repljs.bat +14 -0
  79. data/ext/clojure-clojurescript-bef56a7/script/test +38 -0
  80. data/ext/clojure-clojurescript-bef56a7/script/test-compile +30 -0
  81. data/ext/clojure-clojurescript-bef56a7/src/clj/cljs/analyzer.clj +975 -0
  82. data/{vendor/assets → ext/clojure-clojurescript-bef56a7}/src/clj/cljs/closure.clj +173 -73
  83. data/ext/clojure-clojurescript-bef56a7/src/clj/cljs/compiler.clj +1081 -0
  84. data/ext/clojure-clojurescript-bef56a7/src/clj/cljs/core.clj +1158 -0
  85. data/{vendor/assets → ext/clojure-clojurescript-bef56a7}/src/clj/cljs/repl.clj +51 -25
  86. data/ext/clojure-clojurescript-bef56a7/src/clj/cljs/repl/browser.clj +258 -0
  87. data/ext/clojure-clojurescript-bef56a7/src/clj/cljs/repl/reflect.clj +75 -0
  88. data/{vendor/assets → ext/clojure-clojurescript-bef56a7}/src/clj/cljs/repl/rhino.clj +6 -5
  89. data/ext/clojure-clojurescript-bef56a7/src/clj/cljs/repl/server.clj +173 -0
  90. data/ext/clojure-clojurescript-bef56a7/src/clj/cljs/tagged_literals.clj +30 -0
  91. data/ext/clojure-clojurescript-bef56a7/src/cljs/cljs/core.cljs +7197 -0
  92. data/{vendor/assets → ext/clojure-clojurescript-bef56a7}/src/cljs/cljs/nodejs.cljs +1 -1
  93. data/{vendor/assets → ext/clojure-clojurescript-bef56a7}/src/cljs/cljs/nodejs_externs.js +0 -0
  94. data/{vendor/assets → ext/clojure-clojurescript-bef56a7}/src/cljs/cljs/nodejscli.cljs +1 -1
  95. data/ext/clojure-clojurescript-bef56a7/src/cljs/cljs/reader.cljs +551 -0
  96. data/{vendor/assets → ext/clojure-clojurescript-bef56a7}/src/cljs/clojure/browser/dom.cljs +59 -13
  97. data/{vendor/assets → ext/clojure-clojurescript-bef56a7}/src/cljs/clojure/browser/event.cljs +0 -0
  98. data/{vendor/assets → ext/clojure-clojurescript-bef56a7}/src/cljs/clojure/browser/net.cljs +8 -7
  99. data/{vendor/assets → ext/clojure-clojurescript-bef56a7}/src/cljs/clojure/browser/repl.cljs +2 -2
  100. data/ext/clojure-clojurescript-bef56a7/src/cljs/clojure/core/reducers.cljs +298 -0
  101. data/ext/clojure-clojurescript-bef56a7/src/cljs/clojure/data.cljs +162 -0
  102. data/ext/clojure-clojurescript-bef56a7/src/cljs/clojure/reflect.cljs +48 -0
  103. data/{vendor/assets → ext/clojure-clojurescript-bef56a7}/src/cljs/clojure/set.cljs +0 -0
  104. data/{vendor/assets → ext/clojure-clojurescript-bef56a7}/src/cljs/clojure/string.cljs +4 -10
  105. data/{vendor/assets → ext/clojure-clojurescript-bef56a7}/src/cljs/clojure/walk.cljs +0 -0
  106. data/{vendor/assets → ext/clojure-clojurescript-bef56a7}/src/cljs/clojure/zip.cljs +0 -0
  107. data/ext/clojure-clojurescript-bef56a7/test/cljs/cljs/binding_test.cljs +7 -0
  108. data/ext/clojure-clojurescript-bef56a7/test/cljs/cljs/binding_test_other_ns.cljs +3 -0
  109. data/ext/clojure-clojurescript-bef56a7/test/cljs/cljs/core_test.cljs +1678 -0
  110. data/ext/clojure-clojurescript-bef56a7/test/cljs/cljs/import_test.cljs +11 -0
  111. data/ext/clojure-clojurescript-bef56a7/test/cljs/cljs/import_test/foo.cljs +5 -0
  112. data/ext/clojure-clojurescript-bef56a7/test/cljs/cljs/letfn_test.cljs +19 -0
  113. data/ext/clojure-clojurescript-bef56a7/test/cljs/cljs/macro_test.cljs +6 -0
  114. data/ext/clojure-clojurescript-bef56a7/test/cljs/cljs/macro_test/macros.clj +5 -0
  115. data/ext/clojure-clojurescript-bef56a7/test/cljs/cljs/ns_test.cljs +14 -0
  116. data/ext/clojure-clojurescript-bef56a7/test/cljs/cljs/ns_test/bar.cljs +3 -0
  117. data/ext/clojure-clojurescript-bef56a7/test/cljs/cljs/ns_test/foo.cljs +7 -0
  118. data/ext/clojure-clojurescript-bef56a7/test/cljs/cljs/reader_test.cljs +124 -0
  119. data/ext/clojure-clojurescript-bef56a7/test/cljs/clojure/data_test.cljs +22 -0
  120. data/ext/clojure-clojurescript-bef56a7/test/cljs/clojure/string_test.cljs +97 -0
  121. data/ext/clojure-clojurescript-bef56a7/test/cljs/foo/ns_shadow_test.cljs +9 -0
  122. data/ext/clojure-clojurescript-bef56a7/test/cljs/test_runner.cljs +26 -0
  123. data/lib/clementine.rb +3 -24
  124. data/lib/clementine/clojurescript_engine.rb +9 -48
  125. data/lib/clementine/clojurescript_engine/base.rb +15 -0
  126. data/lib/clementine/clojurescript_engine/jruby.rb +46 -0
  127. data/lib/clementine/{clojurescript_engine_mri.rb → clojurescript_engine/mri.rb} +17 -10
  128. data/lib/clementine/version.rb +1 -1
  129. data/test/clojurescript_engine_test.rb +36 -14
  130. metadata +177 -83
  131. data/vendor/assets/lib/clojure.jar +0 -0
  132. data/vendor/assets/lib/compiler.jar +0 -0
  133. data/vendor/assets/lib/goog.jar +0 -0
  134. data/vendor/assets/lib/js.jar +0 -0
  135. data/vendor/assets/src/clj/cljs/compiler.clj +0 -1341
  136. data/vendor/assets/src/clj/cljs/core.clj +0 -702
  137. data/vendor/assets/src/clj/cljs/repl/browser.clj +0 -341
  138. data/vendor/assets/src/cljs/cljs/core.cljs +0 -3330
  139. data/vendor/assets/src/cljs/cljs/reader.cljs +0 -360
@@ -0,0 +1,7 @@
1
+ external = {};
2
+
3
+ external.lib = {
4
+ send_alert : function (msg) {
5
+ alert("Sending Alert via " + msg + "!");
6
+ }
7
+ };
@@ -0,0 +1,3 @@
1
+ var external = {};
2
+ external.lib = {};
3
+ external.lib.send_alert = function() {};
@@ -0,0 +1,14 @@
1
+ <html>
2
+ <head>
3
+ <title>Hello Externed JavaScript Library</title>
4
+ </head>
5
+ <body>
6
+ <h1>Hello Externed JavaScript Library!</h1>
7
+ <script type="text/javascript" src="out/goog/base.js"></script>
8
+ <script type="text/javascript" src="externed-lib.js"></script>
9
+ <script type="text/javascript" src="hello-extern.js"></script>
10
+ <script>
11
+ goog.require('hello.extern_example');
12
+ </script>
13
+ </body>
14
+ </html>
@@ -0,0 +1,18 @@
1
+ <html>
2
+ <head>
3
+ <title>Hello External JavaScript Library</title>
4
+ </head>
5
+ <body>
6
+ <h1>Hello External JavaScript Library!</h1>
7
+ <!-- In unoptimized mode, additional script tags are required -->
8
+ <script type="text/javascript" src="out/goog/base.js"></script>
9
+ <script type="text/javascript" src="my-external-lib.js"></script>
10
+ <script type="text/javascript" src="hello-js.js"></script>
11
+ <script>
12
+ goog.require('hello_js.core');
13
+ </script>
14
+ <script>
15
+ hello_js.core.popup_msg('JavaScript calling a ClojureScript function');
16
+ </script>
17
+ </body>
18
+ </html>
@@ -0,0 +1,17 @@
1
+ <html>
2
+ <head>
3
+ <title>Hello External JavaScript Library</title>
4
+ </head>
5
+ <body>
6
+ <h1>Hello External JavaScript Library!</h1>
7
+ <script type="text/javascript" src="out/goog/base.js"></script>
8
+ <script type="text/javascript" src="my-external-lib.js"></script>
9
+ <script type="text/javascript" src="hello-js.js"></script>
10
+ <script>
11
+ goog.require('hello_js.core');
12
+ </script>
13
+ <script>
14
+ hello_js.core.popup_msg('JavaScript calling a ClojureScript function');
15
+ </script>
16
+ </body>
17
+ </html>
@@ -0,0 +1,3 @@
1
+ function send_alert(msg) {
2
+ alert("Sending Alert via " + msg + "!");
3
+ };
@@ -0,0 +1,9 @@
1
+ (ns hello-js.core)
2
+
3
+ (defn ^:export popup-msg
4
+ [msg]
5
+ (js/send_alert msg))
6
+
7
+ (popup-msg "ClojureScript calling a global function defined in an external JavaScript library")
8
+
9
+ (popup-msg (str "ClojureScript: the time is now " (js/Date.)))
@@ -0,0 +1,5 @@
1
+ (ns hello.extern-example)
2
+
3
+ (defn ^:export foo [] 42)
4
+
5
+ (external.lib/send_alert "ClojureScript calling a function defined in an externed JavaScript library")
@@ -0,0 +1,2 @@
1
+ out/
2
+ hello.js
@@ -0,0 +1,34 @@
1
+ Simple ClojureScript Project Example.
2
+
3
+ One-time Setup
4
+ ==============
5
+
6
+ - Create a CLOJURESCRIPT_HOME environment variable which points to the
7
+ ClojureScript root directory.
8
+
9
+ - If you have not already done so, execute
10
+
11
+ $CLOJURESCRIPT_HOME/script/bootstrap
12
+
13
+ - Add $CLOJURESCRIPT_HOME/bin to your PATH.
14
+
15
+ Run in Development Mode
16
+ =======================
17
+
18
+ Development mode allows for each file to be loaded in a separate script tag so
19
+ that errors can be easily tracked to the offending file.
20
+
21
+ cljsc src > hello.js
22
+
23
+ After running the above command, open hello-dev.html. Notice that each required
24
+ JavaScript file has been loaded in its most readable form.
25
+
26
+ Run Optimized JavaScript
27
+ ========================
28
+
29
+ Once an application is ready for production, a single optimized file can be produced.
30
+
31
+ cljsc src {:optimizations :advanced} > hello.js
32
+
33
+ After running the above command, open hello.html to view the result.
34
+
@@ -0,0 +1,18 @@
1
+ <html>
2
+ <head>
3
+ <title>Hello ClojureScript</title>
4
+ </head>
5
+ <body>
6
+ <h1>Hello ClojureScript!</h1>
7
+ <!-- In unoptimized mode, additional script tags are required -->
8
+ <script type="text/javascript" src="out/goog/base.js"></script>
9
+ <script type="text/javascript" src="hello.js"></script>
10
+ <script>
11
+ goog.require('hello.core');
12
+ </script>
13
+ <script>
14
+ alert(greet("ClojureScript"));
15
+ alert("The sum of [1,2,3,4,5,6,7,8,9] is: " + hello.core.sum([1,2,3,4,5,6,7,8,9]));
16
+ </script>
17
+ </body>
18
+ </html>
@@ -0,0 +1,13 @@
1
+ <html>
2
+ <head>
3
+ <title>Hello ClojureScript</title>
4
+ </head>
5
+ <body>
6
+ <h1>Hello ClojureScript!</h1>
7
+ <script type="text/javascript" src="hello.js"></script>
8
+ <script>
9
+ alert(greet("ClojureScript"));
10
+ alert("The sum of [1,2,3,4,5,6,7,8,9] is: " + hello.core.sum([1,2,3,4,5,6,7,8,9]));
11
+ </script>
12
+ </body>
13
+ </html>
@@ -0,0 +1,8 @@
1
+ (ns hello.core
2
+ (:require [hello.foo.bar :as bar]))
3
+
4
+ (defn ^{:export greet} greet [n]
5
+ (str "Hello " n))
6
+
7
+ (defn ^:export sum [xs]
8
+ (bar/sum xs))
@@ -0,0 +1,4 @@
1
+ (ns hello.foo.bar)
2
+
3
+ (defn sum [xs]
4
+ (reduce + 0 xs))
@@ -0,0 +1,18 @@
1
+ (ns nodehello)
2
+
3
+ (defn -main [& args]
4
+ (println (apply str (map [\space "world" "hello"] [2 0 1]))))
5
+
6
+ (set! *main-cli-fn* -main)
7
+
8
+ (comment
9
+ ; Compile this using a command line like:
10
+
11
+ CLOJURESCRIPT_HOME=".../clojurescript/" \
12
+ bin/cljsc samples/nodehello.cljs {:target :nodejs} \
13
+ > out/nodehello.js
14
+
15
+ ; Then run using:
16
+ nodejs out/nodehello.js
17
+
18
+ )
@@ -0,0 +1,17 @@
1
+ ; This one doesn't yet work with :optimizations :advanced
2
+ (ns nodels
3
+ (:require [cljs.nodejs :as nodejs]))
4
+
5
+ (def fs (nodejs/require "fs"))
6
+ (def path (nodejs/require "path"))
7
+
8
+ (defn file-seq [dir]
9
+ (tree-seq
10
+ (fn [f] (.isDirectory (.statSync fs f) ()))
11
+ (fn [d] (map #(.join path d %) (.readdirSync fs d)))
12
+ dir))
13
+
14
+ (defn -main [& paths]
15
+ (dorun (map println (mapcat file-seq paths))))
16
+
17
+ (set! *main-cli-fn* -main)
@@ -0,0 +1,2 @@
1
+ out/
2
+ main.js
@@ -0,0 +1,101 @@
1
+ # ClojureScript REPL Examples
2
+
3
+ The ClojureScript REPL has been updated to work with multiple
4
+ JavaScript evaluation environments. This readme and the example code
5
+ in this project show how to use the new REPL. There are now two
6
+ implemented environments: Rhino and the browser.
7
+
8
+ ## Using the new REPL
9
+
10
+ There are currently four steps in starting a ClojureScript REPL.
11
+
12
+ 1. require cljs.repl
13
+ 2. require the namespace which implements the desired evaluation environment
14
+ 3. create a new evaluation environment
15
+ 4. start the REPL with the created environment
16
+
17
+ ## Evaluating with Rhino
18
+
19
+ ```clj
20
+ (require '[cljs.repl :as repl])
21
+ (require '[cljs.repl.rhino :as rhino])
22
+ (def env (rhino/repl-env))
23
+ (repl/repl env)
24
+ ```
25
+
26
+ ## Evaluating in the Browser
27
+
28
+ A browser-connected REPL works in much the same way as a normal REPL:
29
+ forms are read from the console, evaluated and return values are
30
+ printed. A major and useful difference form normal REPL usage is that
31
+ all side-effects occur in the browser. You can show alerts, manipulate
32
+ the dom and interact with running applications.
33
+
34
+ The main benefit of using the browser as an evaluation environment is
35
+ that the REPL is no longer limited to non-browser code. You get all
36
+ the benefits of a REPL with all of your code.
37
+
38
+ The example below shows how to start a browser-connected REPL with an
39
+ empty project. The same technique can be used to integrate a REPL into
40
+ an existing project. In the future there may be an easier way to start
41
+ a browser-connected REPL without a project.
42
+
43
+ ### Building
44
+
45
+ This sample project contains an HTML file and single ClojureScript
46
+ file which establishes the connection to the REPL from the
47
+ browser. These are currently the minimum requirements for starting a
48
+ browser-connected REPL.
49
+
50
+ To build the project, launch a Clojure REPL from this folder
51
+
52
+ ```bash
53
+ cd samples/repl
54
+ ../../script/repl
55
+ ```
56
+
57
+ and evaluate the following forms:
58
+
59
+ ```clj
60
+ (use 'cljs.closure)
61
+ (def opts {:output-to "main.js" :output-dir "out"})
62
+ (build "src" opts)
63
+ ```
64
+
65
+ ### Starting the REPL and connecting to the browser
66
+
67
+ Start the REPL using the browser as the evaluator (do it in "samples/repl"):
68
+
69
+ ```clj
70
+ (require '[cljs.repl :as repl])
71
+ (require '[cljs.repl.browser :as browser])
72
+ (def env (browser/repl-env))
73
+ (repl/repl env)
74
+ ```
75
+
76
+ Open http://localhost:9000/ in a browser. When this page is loaded it will connect
77
+ to the REPL. Alternatively you can serve index.html from your own local webserver.
78
+
79
+ ### Try it out
80
+
81
+ ```clj
82
+ ;; Evaluate some basic forms.
83
+ (+ 1 1)
84
+ {:a :b}
85
+ "hello"
86
+ (reduce + [1 2 3 4 5])
87
+ (js/alert "Hello World!")
88
+
89
+ ;; Load a file, and use it.
90
+ (load-file "clojure/string.cljs")
91
+ (clojure.string/reverse "Hello")
92
+
93
+ ;; Define functions and call them.
94
+ (defn sum [coll] (reduce + coll))
95
+ (sum [2 2 2 2])
96
+
97
+ ;; Create dom elements.
98
+ (ns dom.testing (:require [clojure.browser.dom :as dom]))
99
+ (dom/append (dom/get-element "content")
100
+ (dom/element "Hello World!"))
101
+ ```
@@ -0,0 +1,27 @@
1
+ <!doctype html>
2
+ <!--[if lt IE 7 ]> <html lang="en" class="no-js ie6"> <![endif]-->
3
+ <!--[if IE 7 ]> <html lang="en" class="no-js ie7"> <![endif]-->
4
+ <!--[if IE 8 ]> <html lang="en" class="no-js ie8"> <![endif]-->
5
+ <!--[if IE 9 ]> <html lang="en" class="no-js ie9"> <![endif]-->
6
+ <!--[if (gt IE 9)|!(IE)]><!--> <html lang="en" class="no-js"> <!--<![endif]-->
7
+ <head>
8
+ <meta charset="UTF-8">
9
+ <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
10
+
11
+ <title>Browser-connected REPL</title>
12
+ <meta name="viewport" content="width=device-width,initial-scale=1.0">
13
+
14
+ <!--[if lt IE 9]>
15
+ <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
16
+ <![endif]-->
17
+
18
+ </head>
19
+ <body>
20
+ <div id="content">
21
+ <script type="text/javascript" src="out/goog/base.js"></script>
22
+ <script type="text/javascript" src="main.js"></script>
23
+ <script type="text/javascript">
24
+ goog.require('repl.test');
25
+ </script>
26
+ </body>
27
+ </html>
@@ -0,0 +1,73 @@
1
+ ;; Copyright (c) Rich Hickey. All rights reserved.
2
+ ;; The use and distribution terms for this software are covered by the
3
+ ;; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
4
+ ;; which can be found in the file epl-v10.html at the root of this distribution.
5
+ ;; By using this software in any fashion, you are agreeing to be bound by
6
+ ;; the terms of this license.
7
+ ;; You must not remove this notice, or any other, from this software.
8
+
9
+ (ns repl.test
10
+ (:require [clojure.browser.repl :as repl]
11
+ [clojure.reflect :as reflect]))
12
+
13
+ (repl/connect "http://localhost:9000/repl")
14
+
15
+ (comment
16
+
17
+ ;; Note: If you would like for the compiler to be aware of
18
+ ;; everything in a project then delete the 'out' directory before
19
+ ;; calling build. This will force the compiler to compile the whole
20
+ ;; project.
21
+
22
+ ;; Compile this project to JavaScript
23
+ (use 'cljs.closure)
24
+ (def opts {:output-to "samples/repl/main.js"
25
+ :output-dir "samples/repl/out"})
26
+ (build "samples/repl/src" opts)
27
+
28
+ ;; Start REPL
29
+ (do (require '[cljs.repl :as repl])
30
+ (require '[cljs.repl.browser :as browser])
31
+ (def env (browser/repl-env))
32
+ (repl/repl env))
33
+
34
+ ;; Open http://localhost:9000/ in a browser. When this page is loaded
35
+ ;; it will connect to the REPL. Alternatively you can serve index.html
36
+ ;; from your own local webserver.
37
+
38
+ ;; Evaluate some basic forms
39
+ (+ 1 1)
40
+ (string-print "hello")
41
+ (prn "foo")
42
+ (prn {:a :b})
43
+ (println "hello")
44
+ (doseq [next (range 20)] (println next))
45
+ {:a :b}
46
+ "hello"
47
+ (reduce + [1 2 3 4 5])
48
+ (time (reduce + (range 10000)))
49
+ (js/alert "Hello World!")
50
+
51
+ (load-file "clojure/string.cljs")
52
+ (clojure.string/reverse "Hello")
53
+
54
+ (defn sum [coll] (reduce + coll))
55
+ (sum [2 2 2 2])
56
+
57
+ ;; Create dom elements.
58
+ (ns dom.testing (:require [clojure.browser.dom :as dom]))
59
+ (dom/append (dom/get-element "content")
60
+ (dom/element "Hello World!"))
61
+
62
+ ;; Load something we haven't used yet
63
+ (ns test.crypt
64
+ (:require [goog.crypt :as c]))
65
+ (c/stringToByteArray "ClojureScript")
66
+
67
+ (load-namespace 'goog.date.Date)
68
+ (goog.date.Date.)
69
+
70
+ (ns test.color (:require [goog.color :as c]))
71
+ (js->clj (c/parse "#000000"))
72
+
73
+ )
@@ -0,0 +1,2 @@
1
+ out/
2
+ twitterbuzz.js
@@ -0,0 +1,42 @@
1
+ # ClojureScript "TwitterBuzz" Demo
2
+
3
+ ## One-time Setup
4
+
5
+ See https://github.com/clojure/clojurescript/wiki/Quick-Start
6
+
7
+ ## Run in Development Mode
8
+
9
+ Compile the demo:
10
+
11
+ cljsc src > twitterbuzz.js
12
+
13
+ After running the above command, open index.html.
14
+
15
+ ## Compile in Development Mode with the REPL (Faster)
16
+
17
+ * Run `script/repl`
18
+ * To run it from Emacs, `C-x d` and nav to the `clojurescript` directory
19
+ * `M-x set-variable inferior-lisp-program`
20
+ * Set to `"script/repl"`
21
+ * `M-x run-lisp`
22
+
23
+ * Once the REPL is running, evaluate:
24
+
25
+ (use 'cljs.closure)
26
+ (def opts {:output-to "samples/twitterbuzz/twitterbuzz.js" :output-dir "samples/twitterbuzz/out"})
27
+
28
+ (build "samples/twitterbuzz/src" opts)
29
+
30
+ The reason we set the `:output-dir` is because the `index.html` script tag is specifically pointing to that directory.
31
+
32
+ * See `cljs.closure` source for more compilation examples.
33
+
34
+ ## Compile in Advanced Mode
35
+
36
+ `cljsc` can be run with a Clojure map of compiler options. To compile using `cljsc` and Closure Compiler's "advanced" optimization setting:
37
+
38
+ cljsc src '{:optimizations :advanced}' > twitterbuzz.js
39
+
40
+ Because advanced mode results in only one `.js` file, `twitterbuzz.js`, only one `<script>` include tag is required. To see the app as compiled in advanced mode, open `index-advanced.html`.
41
+
42
+ See https://github.com/clojure/clojurescript/wiki/Quick-Start for more information about compiling in advanced mode.