got browser repl working finally

This commit is contained in:
John Bintz 2016-01-12 06:59:07 -05:00
parent 2d36543ce5
commit 46d42cc966
8 changed files with 72687 additions and 16 deletions

3
.gitignore vendored
View File

@ -11,3 +11,6 @@ pom.xml.asc
/out /out
/.repl-* /.repl-*
/.cljs_node_repl/ /.cljs_node_repl/
/public/out
/images

View File

@ -1,13 +1,23 @@
# picture-processor # picture-processor
A Clojure library designed to ... well, that part is up to you. Process a bunch of pictures in nested directories and provide a nice, mobile-
friendly view of them.
## REPL ## REPL with vim-fireplace and Piggieback
### serverside with vim-fireplace and Piggieback ### client-side
* `lein repl` * `lein repl`
* In the repl, `(start)` to launch a cljs repl. * In the repl, `(web-start)` to launch a Jetty server on port 3500.
* In the browser, `http://localhost:3500`.
* In vim, `:Connect`, then `:Piggieback (weasel.repl.websocket/repl-env :port 45192)`
* In the browser console, `startRepl(45192)`
* Evaluate away!
### server-side
* `lein repl`
* In the repl, `(start)` to launch a cljs node repl.
* In vim, `:Connect`, then `:Piggieback (weasel.repl.websocket/repl-env :port 45192)` * In vim, `:Connect`, then `:Piggieback (weasel.repl.websocket/repl-env :port 45192)`
* In the cljs repl, `(require 'picture-processor.repl)` * In the cljs repl, `(require 'picture-processor.repl)`
* ...and then `(picture-processor.repl/start 45192)` * ...and then `(picture-processor.repl/start 45192)`

View File

@ -5,22 +5,44 @@
:url "http://www.eclipse.org/legal/epl-v10.html"} :url "http://www.eclipse.org/legal/epl-v10.html"}
:plugins [[lein-cljsbuild "1.1.2"] :plugins [[lein-cljsbuild "1.1.2"]
[lein-npm "0.6.1"]] [lein-npm "0.6.1"]]
:source-paths ["src"] :source-paths ["src/server" "src/client"]
:npm { :dependencies [[ws "0.4.30"]]} :npm { :dependencies [[ws "0.4.30"]
[imagemagick-native "https://github.com/elad/node-imagemagick-native.git"]]}
:cljsbuild { :cljsbuild {
:builds [{:source-paths ["src"] :builds [{:source-paths ["src/server"]
:compiler { :compiler {
:target :nodejs :target :nodejs
:optimizations :simple}}]} :optimizations :simple}}
{:source-paths ["src/client"]
:compiler {
:output-dir "public/out"
:output-to "public/index.js"
:pretty-print true
:optimizations :whitespace}}
]}
:profiles {:dev {:source-paths ["dev-src"] :profiles {:dev {:source-paths ["dev-src"]
:dependencies [[com.cemerick/piggieback "0.2.1"] :dependencies [[com.cemerick/piggieback "0.2.1"]
[org.clojure/tools.nrepl "0.2.10"]] [org.clojure/tools.nrepl "0.2.10"]
[ring/ring-core "1.4.0"]
[ring/ring-jetty-adapter "1.4.0"]]
:repl-options {:nrepl-middleware [cemerick.piggieback/wrap-cljs-repl] :repl-options {:nrepl-middleware [cemerick.piggieback/wrap-cljs-repl]
:init (do :init (do
(require 'cljs.repl.node) (require 'cljs.repl.node
(require 'weasel.repl.websocket) 'weasel.repl.websocket)
(use 'ring.middleware.file
'ring.adapter.jetty)
(defn web-start []
(run-jetty (wrap-file (fn [request]
{:status 200
:body "ok"}
) "public")
{:port 3500}
))
(defn start [] (cemerick.piggieback/cljs-repl (cljs.repl.node/repl-env)))) (defn start [] (cemerick.piggieback/cljs-repl (cljs.repl.node/repl-env))))
}}} }}}
:dependencies [[org.clojure/clojure "1.7.0"] :dependencies [[org.clojure/clojure "1.7.0"]
[weasel "0.7.0" :exclusions [org.clojure/clojurescript]] [weasel "0.7.0" :exclusions [org.clojure/clojurescript]]
[org.clojure/clojurescript "1.7.170"]]) [org.clojure/clojurescript "1.7.170"]
[org.omcljs/om "0.9.0"]
[sablono "0.3.6"]
])

8
public/index.html Normal file
View File

@ -0,0 +1,8 @@
<html>
<head>
<script src="index.js" defer async></script>
</head>
<body>
<div id="app">hi</div>
</body>
</html>

72568
public/index.js Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,33 @@
(ns picture-processor.browser.core
(:require [weasel.repl :as repl]
[om.core :as om :include-macros true]
[sablono.core :as html :refer-macros [html]]
))
(aset js/window
"startRepl"
(fn [port]
(when-not (repl/alive?)
(weasel.repl/connect (str "ws://localhost:" port))))
)
(def meow (atom 1))
(add-watch meow :key (fn [key ref old-val new-val]
(.log js/console new-val)
))
(defn widget [data owner]
(reify
om/IRender
(render [this]
(html [:div data])
)
)
)
(.log js/console @meow)
(reset! meow 2)
(om/root widget meow {:target (.getElementById js/document "app")})

View File

@ -4,7 +4,3 @@
"I don't do a whole lot." "I don't do a whole lot."
[x] [x]
(.log js/console (str x "Hello, World!"))) (.log js/console (str x "Hello, World!")))
(def a "dogs")
(foo "cats")

View File

@ -0,0 +1,31 @@
(ns picture-processor.images)
(def fs (js/require "fs"))
(def imagemagick (js/require "imagemagick-native"))
(defn write-file [data path]
(.writeFileSync fs path data))
(defn read-file [path]
(.readFileSync fs path))
(defn shrink-image-data
[data width]
(.log js/console "here")
(.convert
imagemagick
(clj->js {:srcData data
:width width
:height width
:resizeStyle "aspectfill"}
)))
(defn create-thumbnail
"Make a mobile thumbnail from a file path"
[source target width]
(-> source
read-file
(shrink-image-data width)
(write-file target)
))