simplify
This commit is contained in:
parent
48354a2ce9
commit
bcfca8cf38
|
@ -16,48 +16,31 @@
|
||||||
|
|
||||||
(defn- read-html
|
(defn- read-html
|
||||||
[in]
|
[in]
|
||||||
(try
|
|
||||||
(cond
|
(cond
|
||||||
(string? in) in
|
(string? in) in
|
||||||
(sequential? in) (h/html5 {} in)
|
(sequential? in) (h/html5 {} in)
|
||||||
:else (with-open [r (io/reader in)]
|
:else (with-open [r (io/reader in)]
|
||||||
(slurp r)))
|
(slurp r))))
|
||||||
(catch Exception ex
|
|
||||||
(throw (Exception. "Error reading HTML from input." ex)))))
|
|
||||||
|
|
||||||
(defn- ->output-stream
|
(defn- ->output-stream
|
||||||
[out]
|
[out]
|
||||||
(try
|
|
||||||
(if (instance? OutputStream out)
|
(if (instance? OutputStream out)
|
||||||
out
|
out
|
||||||
(io/output-stream out))
|
(io/output-stream out)))
|
||||||
(catch Exception ex
|
|
||||||
(throw (Exception. "Error preparing an OutputStream from output given." ex)))))
|
|
||||||
|
|
||||||
(defn- parse-jsoup-html
|
|
||||||
[^String html]
|
|
||||||
(try
|
|
||||||
(Jsoup/parse html)
|
|
||||||
(catch Exception ex
|
|
||||||
(throw (Exception. "Error parsing input HTML to Jsoup Document." ex)))))
|
|
||||||
|
|
||||||
(defn- set-jsoup-html-doc
|
(defn- set-jsoup-html-doc
|
||||||
[^PdfRendererBuilder builder jsoup-doc base-uri]
|
[^PdfRendererBuilder builder jsoup-doc base-uri]
|
||||||
(try
|
|
||||||
(let [doc (DOMBuilder/jsoup2DOM jsoup-doc)]
|
(let [doc (DOMBuilder/jsoup2DOM jsoup-doc)]
|
||||||
(.withW3cDocument builder doc base-uri))
|
(.withW3cDocument builder doc base-uri)))
|
||||||
(catch Exception ex
|
|
||||||
(throw (Exception. "Error setting org.w3c.dom.Document HTML." ex)))))
|
|
||||||
|
|
||||||
(defn ->pdf
|
(defn ->pdf
|
||||||
[in out & [options]]
|
[in out & [options]]
|
||||||
(let [options (merge o/default-options options)
|
(let [options (merge o/default-options options)
|
||||||
builder (PdfRendererBuilder.)
|
builder (PdfRendererBuilder.)
|
||||||
html (read-html in)
|
html (read-html in)
|
||||||
html-doc (parse-jsoup-html html)
|
html-doc (Jsoup/parse html)
|
||||||
html-doc (o/inject-options-into-html html-doc options)
|
html-doc (o/inject-options-into-html html-doc options)
|
||||||
output (->output-stream out)]
|
output (->output-stream out)]
|
||||||
html-doc
|
|
||||||
(if (:logging? options)
|
(if (:logging? options)
|
||||||
(let [logger (:logger options)]
|
(let [logger (:logger options)]
|
||||||
(if logger (XRLog/setLoggerImpl logger))
|
(if logger (XRLog/setLoggerImpl logger))
|
||||||
|
|
Loading…
Reference in a new issue