Permalink
Browse files

Merge branch 'master' into atom-watches

  • Loading branch information...
2 parents cb04a69 + 2c2f49e commit 384065e52c06eaf819ca208e310a9da1b8f33961 @fogus fogus committed Sep 23, 2011
View
@@ -0,0 +1,2 @@
+out/
+dom.js
@@ -0,0 +1,48 @@
+(ns dom.test
+ (:require [clojure.browser.event :as event]
+ [clojure.browser.dom :as dom]))
+
+(defn log [& args]
+ (.log js/console (apply pr-str args)))
+
+(defn log-obj [obj]
+ (.log js/console obj))
+
+(defn log-listener-count []
+ (log "listener count: " (event/total-listener-count)))
+
+(def source (dom/get-element "source"))
+(def destination (dom/get-element "destination"))
+
+(dom/append source
+ (dom/element "Testing me ")
+ (dom/element "out!"))
+
+(def success-count (atom 0))
+
+(log-listener-count)
+
+(event/listen source
+ :click
+ (fn [e]
+ (let [i (swap! success-count inc)
+ e (dom/element :li
+ {:id "testing"
+ :class "test me out please"}
+ "It worked!")]
+ (log-obj e)
+ (log i)
+ (dom/append destination
+ e))))
+
+(log-obj (dom/element "Text node"))
+(log-obj (dom/element :li))
+(log-obj (dom/element :li {:class "foo"}))
+(log-obj (dom/element :li {:class "bar"} "text node"))
+(log-obj (dom/element [:ul [:li :li :li]]))
+(log-obj (dom/element :ul [:li :li :li]))
+(log-obj (dom/element :li {} [:ul {} [:li :li :li]]))
+(log-obj (dom/element [:li {:class "baz"} [:li {:class "quux"}]]))
+
+(log-obj source)
+(log-listener-count)
View
@@ -0,0 +1,30 @@
+<!doctype html>
+<!--[if lt IE 7 ]> <html lang="en" class="no-js ie6"> <![endif]-->
+<!--[if IE 7 ]> <html lang="en" class="no-js ie7"> <![endif]-->
+<!--[if IE 8 ]> <html lang="en" class="no-js ie8"> <![endif]-->
+<!--[if IE 9 ]> <html lang="en" class="no-js ie9"> <![endif]-->
+<!--[if (gt IE 9)|!(IE)]><!--> <html lang="en" class="no-js"> <!--<![endif]-->
+ <head>
+ <meta charset="UTF-8">
+ <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
+
+ <title>DOM testing</title>
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
+
+ <!--[if lt IE 9]>
+ <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
+ <![endif]-->
+
+ </head>
+ <body>
+ <div id="source"></div>
+ <ol id="destination"></ol>
+
+ <script type="text/javascript" src="out/goog/base.js"></script>
+ <script type="text/javascript" src="dom.js"></script>
+ <script type="text/javascript">
+ goog.require('dom.test');
+ </script>
+
+ </body>
+</html>
View
@@ -0,0 +1,2 @@
+out/
+main.js
View
@@ -0,0 +1,95 @@
+# ClojureScript REPL Examples
+
+The ClojureScript REPL has been updated to work with multiple
+JavaScript evaluation environments. This readme and the example code
+in this project show how to use the new REPL. There are now two
+implemented environments: Rhino and the browser.
+
+## Using the new REPL
+
+There are currently four steps in starting a ClojureScript REPL.
+
+1. require cljs.repl
+2. require the namespace which implements the desired evaluation environment
+3. create a new evaluation environment
+4. start the REPL with the created environment
+
+## Evaluating with Rhino
+
+```clj
+(require '[cljs.repl :as repl])
+(require '[cljs.repl.rhino :as rhino])
+(def env (rhino/repl-env))
+(repl/repl env)
+```
+
+## Evaluating in the Browser
+
+A browser-connected REPL works in much the same way as a normal REPL:
+forms are read from the console, evaluated and return values are
+printed. A major and useful difference form normal REPL usage is that
+all side-effects occur in the browser. You can show alerts, manipulate
+the dom and interact with running applications.
+
+The main benefit of using the browser as an evaluation environment is
+that the REPL is no longer limited to non-browser code. You get all
+the benefits of a REPL with all of your code.
+
+The example below shows how to start a browser-connected REPL with an
+empty project. The same technique can be used to integrate a REPL into
+an existing project. In the future there may be an easier way to start
+a browser-connected REPL without a project.
+
+### Building
+
+This sample project contains an HTML file and single ClojureScript
+file which establishes the connection to the REPL from the
+browser. These are currently the minimum requirements for starting a
+browser-connected REPL.
+
+To build the project, launch a Clojure REPL and evaluate the following
+forms:
+
+```clj
+(use 'cljs.closure)
+(def opts {:output-to "samples/repl/main.js" :output-dir "samples/repl/out"})
+(build "samples/repl/src" opts)
+```
+
+### Starting the REPL and connecting to the browser
+
+Start the REPL using the browser as the evaluator:
+
+```clj
+(require '[cljs.repl :as repl])
+(require '[cljs.repl.browser :as browser])
+(def env (browser/repl-env))
+(repl/repl env)
+```
+
+Open index.html in a browser. When this page is loaded it will connect
+to the REPL.
+
+### Try it out
+
+```clj
+;; Evaluate some basic forms.
+(+ 1 1)
+{:a :b}
+"hello"
+(reduce + [1 2 3 4 5])
+(js/alert "Hello World!")
+
+;; Load a file, and use it.
+(load-file "clojure/string.cljs")
+(clojure.string/reverse "Hello")
+
+;; Define functions and call them.
+(defn sum [coll] (reduce + coll))
+(sum [2 2 2 2])
+
+;; Create dom elements.
+(ns dom.testing (:require [clojure.browser.dom :as dom]))
+(dom/append (dom/get-element "content")
+ (dom/element "Hello World!"))
+```
View
@@ -0,0 +1,27 @@
+<!doctype html>
+<!--[if lt IE 7 ]> <html lang="en" class="no-js ie6"> <![endif]-->
+<!--[if IE 7 ]> <html lang="en" class="no-js ie7"> <![endif]-->
+<!--[if IE 8 ]> <html lang="en" class="no-js ie8"> <![endif]-->
+<!--[if IE 9 ]> <html lang="en" class="no-js ie9"> <![endif]-->
+<!--[if (gt IE 9)|!(IE)]><!--> <html lang="en" class="no-js"> <!--<![endif]-->
+ <head>
+ <meta charset="UTF-8">
+ <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
+
+ <title>Browser-connected REPL</title>
+ <meta name="viewport" content="width=device-width,initial-scale=1.0">
+
+ <!--[if lt IE 9]>
+ <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
+ <![endif]-->
+
+ </head>
+ <body>
+ <div id="content">
+ <script type="text/javascript" src="out/goog/base.js"></script>
+ <script type="text/javascript" src="main.js"></script>
+ <script type="text/javascript">
+ goog.require('repl.test');
+ </script>
+ </body>
+</html>
@@ -0,0 +1,61 @@
+;; Copyright (c) Rich Hickey. All rights reserved.
+;; The use and distribution terms for this software are covered by the
+;; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
+;; which can be found in the file epl-v10.html at the root of this distribution.
+;; By using this software in any fashion, you are agreeing to be bound by
+;; the terms of this license.
+;; You must not remove this notice, or any other, from this software.
+
+(ns repl.test
+ (:require [clojure.browser.repl :as repl]))
+
+(repl/connect "http://localhost:9000/repl")
+
+(comment
+
+ ;; Note: If you would like for the compiler to be aware of
+ ;; everything in a project then delete the 'out' directory before
+ ;; calling build. This will force the compiler to compile the whole
+ ;; project.
+
+ ;; Compile this project to JavaScript
+ (use 'cljs.closure)
+ (def opts {:output-to "samples/repl/main.js"
+ :output-dir "samples/repl/out"})
+ (build "samples/repl/src" opts)
+
+ ;; Start REPL
+ (do (require '[cljs.repl :as repl])
+ (require '[cljs.repl.browser :as browser])
+ (def env (browser/repl-env))
+ (repl/repl env))
+
+ ;; Open the file samples/repl/index.html
+
+ ;; Evaluate some basic forms
+ (+ 1 1)
+ {:a :b}
+ "hello"
+ (reduce + [1 2 3 4 5])
+ (js/alert "Hello World!")
+
+ (load-file "clojure/string.cljs")
+ (clojure.string/reverse "Hello")
+
+ (defn sum [coll] (reduce + coll))
+ (sum [2 2 2 2])
+
+ ;; Create dom elements.
+ (ns dom.testing (:require [clojure.browser.dom :as dom]))
+ (dom/append (dom/get-element "content")
+ (dom/element "Hello World!"))
+
+ ;; Load something we haven't used yet
+ (ns test.crypt
+ (:require [goog.crypt :as c]))
+ (c/stringToByteArray "ClojureScript")
+
+ (load-namespace 'goog.date.Date)
+ (goog.date.Date.)
+
+ )
View
@@ -3,29 +3,37 @@
mkdir -p lib
echo "Fetching Clojure..."
-curl -O -s http://repo1.maven.org/maven2/org/clojure/clojure/1.3.0-beta1/clojure-1.3.0-beta1.zip
-unzip -q clojure-1.3.0-beta1.zip
-cp clojure-1.3.0-beta1/clojure-1.3.0-beta1.jar lib/clojure.jar
-rm -rf clojure-1.3.0-beta1/
-rm clojure-1.3.0-beta1.zip
+curl -O -s http://repo1.maven.org/maven2/org/clojure/clojure/1.3.0-beta3/clojure-1.3.0-beta3.zip
+unzip -qu clojure-1.3.0-beta3.zip
+echo "Copying clojure-1.3.0-beta3/clojure-1.3.0-beta3.jar to lib/clojure.jar..."
+cp clojure-1.3.0-beta3/clojure-1.3.0-beta3.jar lib/clojure.jar
+echo "Cleaning up Clojure directory..."
+rm -rf clojure-1.3.0-beta3/
+echo "Cleaning up Clojure archive..."
+rm clojure-1.3.0-beta3.zip
-echo "Fetching Google Closure Library..."
+echo "Fetching Google Closure library..."
mkdir -p closure/library
cd closure/library
curl -O -s http://closure-library.googlecode.com/files/closure-library-20110323-r790.zip
-unzip -q closure-library-20110323-r790.zip
+unzip -qu closure-library-20110323-r790.zip
+echo "Cleaning up Google Closure library archive..."
rm closure-library-20110323-r790.zip
cd ..
-echo "Fetching Google Closure Compiler..."
+echo "Fetching Google Closure compiler..."
mkdir -p compiler
cd compiler
curl -O -s http://closure-compiler.googlecode.com/files/compiler-latest.zip
-unzip -q compiler-latest.zip
+unzip -qu compiler-latest.zip
+echo "Cleaning up Google Closure compiler archive..."
rm compiler-latest.zip
cd ../..
-echo "Building goog.jar..."
+echo "Building lib/goog.jar..."
+echo "jar cf ./lib/goog.jar -C closure/library/closure/ goog"
jar cf ./lib/goog.jar -C closure/library/closure/ goog
-echo "Copying closure/compiler/compiler.jar to lib/..."
+echo "Copying closure/compiler/compiler.jar to lib/compiler.jar"
cp closure/compiler/compiler.jar lib
+
+echo "[Bootstrap Completed]"
View
@@ -1,9 +1,9 @@
#!/bin/sh
-java -server -Xmx2G -Xms2G -Xmn256m -cp 'lib/*:src/clj:src/cljs' clojure.main - > core.js <<CLJ
-(require :reload '[cljs.compiler :as comp] '[cljs.core])
-(binding [comp/*cljs-verbose* true]
- (comp/load-file (comp/repl-env) "cljs/core.cljs"))
+rm core.js
+java -server -Xmx2G -Xms2G -Xmn256m -cp 'lib/*:src/clj:src/cljs' clojure.main - <<CLJ
+(require :reload '[cljs.compiler :as comp] '[clojure.java.io :as io] '[cljs.core])
+(comp/compile-file (io/resource "cljs/core.cljs") "core.js")
CLJ
java -jar closure/compiler/compiler.jar \
View
@@ -10,6 +10,6 @@ for next in lib/*: src/clj: src/cljs: test/cljs; do
done
java -server -cp $CLJSC_CP clojure.main -e \
-"(require '[cljs.compiler :as comp])
-(def jse (comp/repl-env))
-(comp/repl jse)"
+"(require '[cljs.repl :as repl])
+(require '[cljs.repl.rhino :as rhino])
+(repl/repl (rhino/repl-env))"
View
@@ -9,6 +9,6 @@ for /R "%CLOJURESCRIPT_HOME%\lib" %%a in (*.jar) do (
)
set CLASSPATH=!CLASSPATH!"
-set REPL_CLJ="(require '[cljs.compiler :as comp])(def jse (comp/repl-env))(comp/repl jse)"
+set REPL_CLJ="(require '[cljs.repl :as repl])(require '[cljs.repl.rhino :as rhino])(repl/repl (rhino/repl-env))"
java -server -cp "%CLASSPATH%" clojure.main -e %REPL_CLJ%
Oops, something went wrong.

0 comments on commit 384065e

Please sign in to comment.