refactor the piped-input-stream -> java.io.Writer stuff
This commit is contained in:
parent
59a829b9ef
commit
502ceade97
|
@ -3,9 +3,8 @@
|
||||||
(javax.imageio.stream ImageInputStream)
|
(javax.imageio.stream ImageInputStream)
|
||||||
(java.io Writer))
|
(java.io Writer))
|
||||||
(:require [clojure.java.io :as io]
|
(:require [clojure.java.io :as io]
|
||||||
[ring.util.io :refer [piped-input-stream]]
|
|
||||||
[clj-image2ascii.core :as i2a]
|
[clj-image2ascii.core :as i2a]
|
||||||
[toascii.util :refer [query-param-url->java-url]]))
|
[toascii.util :refer [query-param-url->java-url stream-response]]))
|
||||||
|
|
||||||
(def js-gif-animation (slurp (io/resource "gif-animation.js")))
|
(def js-gif-animation (slurp (io/resource "gif-animation.js")))
|
||||||
|
|
||||||
|
@ -26,21 +25,17 @@
|
||||||
(str "<pre style=\"" ascii-pre-css "\">" ascii "</pre>")
|
(str "<pre style=\"" ascii-pre-css "\">" ascii "</pre>")
|
||||||
ascii)))
|
ascii)))
|
||||||
|
|
||||||
(defn- write-out [^Writer w s]
|
|
||||||
(.write w (str s)))
|
|
||||||
|
|
||||||
(defn gif->ascii [^ImageInputStream image-stream scale-to-width color?]
|
(defn gif->ascii [^ImageInputStream image-stream scale-to-width color?]
|
||||||
(piped-input-stream
|
(stream-response
|
||||||
(fn [output-stream]
|
(fn [^Writer w]
|
||||||
(with-open [^Writer w (io/writer output-stream :append true)]
|
(.write w "<div class=\"animated-gif-frames\">")
|
||||||
(write-out w "<div class=\"animated-gif-frames\">")
|
(i2a/stream-animated-gif-frames!
|
||||||
(i2a/stream-animated-gif-frames!
|
image-stream scale-to-width color?
|
||||||
image-stream scale-to-width color?
|
(fn [{:keys [^String image delay]}]
|
||||||
(fn [{:keys [image delay]}]
|
(.write w (str "<pre style=\"" ascii-pre-css " display: none;\" data-delay=\"" delay "\">"))
|
||||||
(write-out w (str "<pre style=\"" ascii-pre-css " display: none;\" data-delay=\"" delay "\">"))
|
(.write w image)
|
||||||
(write-out w image)
|
(.write w "</pre>")))
|
||||||
(write-out w "</pre>")))
|
(.write w "</div>")
|
||||||
(write-out w "</div>")
|
(.write w "<script type=\"text/javascript\">")
|
||||||
(write-out w "<script type=\"text/javascript\">")
|
(.write w js-gif-animation)
|
||||||
(write-out w js-gif-animation)
|
(.write w "</script>"))))
|
||||||
(write-out w "</script>")))))
|
|
|
@ -1,7 +1,10 @@
|
||||||
(ns toascii.util
|
(ns toascii.util
|
||||||
(:import (java.net URL))
|
(:import (java.net URL)
|
||||||
|
(java.io Writer))
|
||||||
(:require [clojure.string :as str]
|
(:require [clojure.string :as str]
|
||||||
|
[clojure.java.io :as io]
|
||||||
[clojure.stacktrace :refer [print-stack-trace]]
|
[clojure.stacktrace :refer [print-stack-trace]]
|
||||||
|
[ring.util.io :refer [piped-input-stream]]
|
||||||
[cemerick.url :as url]))
|
[cemerick.url :as url]))
|
||||||
|
|
||||||
(defn get-filename-without-ext [^String filename]
|
(defn get-filename-without-ext [^String filename]
|
||||||
|
@ -76,4 +79,10 @@
|
||||||
"0" false
|
"0" false
|
||||||
0 false
|
0 false
|
||||||
nil false
|
nil false
|
||||||
true)))
|
true)))
|
||||||
|
|
||||||
|
(defn stream-response [f]
|
||||||
|
(piped-input-stream
|
||||||
|
(fn [output-stream]
|
||||||
|
(with-open [^Writer w (io/writer output-stream)]
|
||||||
|
(f w)))))
|
Reference in a new issue