Skip to content

Commit

Permalink
componentize all the state!!1!
Browse files Browse the repository at this point in the history
  • Loading branch information
Dom Kiva-Meyer committed Jun 7, 2014
1 parent 4a6762f commit 6ea23a0
Show file tree
Hide file tree
Showing 9 changed files with 362 additions and 346 deletions.
19 changes: 9 additions & 10 deletions project.clj
Original file line number Diff line number Diff line change
@@ -1,51 +1,50 @@
(defproject omelette "0.0.0"

:description "Example of mirrored server/client rendering and routing using Om, Sente, Secretary, and the Nashorn JavaScript engine."
:description "Example of mirrored server/client rendering and routing using Om, Sente, and the Nashorn JavaScript engine."

:license {:name "Eclipse Public License"
:url "http://www.eclipse.org/legal/epl-v10.html"
:distribution :repo
:comments "Same as Clojure"}

:main omelette.handler
:main omelette.main

:global-vars {*warn-on-reflection* true}

:source-paths ["src" "target/src"]

:resource-paths ["resources" "target/resources"]

:dependencies [[ankha "0.1.2"]
[com.cemerick/url "0.1.1"]
:dependencies [[ankha "0.1.3"]
[com.stuartsierra/component "0.2.1"]
[com.taoensso/encore "1.6.0"]
[com.taoensso/sente "0.14.1"]
[compojure "1.1.8"]
[hiccup "1.0.5"]
[http-kit "2.1.18"]
[lein-light-nrepl "0.0.18"]
[markdown-clj "0.9.44"]
[om "0.6.2"]
[om "0.6.4"]
[org.clojure/clojure "1.6.0"]
[org.clojure/clojurescript "0.0-2227"]
[org.clojure/core.async "0.1.298.0-2a82a1-alpha"]
[org.clojure/core.match "0.2.1"]
[org.clojure/tools.nrepl "0.2.3"]
[ring "1.2.2"]
[org.clojure/tools.namespace "0.2.4"]
[ring "1.3.0"]
[ring/ring-anti-forgery "0.3.2"]
[sablono "0.2.17"]]

:plugins [[com.keminglabs/cljx "0.3.2"]
[lein-cljsbuild "1.0.3"]
[lein-pdo "0.1.1"]]

:hooks [cljx.hooks]
:hooks [cljx.hooks leiningen.cljsbuild]

:cljx {:builds [{:source-paths ["src"], :output-path "target/src", :rules :clj}
{:source-paths ["src"], :output-path "target/src", :rules :cljs}]}

:cljsbuild {:builds [{:source-paths ["src" "target/src"]
:compiler {
;; :preamble ["react/react.js"]
:preamble ["react/react.min.js"]
:output-to "target/resources/public/assets/scripts/main.js"
:output-dir "target/resources/public/assets/scripts"
:source-map "target/resources/public/assets/scripts/main.js.map"
Expand Down
3 changes: 2 additions & 1 deletion resources/about.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Zombie ipsum reversus ab viral inferno, nam rick grimes malum cerebro. De carne lumbering animata corpora quaeritis. Summus brains sit​​, morbo vel maleficia? De apocalypsi gorger omero undead survivor dictum mauris. Hi mindless mortuis soulless creaturas, imo evil stalking monstra adventus resi dentevil vultus comedat cerebella viventium. Qui animated corpse, cricket bat max brucks terribilem incessu zomby. The voodoo sacerdos flesh eater, suscitat mortuos comedere carnem virus. Zonbi tattered for solum oculi eorum defunctis go lum cerebro. Nescio brains an Undead zombies. Sicut malus putrid voodoo horror. Nigh tofth eliv ingdead.
Zombie ipsum reversus ab viral inferno, nam rick grimes malum cerebro. De carne lumbering animata corpora quaeritis. Summus brains sit, morbo vel maleficia? De apocalypsi gorger omero undead survivor dictum mauris. Hi mindless mortuis soulless creaturas, imo evil stalking monstra adventus resi dentevil vultus comedat cerebella viventium. Qui animated corpse, cricket bat max brucks terribilem incessu zomby. The voodoo sacerdos flesh eater, suscitat mortuos comedere carnem virus. Zonbi tattered for solum oculi eorum defunctis go lum cerebro. Nescio brains an Undead zombies. Sicut malus putrid voodoo horror. Nigh tofth eliv ingdead.

Cum horribilem walking dead resurgere de crazed sepulcris creaturis, zombie sicut de grave feeding iride et serpens. Pestilentia, shaun ofthe dead scythe animated corpses ipsa screams. Pestilentia est plague haec decaying ambulabat mortuos. Sicut zeder apathetic malus voodoo. Aenean a dolor plan et terror soulless vulnerum contagium accedunt, mortui iam vivam unlife. Qui tardius moveri, brid eof reanimator sed in magna copia sint terribiles undeath legionis. Alii missing oculis aliorum sicut serpere crabs nostram. Putridi braindead odores kill and infect, aere implent left four dead.

Expand All @@ -7,3 +7,4 @@ Lucio fulci tremor est dark vivos magna. Expansis creepy arm yof darkness ulnis
In Craven omni memoria patriae zombieland clairvius narcisse religionis sunt diri undead historiarum. Golums, zombies unrelenting et Raimi fascinati beheading. Maleficia! Vel cemetery man a modern bursting eyeballs perhsaps morbi. A terrenti flesh contagium. Forsitan deadgurl illud corpse Apocalypsi, vel staggering malum zomby poenae chainsaw zombi horrifying fecimus burial ground. Indeflexus shotgun coup de poudre monstra per plateas currere. Fit de decay nostra carne undead. Poenitentiam violent zom biehig hway agite RE:dead pœnitentiam! Vivens mortua sunt apud nos night of the living dead.

Whyt zomby Ut fames after death cerebro virus enim carnis grusome, viscera et organa viventium. Sicut spargit virus ad impetum, qui supersumus flesh eating. Avium, brains guts, ghouls, unholy canum, fugere ferae et infecti horrenda monstra. Videmus twenty-eight deformis pale, horrenda daemonum. Panduntur brains portae rotting inferi. Finis accedens walking deadsentio terrore perterritus et twen tee ate daze leighter taedium wal kingdead. The horror, monstra epidemic significant finem. Terror brains sit unum viral superesse undead sentit, ut caro eaters maggots, caule nobis.

85 changes: 0 additions & 85 deletions src/omelette/handler.clj

This file was deleted.

23 changes: 23 additions & 0 deletions src/omelette/main.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
(ns omelette.main
(:gen-class)
(:require [com.stuartsierra.component :as component]
[omelette.route :as route]
[omelette.serve :as serve]))

(def system
(component/system-map
:router (route/router)
:server (component/using
(serve/server)
[:router])))

(defn browse [system]
(->> (get-in system [:server :port])
(str "http://localhost:")
java.net.URI.
(.browse (java.awt.Desktop/getDesktop))))

(defn -main [& _]
(-> system
component/start
browse))
47 changes: 23 additions & 24 deletions src/omelette/render.clj
Original file line number Diff line number Diff line change
@@ -1,30 +1,29 @@
(ns omelette.render
(require [clojure.java.io :as io]
[omelette.route :as route])
(:require [clojure.java.io :as io]
[hiccup.page :refer [html5]])
(:import [javax.script
Invocable
ScriptEngineManager]))

(let [js (doto (.getEngineByName (ScriptEngineManager.) "nashorn")
; React requires either "window" or "global" to be defined.
(.eval "var global = this")
; Rendering to string errors with some components in 0.9.0.
; Om is waiting for 0.11.0, though I don't know why.
(.eval ^String (slurp "http://cdnjs.cloudflare.com/ajax/libs/react/0.10.0/react.min.js"))
(.eval (-> "public/assets/scripts/main.js" io/resource io/reader))
; Is there a way to eval it without using closure compiler optimizations?
; The compile speed is pretty slow on whitespace, about 6-10 seconds
)
view (.eval js "omelette.view")]
(defn edn->html [edn]
(.invokeMethod ^Invocable js view "render_to_string" (-> edn list object-array))))
(defn renderer []
(let [js (doto (.getEngineByName (ScriptEngineManager.) "nashorn")
(.eval "var global = this") ; React requires either "window" or "global" to be defined.
(.eval (-> "public/assets/scripts/main.js" io/resource io/reader)))
view (.eval js "omelette.view")]
(fn render
[title state-edn]
(html5
[:head
[:meta {:charset "utf-8"}]
[:meta {:http-equiv "X-UA-Compatible" :content "IE=edge,chrome=1"}]
[:meta {:name "viewport" :content "width=device-width"}]
[:title (str title " | Omelette")]]
[:body
[:noscript "If you're seeing this then you're probably a search engine."]
[:div#omelette-app (.invokeMethod ^Invocable js view "render_to_string" (-> state-edn list object-array))]
[:script {:type "text/javascript" :src "/assets/scripts/main.js"}]
[:script#omelette-state {:type "application/edn"} state-edn]
[:script {:type "text/javascript"} "omelette.view.init('omelette-state')"]
]))))

(defn response [req]
(let [state (route/handler {:event (-> req :uri route/path->state), :ring-req req})
state-edn (pr-str state)]
{:status (if (-> state first name (= "not-found"))
404
200)
:title (route/state->title state)
:body (edn->html state-edn)
:state state-edn}))
;; ((renderer) "foo" (pr-str [:omelette.page/not-found {}]))
Loading

0 comments on commit 6ea23a0

Please sign in to comment.