Permalink
Browse files

fixed cljsbuild integration

  • Loading branch information...
1 parent 86c998c commit 8eeb2e9906ddcb16a3bc779c5a2257d60b11b863 @fmw committed Aug 6, 2012
View
@@ -33,11 +33,13 @@ pre-compiled package as well. If you are a non-technical user
`Vixu.com`_ is happy to set up a free demo account for you in return
for your feedback (use the contact information below to get in touch).
-Vix has the following dependencies: `Leiningen`_, `ClojureScript`_ and
-`CouchDB`_. The compiler for the Soy templates is a separate download
-that you can find here: `download Soy`_. For production use you also
-need an application server like `Apache Tomcat`_, but for testing and
-development you just need a working Java environment.
+Vix requires a working Java environment with `Leiningen`_ and
+`CouchDB`_ installed. The compiler for the Soy templates is a separate
+download that you can find here: `download Soy`_. The other
+dependencies are installed through Leiningen. For production use you
+also need an application server like `Apache Tomcat`_, but for testing
+and development you can launch a simple server using the Ring plugin
+for Leiningen.
This is the sequence of commands used to install Vix on a clean Ubuntu
12.04 LTS installation (if you already installed some of the
@@ -119,35 +121,10 @@ Install rlwrap::
sudo apt-get install rlwrap
-Add the following lines to your your ~/.bash_profile or ~/.bashrc file
-using your favorite text editor::
-
- export CLOJURESCRIPT_HOME="$HOME/clj/clojurescript"
-
- alias cotpl="java -jar SoyToJsSrcCompiler.jar --shouldProvideRequireSoyNamespaces --shouldGenerateJsdoc --outputPathFormat resources/public/js/soy/{INPUT_FILE_NAME_NO_EXT}.soy.js soy/editor.soy soy/feed.soy"
- alias cljs="rlwrap java -cp \"$CLOJURESCRIPT_HOME/lib/*:$CLOJURESCRIPT_HOME/src/clj:$CLOJURESCRIPT_HOME/src/cljs/:$CLOJURESCRIPT_HOME/test/cljs:cljs/macros\" clojure.main"
-
-If you don't want to restart your terminal emulator after creating
-this file you can run, e.g.::
-
- source ~/.bash_profile
-
-Compile the templates (this command must be executed in the vix
-directory)::
+Compile the templates::
cd ~/clj/vix
- cotpl
-
-Create the output directory for the compiled JavaScript::
-
- mkdir ~/clj/vix/resources/public/js/vix
-
-Install ClojureScript::
-
- cd ~/clj
- git clone git://github.com/clojure/clojurescript.git
- cd clojurescript/
- script/bootstrap --closure-library-head
+ java -jar SoyToJsSrcCompiler.jar --shouldProvideRequireSoyNamespaces --shouldGenerateJsdoc --outputPathFormat resources/public/js/soy/{INPUT_FILE_NAME_NO_EXT}.soy.js soy/editor.soy soy/feed.soy
Create a directory to store Apache Lucene indexes (you can change the
path in src/vix/lucene.clj)::
@@ -156,21 +133,10 @@ path in src/vix/lucene.clj)::
sudo mkdir /var/lucene/vix
sudo chown yourusername:yourusergroup /var/lucene/vix
-Start the ClojureScript REPL to compile the client-side code::
-
- cd ~/clj/vix
- cljs
-
-Execute this code to compile the ClojureScript, but change the
-directory "/home/fmw/clj/vix" to reflect the right path on your
-system::
-
- (use 'cljs.closure)
- (defn b [] (build "/home/fmw/clj/vix/cljs/src" {:pretty-print true :output-to "/home/fmw/clj/vix/resources/public/js/vix/vix.js" :output-dir "/home/fmw/clj/vix/resources/public/js/out" :libs ["/home/fmw/clj/vix/resources/public/js/soy/"]}))
- (b)
+You can compile the client-side ClojureScript code using the
+`lein-cljsbuild`_ plugin::
-You can ignore any undeclared Var errors; just run (b) again to
-recompile in that case.
+ lein cljsbuild once
Start the server::
@@ -212,3 +178,4 @@ touch!
.. _`ClojureScript quickstart instructions`: https://github.com/clojure/clojurescript/wiki/Quick-Start
.. _`Apache Tomcat`: http://tomcat.apache.org/
.. _`CouchDB`: http://couchdb.apache.org/
+.. _`lein-cljsbuild`: https://github.com/emezeske/lein-cljsbuild
View
@@ -0,0 +1,32 @@
+if (phantom.args.length != 1) {
+ console.log('Expected a target URL parameter.');
+ phantom.exit(1);
+}
+
+var page = require('webpage').create();
+var url = phantom.args[0];
+var page_opened = false;
+
+page.onConsoleMessage = function (message) {
+ console.log("App console: " + message);
+};
+
+console.log("Loading URL: " + url);
+
+page.open(url, function (status) {
+ // FIXME: This is a horrible, ridiculous hack. For some reason,
+ // PhantomJS calls page.open() twice, and if doesn't return
+ // immediately the second time, things break. Reference:
+ // http://code.google.com/p/phantomjs/issues/detail?id=353&q=wait&sort=-type
+ if (page_opened) {
+ return;
+ }
+ page_opened = true;
+
+ if (status != "success") {
+ console.log('Failed to open ' + url);
+ phantom.exit(1);
+ }
+
+ console.log("Loaded successfully.");
+});
View
@@ -0,0 +1,39 @@
+if (phantom.args.length != 1) {
+ console.log('Expected a target URL parameter.');
+ phantom.exit(1);
+}
+
+var page = require('webpage').create();
+var url = phantom.args[0];
+
+page.onConsoleMessage = function (message) {
+ console.log("Test console: " + message);
+};
+
+console.log("Loading URL: " + url);
+
+page.open(url, function (status) {
+ if (status != "success") {
+ console.log('Failed to open ' + url);
+ phantom.exit(1);
+ }
+
+ console.log("Running test.");
+
+ var result = page.evaluate(function() {
+ return bg.test.run();
+ });
+
+ // NOTE: PhantomJS 1.4.0 has a bug that prevents the exit codes
+ // below from being returned properly. :(
+ //
+ // http://code.google.com/p/phantomjs/issues/detail?id=294
+
+ if (result != 0) {
+ console.log("*** Test failed! ***");
+ phantom.exit(1);
+ }
+
+ console.log("Test succeeded.");
+ phantom.exit(0);
+});
View
@@ -20,7 +20,7 @@
[org.apache.lucene/lucene-queries "3.5.0"]]
:plugins [[lein-ring "0.7.1"]
[lein-cljsbuild "0.2.5"]]
- :ring vix.routes/app
+ :ring {:handler vix.routes/app}
:min-lein-version "2.0.0"
:hooks [leiningen.cljsbuild]
:source-paths ["src" "src/clj"]
@@ -78,16 +78,21 @@
"-i"
"~/Pictures/clojure-glyph.svg"
"lein-cljsbuild"]
- :compiler {:output-to (str "resources/public/js/"
- "main-debug.js")
- :optimizations :whitespace
- :pretty-print true}}
+ :compiler {:output-to
+ "resources/public/js/main-debug.js"
+ :libs
+ ["resources/public/js/soy/"]
+ :optimizations
+ :whitespace
+ :pretty-print
+ true}}
;; This build has the highest level of
;; optimizations, so it is efficient when
;; running the app in production.
:prod
{:source-path "src/cljs"
:compiler {:output-to "resources/public/js/main.js"
+ :libs ["resources/public/js/soy/"]
:optimizations :advanced
:pretty-print false}}
;; This build is for the ClojureScript unit
@@ -96,7 +101,11 @@
;; how it's run.
:test
{:source-path "test/cljs"
- :compiler {:output-to (str "resources/private/js/"
- "unit-test.js")
- :optimizations :whitespace
- :pretty-print true}}}})
+ :compiler {:output-to
+ "resources/private/js/unit-test.js"
+ :libs
+ ["resources/public/js/soy/"]
+ :optimizations
+ :whitespace
+ :pretty-print
+ true}}}})
View
@@ -479,7 +479,7 @@
<ul draggable="false">
{call .menu_items}
{param links: $children /}
- {param new: false /}
+ {param new_item: false /}
{param nested: true /}
{/call}
</ul>
@@ -490,7 +490,7 @@
/**
*
* @param links
- * @param new
+ * @param new_item
* @param nested
*/
{template .menu_items}
@@ -503,10 +503,10 @@
{/call}
{/foreach}
- {if $new}
+ {if $new_item}
{call .menu_item_li}
- {param label: $new.label /}
- {param uri: $new.uri /}
+ {param label: $new_item.label /}
+ {param uri: $new_item.uri /}
{param nested: $nested /}
{/call}
{/if}
View
@@ -15,49 +15,12 @@
(ns vix.core
(:use-macros [vix.crossover.macros :only [routes]])
- (:require [vix.views.editor :as editor]
+ (:require [vix.util :as util]
+ [vix.views.editor :as editor]
[vix.views.feed :as feed]
[clojure.browser.repl :as repl]
- [goog.global :as global]
- [goog.events :as events]
- [goog.history.EventType :as event-type]
- [goog.history.Html5History :as Html5History]
- [goog.Uri :as Uri]
- [goog.dom :as dom]
[clojure.string :as string]))
-(def *h* (atom nil))
-
-(defn get-path [uri]
- (. (new goog.Uri uri false) (getPath)))
-
-(defn get-internal-links! []
- (filter #(= (.substr (get-path (.-href %)) 0 7) "/admin/")
- (cljs.core.Vector/fromArray
- (. global/document (getElementsByTagName "a")))))
-
-; FIXME: figure out while only nested calls (e.g. in
-; create-document-list-events and render-editor-template)
-; work and replace with a centralized call
-(defn xhrify-internal-links! [link-elements]
- (doseq [element link-elements]
- (events/listen element
- "click"
- (fn [e]
- (. e (preventDefault))
- (navigate (.substr (get-path (.-href (.-target e))) 7)
- (.-title (.-target e)))))))
-
-(defn start-history! []
- (compare-and-set! *h* nil (new goog.history.Html5History))
- (.setUseFragment @*h* false)
- (.setPathPrefix @*h* "/admin/")
- (.setEnabled @*h* true)
- (events/listen @*h*
- event-type/NAVIGATE
- (fn [e]
- (execute-routes! global/document.location.pathname))))
-
(defn chop-path [path]
(rest (string/split path #"/")))
@@ -126,17 +89,12 @@
["admin" :language :feed-name "overview"]
(feed/list-documents (:language params) (:feed-name params))
:fallback
- (navigate-replace-state "" "Vix overview")))
-
-(defn navigate [token title]
- (. @*h* (setToken token title)))
-
-(defn navigate-replace-state [token title]
- (. @*h* (replaceToken token title)))
+ (util/navigate-replace-state "" "Vix overview")))
(defn ^:export start-app [uri-path]
;; in Chrome this triggers an event, leading to a (routes) call
- (start-history!)
+ (util/start-history! (fn [e]
+ (execute-routes! js/document.location.pathname)))
(execute-routes! uri-path))
(defn ^:export repl-connect []
Oops, something went wrong.

0 comments on commit 8eeb2e9

Please sign in to comment.