(defn export [{:strs [pages export-filter type ns-sym var-sym]}]
(let [type (some-> type keyword)
ns-sym (some-> ns-sym symbol)
var-sym (when var-sym
(edn/read-string var-sym))
zip-file (io/file "dynadoc-export.zip")]
(with-open [zip (ZipOutputStream. (io/output-stream zip-file))]
(case pages
"single"
(cond
(some? var-sym)
(do
(.putNextEntry zip (ZipEntry. "index.html"))
(io/copy (page
"/index.html"
{:type type
:ns-sym ns-sym
:var-sym var-sym
:static? true
:hide-sidebar? true})
zip)
(.closeEntry zip))
(some? ns-sym)
(let [cljs-nses-and-vars (get-cljs-nses-and-vars)
var-syms (map :sym
(case type
:cljs (get-cljs-vars cljs-nses-and-vars ns-sym)
:clj (get-clj-vars ns-sym)))]
(.putNextEntry zip (ZipEntry. "index.html"))
(io/copy (page
"/index.html"
{:type type
:ns-sym ns-sym
:static? true
:hide-sidebar? true
:cljs-nses-and-vars cljs-nses-and-vars})
zip)
(.closeEntry zip)
(doseq [var-sym var-syms
:let [path (common/var-sym->url "" true type ns-sym var-sym)]]
(.putNextEntry zip (ZipEntry. path))
(io/copy (page path
{:type type
:ns-sym ns-sym
:var-sym var-sym
:static? true
:hide-sidebar? true
:cljs-nses-and-vars cljs-nses-and-vars})
zip)
(.closeEntry zip))))
"multiple"
(let [clj-nses (get-clj-nses)
cljs-nses-and-vars (get-cljs-nses-and-vars)
cljs-nses (get-cljs-nses cljs-nses-and-vars)
nses (if-let [search (some-> export-filter re-pattern)]
(filter #(re-find search (-> % :sym str))
(sort-by :sym (concat clj-nses cljs-nses)))
(sort-by :sym (concat clj-nses cljs-nses)))]
(.putNextEntry zip (ZipEntry. "index.html"))
(io/copy (page "/index.html"
{:static? true
:cljs-nses-and-vars cljs-nses-and-vars
:nses nses})
zip)
(.closeEntry zip)
(doseq [{:keys [sym type var-syms]} nses
:let [path (str (name type) "/" sym ".html")]]
(.putNextEntry zip (ZipEntry. path))
(io/copy (page path
{:type type
:ns-sym sym
:static? true
:cljs-nses-and-vars cljs-nses-and-vars
:nses nses})
zip)
(.closeEntry zip)
(doseq [var-sym var-syms
:let [path (common/var-sym->url "" true type sym var-sym)]]
(.putNextEntry zip (ZipEntry. path))
(io/copy (page path
{:type type
:ns-sym sym
:var-sym var-sym
:static? true
:cljs-nses-and-vars cljs-nses-and-vars
:nses nses})
zip)
(.closeEntry zip)))))
(doseq [path public-files]
(.putNextEntry zip (ZipEntry. path))
(io/copy
(io/input-stream
(or (io/resource (str "dynadoc-extend/" path))
(io/resource (str "dynadoc-public/" path))))
zip)
(.closeEntry zip)))
zip-file))