Permalink
Browse files

CLJS-54: Added a basic sample app that uses an external js lib

  • Loading branch information...
fogus committed Sep 23, 2011
1 parent c418df9 commit 368655be3be03d09fbeb937a182b966e32a2b030
@@ -0,0 +1,2 @@
+out/
+hello*.js
View
@@ -0,0 +1,33 @@
+Simple ClojureScript Project Example Using an External JavaScript Library
+
+One-time Setup
+==============
+
+- Create a CLOJURESCRIPT_HOME environment variable which points to the
+ ClojureScript root directory.
+
+- If you have not already done so, execute
+
+ $CLOJURESCRIPT_HOME/script/bootstrap
+
+- Add $CLOJURESCRIPT_HOME/bin to your PATH.
+
+Run in Development Mode
+=======================
+
+Development mode allows for each file to be loaded in a separate script tag so
+that errors can be easily tracked to the offending file.
+
+ cljsc src > hello-js.js
+
+After running the above command, open hello-js-dev.html. Notice that each required
+JavaScript file has been loaded in its most readable form.
+
+Run Optimized JavaScript
+========================
+
+Once an application is ready for production, a single optimized file can be produced.
+
+ cljsc src {:optimizations :advanced} > hello-js.js
+
+After running the above command, open hello-js.html to view the result.
@@ -0,0 +1,18 @@
+<html>
+ <head>
+ <title>Hello External JavaScript Library</title>
+ </head>
+ <body>
+ <h1>Hello External JavaScript Library!</h1>
+ <!-- In unoptimized mode, additional script tags are required -->
+ <script type="text/javascript" src="out/goog/base.js"></script>
+ <script type="text/javascript" src="my-external-lib.js"></script>
+ <script type="text/javascript" src="hello-js.js"></script>
+ <script>
+ goog.require('hello_js.core');
+ </script>
+ <script>
+ hello_js.core.popup_msg('JavaScript calling a ClojureScript function');
+ </script>
+ </body>
+</html>
@@ -0,0 +1,13 @@
+<html>
+ <head>
+ <title>Hello External JavaScript Library</title>
+ </head>
+ <body>
+ <h1>Hello External JavaScript Library!</h1>
+ <script type="text/javascript" src="my-external-lib.js"></script>
+ <script type="text/javascript" src="hello-js.js"></script>
+ <script>
+ hello_js.core.popup_msg('JavaScript calling a ClojureScript function');
+ </script>
+ </body>
+</html>
@@ -0,0 +1,3 @@
+function send_alert(msg) {
+ alert("Sending Alert via " + msg + "!");
+};
@@ -0,0 +1,9 @@
+(ns hello-js.core)
+
+(defn ^:export popup-msg
+ [msg]
+ (js/send_alert msg))
+
+(popup-msg "ClojureScript calling a global function defined in an external JavaScript library")
+
+(popup-msg (str "ClojureScript: the time is now " (js/Date.)))

0 comments on commit 368655b

Please sign in to comment.